If you work with a large number of servers and you do not use a system to manage the activation of all machines built, manually logging in and checking the status is just time consuming. I put together a script that will go and get the status of all machines specified in the script and display the information in a grid, each with the version and status. Below is an example of this:

Validate windows activation status using powershell and display the results in a gridview.

Script

The script only has one (1) section that needs updating and it is the following:

  • $remoteMachines (specify each machine, separated by a comma)

Here is the script:

# List of remote machines
$remoteMachines = @("Srv1", "Srv2", "Srv3", "Srv4", "Srv5")

# Output array to store results
$outputArray = @()

# Loop through each remote machine
foreach ($machine in $remoteMachines) {
    # Check if the machine is reachable
    if (Test-Connection -ComputerName $machine -Count 1 -Quiet) {
        # Run slmgr.vbs /xpr remotely
        $activationStatus = Invoke-Command { (cscript /NoLogo "c:\Windows\system32\slmgr.vbs" /xpr) -join '' } -ComputerName $machine
            
        # Add results to the output array
        $outputArray += [PSCustomObject]@{
            ComputerName =$machine
            ActivationStatus =$activationStatus
        }
    } else{
        Write-Host "Unable to reach $machine. Check the connection or the machine may be offline."
    }
}

# Display results in a grid
$outputArray | Out-GridView

The cscript section is not my own as I was not getting the correct information in my testing but I used it from SimonS (comment on superuser.com) – Link

Hope it helps.

Discover more from Everything-PowerShell

Subscribe now to keep reading and get access to the full archive.

Continue reading