Skip to content

Instantly share code, notes, and snippets.

@jak119
Last active July 7, 2016 13:20
Show Gist options
  • Save jak119/47c29b7e84fa394de9d8 to your computer and use it in GitHub Desktop.
Save jak119/47c29b7e84fa394de9d8 to your computer and use it in GitHub Desktop.
PowerShell One-Liners

Active Directory One-Liners

Users

Groups

Remove all group members Get-ADGroupMember "TESTGROUP" | ForEach-Object {Remove-ADGroupMember "TESTGROUP" $_ -Confirm:$false}

Add similar groups to one group get-adgroup -filter {name -like "group*end"} | ForEach-Object {Add-ADGroupMember -Identity "TESTGROUP" -Members $_}

Computers

Disable computer account based on name Get-ADComputer COMPUTERNAME | Disable-ADAccount

Group Policy

Link GPO to OU New-GPLink -Name GPO_NAME -Target "OU=TESTOU,DC=ad,DC=company,DC=com" -Enforced yes

Force GPUpdate on Machines in OU Get-ADComputer -Filter * -SearchBase "OU=TESTOU,DC=ad,DC=company,DC=com" | foreach{ Invoke-GPUpdate -Computer $_.name -force}

vSphere PowerCLI One-Liners

Snapshots

Get all snapshots and format list Get-VM | Get-Snapshot | Format-List name,vm,created

Remove all snapshots Get-VM | Get-Snapshot | Remove-Snapshot

Remove all snapshots from one VM Get-VM VMNAME | Get-Snapshot | Remove-Snapshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment