none
Script to check windows activation status on about 200 servers RRS feed

  • Question

  • Hi all, hope someone could help. 

    I'm tasked to create a two-column report that contains a server name and a windows activation status so I 

    could then manually activate windows on all the servers that have not been activated yet.

    We have about 200 servers and Power Shell is disabled in our environment. 

    Could also activation be done via a batch script or using psexec? 

    Thanks

    Friday, November 8, 2019 1:56 PM

Answers

  • Here is the older method of checking licensing status.

     cscript C:\WINDOWS\SYSTEM32\slmgr.vbs <your pc name> /dli

    You can get all switches like this:

    cscript C:\WINDOWS\SYSTEM32\slmgr.vbs

    The deployment or Windows Gen4eral forum can help you with this utility.


    \_(ツ)_/


    • Edited by jrv Friday, November 8, 2019 9:01 PM
    • Marked as answer by Etoya Friday, November 8, 2019 10:08 PM
    Friday, November 8, 2019 9:00 PM

All replies

  • Does this help?

    https://gallery.technet.microsoft.com/scriptcenter/How-to-check-if-Windows-is-b566d0bb


    Best Regards
    Jatin Makhija
    If my suggestion helps to resolve the issue, Please Click "Mark as Answer"

    Friday, November 8, 2019 2:03 PM
  • Your question belongs in the Deployment forum as it is not a scripting question.


    \_(ツ)_/

    Friday, November 8, 2019 5:17 PM
  • Thanks, but as I said powershell is disabled in our environment. If I get a permission to temporary enable

    powershell, how can I exclude all non-server type operating systems? Also it would have to be run on the entire

    domain and not a specific OU.


    Friday, November 8, 2019 6:17 PM
  • Thanks, but as I said powershell is disabled in our environment. If I get a permission to temporary enable

    powershell, how can I exclude all non-server type operating systems? Also it would have to be run on the entire

    domain and not a specific OU.


    You are asking or someone to design a custom solution. Please take the time to learn PowerShell or contact a consultant to help you design a solution.  Technical forums are not free custom script writing forums.  They are for questions about a script you have written.

    The example given does what you ask.  If PS is disabled then use WMIC to do this.  You will have to post issues for WMIC in the Windows general forum as it is not a script but is a system utility.

    If you post in the deployment forum they will help you find and use the licensing utility which can do what you ask.

    See the topic pinned at the top of the forum for the purpose and limits of this forum: This forum is for scripting questions rather than script requests


    \_(ツ)_/

    Friday, November 8, 2019 6:55 PM
  • As Jrv Said its not a developer forum but as you asked, here is something you can use. As you can see the first line of the script will return only the servers with server OS in your domain. Rest of the script should provide you the license status.

    I customized the script for you posted in the above link. I hope it will help in your requirement:

    $Computername = get-adcomputer -filter {OperatingSystem -like "*Server*"} | Select -expandproperty Name
    $LicenseStatus = @("Unlicensed","Licensed","OOB Grace","OOT Grace","Non-Genuine, Grace","Notification","Extended Grace")
    
    Foreach($CN in $ComputerName)
    {
        Get-CimInstance -ClassName SoftwareLicensingProduct -ComputerName $CN |`
        Where{$_.PartialProductKey -and $_.Name -like "*Windows*"} | Select `
        @{Expression={$_.PSComputerName};Name="ComputerName"},`
        @{Expression={$_.Name};Name="WindowsName"} ,ApplicationID,`
        @{Expression={$LicenseStatus[$($_.LicenseStatus)]};Name="LicenseStatus"}
    }



    Best Regards
    Jatin Makhija
    If my suggestion helps to resolve the issue, Please Click "Mark as Answer"


    Friday, November 8, 2019 7:58 PM
  • If we apply PowerShell "Best Practices" and style rules we get the following:

    $licenseStatus = @(
        'Unlicensed',
        'Licensed',
        'OOB Grace',
        'OOT Grace',
        'Non-Genuine, Grace',
        'Notification',
        'Extended Grace'
    )
    
    $properties = @(
        @{e={$_.PSComputerName};n='ComputerName'},
        @{e={$_.Name};n='WindowsName'} ,
        'ApplicationID',
        @{n='LicenseStatus';e={$licenseStatus[$_.LicenseStatus]}}
    )
    
    Get-AdComputer -filter {OperatingSystem -notlike '*Server*' -and Enabled -eq $true} |
        ForEach-Object{Get-CimInstance SoftwareLicensingProduct -ComputerName $_.Name} |
        Where-Object{$_.PartialProductKey -and $_.Name -like '*Windows*'} |
        Select-Object $properties

    We should avoid code suing line extenders as it is a leftover from PS1 and can lead to many issues.  It is an issue with code posted in forums as forum software can mess up this character and it will cause issues.  Lines can always be broken on pipes and closures oenings "{},[],()" etc. which is more natural and easier to read and debug.


    \_(ツ)_/


    • Edited by jrv Friday, November 8, 2019 8:29 PM
    Friday, November 8, 2019 8:23 PM
  • Great, thanks for the tip, I wasn't aware of that. I have a wmic based script but get RPC error on about 30% of

    the servers. So I was hopping someone would have a ready to be used CMD/PSEXEC based script.

    How do I move my question to deployment forum?

    Friday, November 8, 2019 8:43 PM
  • Great, thanks Jrv! I'll try to get powershell unblocked temporarily for this project! 


    Friday, November 8, 2019 8:45 PM
  • Great, thanks for the tip, I wasn't aware of that. I have a wmic based script but get RPC error on about 30% of

    the servers. So I was hopping someone would have a ready to be used CMD/PSEXEC based script.

    How do I move my question to deployment forum?

    PsExec will not usually work in an environment that is secured.

    WMIC will fail if the OSs are too old(pre-win7) or if the WMI on the systems is not working correctly..

    If WMIC doesn't work and PowerShell remoting is not installed on all systems then Get-CimInstance will also fail.


    \_(ツ)_/


    • Edited by jrv Friday, November 8, 2019 8:52 PM
    Friday, November 8, 2019 8:51 PM
  • Thanks again for the tip Jrv, all our servers are 2008 or newer. we will make sure the PowerShell remoting is

    installed/enabled on all the servers at least for the duration of this project.

    Cheers!

    Friday, November 8, 2019 9:00 PM
  • Here is the older method of checking licensing status.

     cscript C:\WINDOWS\SYSTEM32\slmgr.vbs <your pc name> /dli

    You can get all switches like this:

    cscript C:\WINDOWS\SYSTEM32\slmgr.vbs

    The deployment or Windows Gen4eral forum can help you with this utility.


    \_(ツ)_/


    • Edited by jrv Friday, November 8, 2019 9:01 PM
    • Marked as answer by Etoya Friday, November 8, 2019 10:08 PM
    Friday, November 8, 2019 9:00 PM
  • Thanks again for the tip Jrv, all our servers are 2008 or newer. we will make sure the PowerShell remoting is

    installed/enabled on all the servers at least for the duration of this project.

    Cheers!

    I am pretty sure that 2008 does not support that class. 2008r2 does. Both WS2008 and WS2008r2 are no longer supported.


    \_(ツ)_/

    Friday, November 8, 2019 9:07 PM
  • Awesome, got this script below to work on a test list of 10 servers, 2012 R2 and newer. 

    psexec64 @c:\serverlist.txt -u domain\administrator -p ******** cscript C:\WINDOWS\SYSTEM32\slmgr.vbs /dli

    Thank you!

    Friday, November 8, 2019 10:08 PM