PowerShell



Logoff Link auf Desktop erstellen

$wshshell = New-Object -ComObject WScript.Shell
$desktop = [System.Environment]::GetFolderPath('Desktop')
$lnk = $wshshell.CreateShortcut($desktop+"\LogOff.lnk")
$lnk.TargetPath = "C:\Windows\System32\shutdown.exe"
$lnk.Arguments = "/l"
$lnk.IconLocation = "%SystemRoot%\system32\SHELL32.dll,43"
$lnk.Save()

Shutdown Link auf Desktop erstellen

$wshshell = New-Object -ComObject WScript.Shell
$desktop = [System.Environment]::GetFolderPath('Desktop')
$lnk = $wshshell.CreateShortcut($desktop+"\Shutdown.lnk")
$lnk.TargetPath = "C:\Windows\System32\shutdown.exe"
$lnk.Arguments = "/s /t 0"
$lnk.IconLocation = "%SystemRoot%\system32\SHELL32.dll,27"
$lnk.Save()

Installierte .NET Frameworks anzeigen

#Source: http://stackoverflow.com/questions/3487265/powershell-to-return-versions-of-net-framework-on-a-machine
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse | `
Get-ItemProperty -name Version -EA 0 | Where { $_.PSChildName -match '^(?!S)\p{L}'} | `
Sort-Object Version -descending | Select PSChildName, Version  

Shutdowns and Restarts anzeigen

Get-EventLog -LogName "System" -Newest 10000 | where { $_.EventId -eq 6005 -or $_.EventId -eq 6006} | Select Timegenerated, Message

Remotedesktopconnections anzeigen

Get-WinEvent -FilterHashtable @{Logname = "Microsoft-Windows-TerminalServices-RemoteConnectionManager/Operational" ; ID = 1149,1150,1148} | Out-GridView

Domain Cotroller auflisten

$getdomain = [System.Directoryservices.Activedirectory.Domain]::GetCurrentDomain()
$getdomain | ForEach-Object {$_.DomainControllers} |
ForEach-Object {
  $hEntry= [System.Net.Dns]::GetHostByName($_.Name)
  New-Object -TypeName PSObject -Property @{
      Name = $_.Name
      IPAddress = $hEntry.AddressList[0].IPAddressToString
     }
}
Origin

Systemvariablen beim Aufruf von Programmen auflösen

& "$env:SystemRoot\System32\notepad.exe" test.txt