PrivateFunctions/Get-WMI_OS.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
Function Get-WMI_OS
{
    <#
        .Synopsis
            Simple Private Function to test WMI connectivity on a remote machine
        .DESCRIPTION
            Simple Private Function to test WMI connectivity on a remote machine
            moving the Try...Catch block into isolation helps prevent any errors on the console
            Return is the WMI OS object when sucessfully connects, Null when it does not
        .EXAMPLE
            Get-WMI_OS -ComputerName "Server1"
    #>


    [CmdletBinding()]

    Param (
        [string]$ComputerName
    )

    Try {
        # Get-Wmiobject -ComputerName $ComputerName -Class Win32_OperatingSystem -ErrorAction Stop
        Get-CimInstance -ComputerName $ComputerName -ClassName Win32_OperatingSystem -ErrorAction Stop
    }
    Catch {$null}
}