Skip to content

Instantly share code, notes, and snippets.

@jdhitsolutions
Last active July 11, 2019 16:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdhitsolutions/3df3f07f4091a8fd77e901446c056a18 to your computer and use it in GitHub Desktop.
Save jdhitsolutions/3df3f07f4091a8fd77e901446c056a18 to your computer and use it in GitHub Desktop.
A PowerShell function to test if a remote computer is a Nano installation.
#Requires -version 3.0
<#
Test-IsNanoServer.ps1
****************************************************************
* DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED *
* THOROUGHLY IN A LAB ENVIRONMENT. USE AT YOUR OWN RISK. IF *
* YOU DO NOT UNDERSTAND WHAT THIS SCRIPT DOES OR HOW IT WORKS, *
* DO NOT USE IT OUTSIDE OF A SECURE, TEST SETTING. *
****************************************************************
#>
Function Test-IsNanoServer {
[cmdletbinding()]
Param(
[parameter(
Mandatory,
ValueFromPipeline,
ValueFromPipelineByPropertyName,
HelpMessage = "Enter a computer name to test"
)]
[Alias("cn")]
[string[]]$Computername,
[PSCredential]$Credential,
[Switch]$Quiet
)
Begin {
Write-Verbose "[BEGIN ] Starting: $($MyInvocation.Mycommand)"
$PSBoundParameters.Remove("Quiet") | Out-Null
$PSBoundParameters.Remove("Computername") | Out-Null
} #begin
Process {
foreach ($Computer in $Computername) {
Write-Verbose "[PROCESS] Testing $Computer"
$PSBoundParameters.Computername = $Computer
Try {
Write-Verbose "[PROCESS] Creating a temporary CimSession"
$cs = New-CimSession @PSBoundParameters -ErrorAction Stop
}
Catch {
Write-Warning "Oops. $($_.exception.message)"
}
if ($cs) {
Write-Verbose "[PROCESS] Querying Win32_OperatingSystem"
$os = $cs | Get-CimInstance Win32_OperatingSystem
if ($os.OperatingSystemSKU -match "143|144") {
$IsNano = $True
}
else {
$IsNano = $False
}
if ($Quiet) {
$IsNano
}
else {
$OS | Select @{Name="Computername";Expression={$_.PSComputername.ToUpper()}},
Caption,OperatingSystemSKU,
@{Name="IsNano";Expression={$IsNano}}
}
Write-Verbose "[PROCESS] Removing temporary CimSession"
$cs | Remove-CimSession
}
}
} #process
End {
Write-Verbose "[END ] Ending: $($MyInvocation.Mycommand)"
} #end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment