Aufrufsyntax:
PowerShell[.exe] [-PSConsoleFile <Datei> | -Version <Version>] [-NoLogo] [-NoExit] [-Sta] [-NoProfile] [-NonInteractive] [-InputFormat {Text | XML}] [-OutputFormat {Text | XML}]
[-WindowStyle <style>] [-EncodedCommand <Base64EncodedCommand>] [-File <Dateipfad> <Argumente>] [-ExecutionPolicy <ExecutionPolicy>] [-Command { - | <script-block> [-args <arg-array>]
| <string> [<CommandParameters>] } ] PowerShell[.exe] -Help | -? | /?
REM Powershell Pack Erweiterungspack
http://archive.msdn.microsoft.com/PowerShellPack/Release/ProjectReleases.aspx ?ReleaseId=3341
WPK Create rich user interfaces quick and easily from Windows PowerShell. Think HTA, but easy. Over 600 scripts to help you build quick user interfaces
TaskScheduler List scheduled tasks, create or delete tasks
FileSystem Monitor files and folders, check for duplicate files, and check disk space
IsePack Supercharge your scripting in the Integrated Scripting Environment with over 35 shortcuts
DotNet Explore loaded types, find commands that can work with a type, and explore how you can use PowerShell, DotNet and COM together
PSImageTools Convert, rotate, scale, and crop images and get image metadata PSRSS Harness the FeedStore from PowerShell
PSSystemTools Get Operating System or Hardware Information PSUserTools Get the users on a system, check for elevation, and start-processaadministrator
Ausgabe von get-date | get-member:
Name MemberType Definition ---- --- ---
Add Method System.DateTime Add(System.TimeSpan value) AddDays Method System.DateTime AddDays(double value) AddHours Method System.DateTime AddHours(double value) AddMilliseconds Method System.DateTime AddMilliseconds(double value) AddMinutes Method System.DateTime AddMinutes(double value) AddMonths Method System.DateTime AddMonths(int months) AddSeconds Method System.DateTime AddSeconds(double value) AddTicks Method System.DateTime AddTicks(long value) AddYears Method System.DateTime AddYears(int value)
CompareTo Method int CompareTo(System.Object value), int CompareTo(System.DateTime value) Equals Method bool Equals(System.Object value), bool Equals(System.DateTime value) GetDateTimeFormats Method string[] GetDateTimeFormats(), string[]
GetDateTimeFormats(System.IFormatProvider provider), string[... GetHashCode Method int GetHashCode()
GetType Method type GetType()
GetTypeCode Method System.TypeCode GetTypeCode() IsDaylightSavingTime Method bool IsDaylightSavingTime()
Subtract Method System.TimeSpan Subtract(System.DateTime value), System.DateTime Subtract(System.TimeSpan value)
ToBinary Method long ToBinary() ToFileTime Method long ToFileTime() ToFileTimeUtc Method long ToFileTimeUtc()
ToLocalTime Method System.DateTime ToLocalTime() ToLongDateString Method string ToLongDateString()
Fortsetzung der Ausgabe von get-date | get-member:
ToLongTimeString Method string ToLongTimeString() ToOADate Method double ToOADate()
ToShortDateString Method string ToShortDateString() ToShortTimeString Method string ToShortTimeString() ToString Method string ToString(), string ToString(string format), string ToString(System.IFormatProvider provider),...
ToUniversalTime Method System.DateTime ToUniversalTime() DisplayHint NoteProperty
Microsoft.PowerShell.Commands.DisplayHintType DisplayHint=DateTime Date Property System.DateTime Date {get;} Day Property System.Int32 Day {get;}
DayOfWeek Property System.DayOfWeek DayOfWeek {get;} DayOfYear Property System.Int32 DayOfYear {get;} Hour Property System.Int32 Hour {get;}
Kind Property System.DateTimeKind Kind {get;} Millisecond Property System.Int32 Millisecond {get;} Minute Property System.Int32 Minute {get;} Month Property System.Int32 Month {get;} Second Property System.Int32 Second {get;} Ticks Property System.Int64 Ticks {get;}
TimeOfDay Property System.TimeSpan TimeOfDay {get;} Year Property System.Int32 Year {get;}
DateTime ScriptProperty System.Object DateTime {get=if ((& { Set-StrictMode -Version 1; $this.DisplayHint }) -ieq "Date")...
get-itemproperty -path $OH PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\Software\Oracle\KEY_Or aDb11g_home1 PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\Software\Oracle PSChildName : KEY_OraDb11g_home1 PSDrive : HKLM PSProvider : Microsoft.PowerShell.Core\Registry ORACLE_HOME : D:\oracle\product\11.2.0\dbhome_1 ORACLE_HOME_NAME : OraDb11g_home1
ORACLE_GROUP_NAME : Oracle - OraDb11g_home1 NLS_LANG : GERMAN_GERMANY.WE8MSWIN1252 ORACLE_BUNDLE_NAME : Enterprise OLEDB : D:\oracle\product\11.2.0\dbhome_1\oledb\mesg ORAMTS_CP_TRACE_LEVEL : 0 .. ORACLE_SID :o11g MSHELP_TOOLS :D:\oracle\product\11.2.0\dbhome_1\MSHELP SQLPATH :D:\oracle\product\11.2.0\dbhome_1\dbs ORACLE_HOME_KEY : SOFTWARE\ORACLE\KEY_OraDb11g_home1 ORACLE_BASE : D:\oracle RDBMS_CONTROL :D:\oracle\product\11.2.0\dbhome_1\DATABASE RDBMS_ARCHIVE D:\oracle\product\11.2.0\dbhome_1\DATABASE\ARCHIVE ORA_O112_AUTOSTART : TRUE ORA_O112_SHUTDOWN : TRUE ORA_O112_SHUTDOWNTYPE : immediate ORA_O112_SHUTDOWN_TIMEOUT : 90 ORA_O11G_AUTOSTART : TRUE
Beispiel:
Anzeige der Oracle Services die auf Automatisch stehen, aber nicht gestartet sind:
Get-WmiObject Win32_Service |
Where-Object { $_.StartMode -eq 'Auto' -and $_.State -ne 'Running' -and $_.Name -match "Ora"} | ft –auto
Hinweis:
Folgende Stati der Instanz bringen diese Meldungen zurück:
REM Shutdown in Progress
Fehler ORA-01089: immediate shutdown in progress - no operations are permitted
REM Shutdown Mode:
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist REM Mount:
ORA-01033: ORACLE initialization or shutdown in progress REM Open:
ORA-28000: the account is locked
Die fünf Prozesse mit der größten Speicherauslastung anzeigen:
Hinweis:
Wenn Sie auch Attachments verschicken möchten:
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer) $msg.From = "[email protected]"
$msg.To.Add ("[email protected]") $msg.Subject = "Nachricht mit Anhängen" $msg.Body = "Hier könnte Ihr Body stehen"
# Alle Dateien des Ordners C:\temp\att anhängen foreach ($file in gci "c:\temp\att"){
$att = New-Object Net.Mail.Attachment($file.fullname) $msg.Attachments.Add($att)
}
Beispielausgabe von:
Get-Process | select name,cpu,threads | ft -auto
Beispielausgabe:
#TYPE System.Diagnostics.EventLogEntry#System/Service Control Manager/3221232472 "EventID","MachineName","Data","Index","Category","CategoryNumb er","EntryType","Message","Source","ReplacementStrings","Instan ceId","TimeGenerated","TimeWritten","UserName","Site","Containe r" "7000","goofymarco.muniqsoft.de","System.Byte[]","91701","(0)", "0","Error","Der Dienst ""CyberLink UDF Filesystem"" wurde aufgrund folgenden Fehlers nicht gestartet:
%%1275","Service Control
Manager","System.String[]","3221232472","19.01.2012 07:48:24","19.01.2012 07:48:24",,,
Hinweis:
Eine eigene Zertifizierung der Skripten ist relativ aufwendig und würde den Rahmen dieses Vortrags sprengen.
Im Internet existieren jedoch viele Beispiele zu diesem Thema.
Alias
CMD
Alias
CMD
ac Add-Content gwmi Get-WmiObject
asnp Add-PSSnapin iex Invoke-Expression
clc Clear-Content ihy Invoke-History
cli Clear-Item ii Invoke-Item
clp Clear-ItemProperty ipmo Import-Module
clv Clear-Variable iwmi Invoke-WmiMethod
compare Compare-Object ipal Import-Alias
cpi Copy-Item ipcsv Import-Csv
cpp Copy-ItemProperty measure Measure-Object
cvpa Convert-Path mi Move-Item
dbp Disable-PSBreakpoint mp Move-ItemProperty
diff Compare-Object nal New-Alias
ebp Enable-PSBreakpoint ndr New-PSDrive
epal Export-Alias ni New-Item
epcsv Export-Csv nv New-Variable
fc Format-Custom nmo New-Module
fl Format-List oh Out-Host
foreach ForEach-Object ogv Out-GridView
% ForEach-Object ise powershell_ise.exe
ft Format-Table rbp Remove-PSBreakpoint
fw Format-Wide rdr Remove-PSDrive
gal Get-Alias ri Remove-Item
gbp Get-PSBreakpoint rni Rename-Item
gc Get-Content rnp Rename-ItemProperty
gci Get-ChildItem rp Remove-ItemProperty
gcm Get-Command rmo Remove-Module
gdr Get-PSDrive rsnp Remove-PSSnapin
gcs Get-PSCallStack rv Remove-Variable
ghy Get-History rwmi Remove-WmiObject
gi Get-Item rvpa Resolve-Path
gl Get-Location sal Set-Alias
gm Get-Member sasv Start-Service
gmo Get-Module sbp Set-PSBreakpoint
gp Get-ItemProperty sc Set-Content
gps Get-Process select Select-Object
group Group-Object si Set-Item
gsv Get-Service sl Set-Location
DOAG 2011 DP Tricks-38
Alias
CMD
Alias
CMD
sp Set-ItemProperty set Set-Variable
saps Start-Process type Get-Content
start Start-Process icm Invoke-Command
spps Stop-Process clhy Clear-History
spsv Stop-Service gjb Get-Job
sv Set-Variable rcjb Receive-Job
tee Tee-Object rjb Remove-Job
where Where-Object sajb Start-Job
? Where-Object spjb Stop-Job
write Write-Output wjb Wait-Job
cat Get-Content nsn New-PSSession
cd Set-Location gsn Get-PSSession
clear Clear-Host rsn Remove-PSSession
cp Copy-Item ipsn Import-PSSession
h Get-History epsn Export-PSSession
history Get-History etsn Enter-PSSession
kill Stop-Process exsn Exit-PSSession
lp Out-Printer ls Get-ChildItem man help mount New-PSDrive md mkdir mv Move-Item popd Pop-Location ps Get-Process pushd Push-Location pwd Get-Location r Invoke-History rm Remove-Item rmdir Remove-Item echo Write-Output cls Clear-Host chdir Set-Location copy Copy-Item del Remove-Item dir Get-ChildItem erase Remove-Item move Move-Item rd Remove-Item ren Rename-Item