- 1 year ago
How to get Windows Activation status on all PCs in a specific OU in Active Directory using PowerShell?
To get the Windows activation status on all PCs in a specific Organizational Unit (OU) in Active Directory using PowerShell, you can utilize the Get-WmiObject
cmdlet and query the SoftwareLicensingProduct
class. Here's an example script to accomplish this:
powershell# Set the target OU distinguished name
$ouDN = "OU=Computers,OU=MyOU,DC=domain,DC=com"
# Get all computers in the target OU
$computers = Get-ADComputer -Filter * -SearchBase $ouDN
# Loop through each computer and retrieve activation status
foreach ($computer in $computers) {
$computerName = $computer.Name
$wmiParams = @{
ComputerName = $computerName
Namespace = "root\CIMv2"
Class = "SoftwareLicensingProduct"
Filter = "PartialProductKey != null"
}
$activationStatus = Get-WmiObject @wmiParams | Select-Object -ExpandProperty LicenseStatus
Write-Output "Computer: $computerName"
Write-Output "Activation Status: $activationStatus"
Write-Output "-----------------------------"
}
In this script:
Set the value of
$ouDN
to the distinguished name of your target OU in Active Directory. Update it with the appropriate OU path for your environment.The script uses
Get-ADComputer
to retrieve all computer objects in the specified OU.It then loops through each computer, queries the
SoftwareLicensingProduct
class on the remote computer usingGet-WmiObject
, and retrieves theLicenseStatus
property.The computer name and activation status are displayed for each computer.
Ensure that you have the Active Directory module installed (Import-Module ActiveDirectory
) and that you have appropriate permissions to query Active Directory and access WMI information on the target computers.
Run the script in a PowerShell session with administrative privileges or with an account that has the necessary permissions to access the target OU and the remote computers in order to retrieve the activation status information.