Useful PowerShell snippets (part 1)

Written on December 1, 2008

Some things I’m finding useful:

Processes running on a machine

Get-WmiObject Win32_Process -ComputerName mymachine | Select { $_.Name }

Currently logged in user on a machine

Get-WmiObject Win32_ComputerSystem -ComputerName MyMachine | Select { $_.UserName }

Does a machine have .NET 3.5 SP1 installed

function Get-Net35SP1([string] $machineName) {     $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $machineName)     $regKey= $reg.OpenSubKey("SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" )     if ($regKey -ne $null) {         Write-Output $regKey.GetValue("SP", 0)         $regKey.Close()     } else {         Write-Output "Doesn't have .NET 3.5"     }     $reg.Close() }

Categories: PowerShell