I have publish multiple times different scripts that can use in Powershell to monitoring environments, find details of your Windows Systems and more.
As IT Pro to be compliance you must know every time the License Status of any Software.
It's not easy task to be up to date because of the changes that can be without noted.
For this reason i started to wrote a script that you can identify the License Status of your Windows Servers.
I am in start stage and the script it's not include Handle of Errors and it isn't in GUI Environment.
Right now i have already proceed to handle errors of the powershell script in case that the Windows Server is close or it's not enable the Ws-Man but i don't have include yet in this script until finish it.
So let's start
Prerequisites
Before you run the script in your environment you must keep some specs.
The reason is because the Powersell script retrieve all the Computer names from your Active Directory
- You must install the Active Directory Powershell Module in your Server/Workstation that you will run the script.
- You must enable the Wsman and allow it in your Firewall for your Servers that will scan the License Status.
Run the following command to install Active Directory Powershell Module
Install-WindowsFeature RSAT-AD-PowerShell
The script you can download from here
Of course you can find this feature
How the Powershell Script run
After apply all the prerequisites you can run the script and take the License Status of your Windows Servers.
But i believe it will give more value if explain how create this script line by line to help you expanded or change it base on your requirements.
So let's start to explain line by line our code
Create a variable to ask for credentials
$cred = Get-Credential domain\user
Create an array that will use it to add values while scan the computer names for the licenses
$result1=@()
Save in variable all the computer names of Windows Servers from Active Directory
$os = Get-ADComputer -Filter 'OperatingSystem -like "Windows Server*"'
Start a Loop with ForEach-Object
ForEach-Object{
Save only the name property of the Computername in variable
$compn=$os.name
Create a script that will use in Invoke-command to retrieve 3 properties.
licenses=Only License Product with a Productkeyid. I have add this filter because when query with Get-CimInstance -ClassName SoftwareLicensingProduct will get lot of Licenses related with different applications like Office that will not need it for now.
computername= the computer name of the Windows Server
licensestatus= The License Status of the Product.
In the license status you will see a number. The number has a description which is the status of the license.
Find the table here from Microsoft Site
Value | Description |
---|---|
0 | Unlicensed |
1 | Licensed |
2 | OOBGrace |
3 | OOTGrace |
4 | NonGenuineGrace |
5 | Notification |
6 | ExtendedGrace |
$Scriptblock=
{
$licenses=@{
license= ( Get-CimInstance -ClassName SoftwareLicensingProduct | where {$_.productkeyid} ).Description
Computername=(Get-CIMInstance Win32_ComputerSystem ).Caption
licensestatus= ( Get-CimInstance -ClassName SoftwareLicensingProduct | where {$_.productkeyid} ).LicenseStatus
}
Create a new Object with the Property $licenses
$r=New-Object psobject -Property $licenses
$r
}
Include in the array the results while connenct with Invoke-Command and run the $Scirptblock which create above
$result1+= Invoke-Command -cn $compn -Credential $cred -ScriptBlock $Scriptblock -ArgumentList $compn | Select-Object -property license,Computername,licensestatus -ExcludeProperty PSComputername,RunspaceID
}
Type in screen the results
$result1| Select-Object -property license,Computername,licensestatus -ExcludeProperty PSComputername,RunspaceID
After understand how wrote the code you can run and you will get the results with the failed in red lines of the computer names that can't conenct.
As i said in the beginning in my next article i will proceed to handle the errors and improve my script
You can find a similar option that can use in the VirtualMetric Application that can use to Monitoring your HYPER-V Environment.
If you are interesting you can find a Review that i have done for the VirtualMetric
Have a nice weekend !!!!
I invite you to follow me on Twitter or Facebook. If you have any questions, send email to me at info@askme4tech.com