#basic
Get-ADComputer -Filter "name -like '*'" -Properties operatingSystem | group -Property operatingSystem | `
Select Name,Count | Sort Name | ft -AutoSize
# Workstations
Get-ADComputer -Filter 'operatingsystem -notlike "*server*" -and enabled -eq "true"' -Properties Name,Operatingsystem,OperatingSystemVersion,IPv4Address,CanonicalName,lastLogonDate |`
Sort-Object -Property Operatingsystem | `
Select-Object -Property Name,Operatingsystem,OperatingSystemVersion,IPv4Address,lastLogonDate,CanonicalName | `
Export-Csv C:\Scraps\ad_computers\domainX_workstations_03-03-2022.csv -NoTypeInformation
#servers
Get-ADComputer -Filter 'operatingsystem -like "*server*" -and enabled -eq "true"' -Properties Name,Operatingsystem,OperatingSystemVersion,IPv4Address,CanonicalName | `
Sort-Object -Property Operatingsystem | `
Select-Object -Property Name,Operatingsystem,OperatingSystemVersion,IPv4Address,CanonicalName | FT
#member servers
Get-ADComputer -Filter 'operatingsystem -like "*server*" -and enabled -eq "true" -and primarygroupid -ne "516"' `
-Properties Name,Operatingsystem,OperatingSystemVersion,IPv4Address,CanonicalName |`
Sort-Object -Property Operatingsystem | `
Select-Object -Property Name,Operatingsystem,OperatingSystemVersion,IPv4Address,CanonicalName
# Domain Controllers
Get-ADComputer -Filter 'primarygroupid -eq "516"' -Properties Name,Operatingsystem,OperatingSystemVersion,IPv4Address,CanonicalName |`
Sort-Object -Property Operatingsystem | `
Select-Object -Property Name,Operatingsystem,OperatingSystemVersion,IPv4Address,CanonicalName | FT
PowerShell to Get OS Type and Count – more of this
# scraps
Get-ADComputer -Filter 'operatingsystem -notlike "*server*" -and enabled -eq "true"' `
-Properties Name,Operatingsystem,OperatingSystemVersion,IPv4Address,CanonicalName |`
Sort-Object -Property Operatingsystem |`
Select-Object -Property Name,Operatingsystem,OperatingSystemVersion,IPv4Address,CanonicalName | Export-Csv D:\psExports\ad\computers\workstations_01-11-2022.csv -NoTypeInformation
# scraps
Where { $_.LastLogonDate -GT (Get-Date).AddDays(-30) }
-Filter 'operatingsystem -notlike "*server*" -and enabled -eq "true"' -Properties Name,Operatingsystem,OperatingSystemVersion,IPv4Address,CanonicalName,lastLogonDate |`
Where { $_.LastLogonDate -GT (Get-Date).AddDays(-30) } | Select-Object -Property Name,Operatingsystem,OperatingSystemVersion,IPv4Address,lastLogonDate,CanonicalName | Export-Csv C:\Scraps\ad_computers\domainX_workstations_03-03-2022.csv -NoTypeInformation