functions/get-d365windowsactivationstatus.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

<#
    .SYNOPSIS
        Get activation status
         
    .DESCRIPTION
        Get all the important license and activation information from the machine
         
    .EXAMPLE
        PS C:\> Get-D365WindowsActivationStatus
         
        This will get the remaining grace and rearm activation information for the machine
         
    .NOTES
        The cmdlet uses CIM objects to access the activation details
         
        Author: Mötz Jensen (@Splaxi)
         
#>

function Get-D365WindowsActivationStatus {
    [CmdletBinding()]
    param ()

    begin {}

    process {
        $a = Get-CimInstance -Class SoftwareLicensingProduct -Namespace root/cimv2 -ComputerName . -Filter "Name LIKE '%Windows%'"
        $b = Get-CimInstance -Class SoftwareLicensingService -Namespace root/cimv2 -ComputerName .

        $res = [PSCustomObject]@{ Name = $a.Name
            Description = $a.Description
            "Grace Periode (days)" =  [math]::Round(($a.graceperiodremaining / 1440))
        }

        $res | Add-Member -MemberType NoteProperty -Name 'ReArms left' -Value $b.RemainingWindowsReArmCount
 
        $res
    }

    end {}
}