Wednesday, April 29, 2020

PowerShell for AD



Get computer by service tag
get-adcomputer -Filter 'serialNumber -eq "123456"' -Properties *


Get computer owner
get-adcomputer -properties * | select ManagedBy


Get group info to file
get-adgroup -properties * | Out-File c:\temp\grp.txt


Get group membership for a user
Get-ADPrincipalGroupMembership | select name | Sort-Object name


Get machines owned by a user
Get-adcomputer -Filter "ManagedBy -eq ''


Validate Credentials
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('domain')
$DS.ValidateCredentials('', '')


Get DirectReports - Sorted by last name, filtering out underscores, and showing desk location.
get-aduser -Properties directreports | Select-Object -ExpandProperty directreports | Get-AdUser -Properties * |Select-Object LegalGivenName, LegalSurName, physicalDeliveryOfficeName | Where-Object {$_.physicalDeliveryOfficeName -ne $null} | Sort-Object LegalSurName

No comments:

Post a Comment