AD Users

Description Command
Display Users in a specific OU Get-ADUser -ResultSetSize 3000 -SearchBase "ou=Team1,ou=Users,ou=MyBusiness,DC=Contoso,DC=local" -Filter * | Select Name
Update Users in a specific OU Get-ADUser -ResultSetSize 3000 -SearchBase "ou=Team1,ou=Users,ou=MyBusiness,DC=Contoso,DC=local" -Filter * | Set-ADUser -PasswordNeverExpires $false
Get Users with a profile path beginning… Get-ADUser -Filter {ProfilePath -like "\\fileserver1\Profiles$\*"} -Properties profilepath
Get all ACTIVE users Get-ADUser -Filter 'enabled -eq $true' | select name | export-csv c:\temp\users.csv
Add users in an OU to a Security Group get-aduser -searchbase "ou=Team1,ou=Users,ou=MyBusiness,DC=Contoso,DC=local" -filter * | Add-ADPrincipalGroupMembership -MemberOf "Security Group Name"
Copy group membership to a different group $SourceGroup = "Terminal Service Users"
$TargetGroup = "RDG Users"
$Sgroupmem = Get-ADGroupmember -Identity $SourceGroup
Add-ADGroupmember -Identity $TargetGroup -Member $Sgroupmem
Set the email field for users in a specific OU Get-ADUser -Filter * -SearchBase 'OU=Staff,OU=Users,DC=Domain,DC=local' -server "Servername" | ForEach-Object { Set-ADUser -EmailAddress ($_.givenname + '.' + $_.surName + '@domain.com') -Identity $_ -server "Servername"}
Password last set… get-aduser -filter * -properties passwordlastset, passwordneverexpires |ft Name, passwordlastset, Passwordneverexpires
Users in a group, with a password older than a week! get-adgroupmember "Office 365 Password Sync" | get-aduser -properties passwordlastset, passwordneverexpires | where {$_.passwordlastset -lt ((get-date).AddDays(-7))} | ft Name, passwordlastset, Passwordneverexpires

Virtual Machines

Description Command
Live Migrate a VM Get-VM "VMtobeMoved" -ComputerName "NameofCurrentHyperVHost" | Move-VM -DestinationHost "NameofDestinationHost" -IncludeStorage -DestinationStoragePath "D:\VMtobeMoved"

Posts (Tagged: Powershell)