Public/SystemInformation/Get-EZComputerSerialNumber.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
<#
.SYNOPSIS
Returns the Computer SerialNumber
 
.DESCRIPTION
Returns the Computer SerialNumber
 
.LINK
https://osd.osdeploy.com/module/functions/system-information/get-ezcomputerserialnumber
 
.NOTES
21.1.28 Initial Release
#>

function Get-EZComputerSerialNumber {
    [CmdletBinding()]
    Param ()

    begin {
        $SerialNumber = Get-CimInstance -ClassName Win32_BIOS -ErrorAction SilentlyContinue | Select-Object -ExpandProperty SerialNumber
    }
    process {
        if ($null -eq $SerialNumber) {$SerialNumber = 'Unknown'}
        elseif ($SerialNumber -eq '') {$SerialNumber = 'Unknown'}

        $SerialNumber = $SerialNumber -replace ":", ""
    }
    end {
        Return $SerialNumber
    }
}