Permalink
![Suite Suite](/uploads/1/2/5/8/125845691/431588664.jpg)
![Osproductsuite Osproductsuite](/uploads/1/2/5/8/125845691/115407979.png)
How to use WMIC to connect to remote machine and output OS information to a file? N/A N/A OSLanguage N/A N/A OSProductSuite N/A N/A OSType N/A N/A Organization N. Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell and WMI to obtain basic operating system information. Hey, Scripting Guy! I need to check on computers on my network to find out the operating system, service pack level, and whether the computer has been rebooted in the last 30 days.
All your code in one place
GitHub makes it easy to scale back on context switching. Read rendered documentation, see the history of any file, and collaborate with contributors on projects across GitHub.
Sign up for free See pricing for teams and enterprises Find file Copy path
Cannot retrieve contributors at this time
# Copyright (c) Microsoft Corporation. All rights reserved. |
# Licensed under the MIT License. |
# |
# TEST SPECIFIC HELPER METHODS FOR TESTING Get-ComputerInfo cmdlet |
# |
$computerInfoAll=$null |
$testStartTime=Get-Date |
functionGet-ComputerInfoForTest |
{ |
# NOTE: $forceRefresh only applies to the case where $properties is null |
param([string[]] $properties=$null, [switch] $forceRefresh) |
# non-windows systems show all tests as skipped so we can just return null |
# here because we won't ever look at it |
if ( !$IsWindows ) |
{ |
return$null |
} |
$computerInfo=$null |
if ( $properties ) |
{ |
returnGet-ComputerInfo-Property $properties |
} |
else |
{ |
# run once unless we really need to run again |
if ( $forceRefresh-or$null-eq$script:computerInfoAll) |
{ |
$script:computerInfoAll=Get-ComputerInfo |
} |
return$script:computerInfoAll |
} |
} |
functionGet-StringValuesFromValueMap |
{ |
param([string[]] $values, [hashtable] $valuemap) |
[string] $stringValues= [string]::Empty |
foreach ($valuein$values) |
{ |
if ($stringValues-ne [string]::Empty) |
{ |
$stringValues+=',' |
} |
$stringValues+=$valuemap[$value] |
} |
$stringValues |
} |
functionGet-PropertyNamesForComputerInfoTest |
{ |
$propertyNames=@() |
$propertyNames+=@('BiosBIOSVersion', |
'BiosBuildNumber', |
'BiosCaption', |
'BiosCharacteristics', |
'BiosCodeSet', |
'BiosCurrentLanguage', |
'BiosDescription', |
'BiosEmbeddedControllerMajorVersion', |
'BiosEmbeddedControllerMinorVersion', |
'BiosFirmwareType', |
'BiosIdentificationCode', |
'BiosInstallableLanguages', |
'BiosInstallDate', |
'BiosLanguageEdition', |
'BiosListOfLanguages', |
'BiosManufacturer', |
'BiosName', |
'BiosOtherTargetOS', |
'BiosPrimaryBIOS', |
'BiosReleaseDate', |
'BiosSerialNumber', |
'BiosSMBIOSBIOSVersion', |
'BiosSMBIOSPresent', |
'BiosSMBIOSMajorVersion', |
'BiosSMBIOSMinorVersion', |
'BiosSoftwareElementState', |
'BiosStatus', |
'BiosTargetOperatingSystem', |
'BiosVersion') |
$propertyNames+=@('CsAdminPasswordStatus', |
'CsAutomaticManagedPagefile', |
'CsAutomaticResetBootOption', |
'CsAutomaticResetCapability', |
'CsBootOptionOnLimit', |
'CsBootOptionOnWatchDog', |
'CsBootROMSupported', |
'CsBootStatus', |
'CsBootupState', |
'CsCaption', |
'CsChassisBootupState', |
'CsChassisSKUNumber', |
'CsCurrentTimeZone', |
'CsDaylightInEffect', |
'CsDescription', |
'CsDNSHostName', |
'CsDomain', |
'CsDomainRole', |
'CsEnableDaylightSavingsTime', |
'CsFrontPanelResetStatus', |
'CsHypervisorPresent', |
'CsInfraredSupported', |
'CsInitialLoadInfo', |
'CsInstallDate', |
'CsKeyboardPasswordStatus', |
'CsLastLoadInfo', |
'CsManufacturer', |
'CsModel', |
'CsName', |
'CsNetworkAdapters', |
'CsNetworkServerModeEnabled', |
'CsNumberOfLogicalProcessors', |
'CsNumberOfProcessors', |
'CsOEMStringArray', |
'CsPartOfDomain', |
'CsPauseAfterReset', |
'CsPCSystemType', |
'CsPCSystemTypeEx', |
'CsPhysicallyInstalledMemory', |
'CsPowerManagementCapabilities', |
'CsPowerManagementSupported', |
'CsPowerOnPasswordStatus', |
'CsPowerState', |
'CsPowerSupplyState', |
'CsPrimaryOwnerContact', |
'CsPrimaryOwnerName', |
'CsProcessors', |
'CsResetCapability', |
'CsResetCount', |
'CsResetLimit', |
'CsRoles', |
'CsStatus', |
'CsSupportContactDescription', |
'CsSystemFamily', |
'CsSystemSKUNumber', |
'CsSystemType', |
'CsThermalState', |
'CsTotalPhysicalMemory', |
'CsUserName', |
'CsWakeUpType', |
'CsWorkgroup') |
$propertyNames+=@('HyperVisorPresent', |
'HyperVRequirementDataExecutionPreventionAvailable', |
'HyperVRequirementSecondLevelAddressTranslation', |
'HyperVRequirementVirtualizationFirmwareEnabled', |
'HyperVRequirementVMMonitorModeExtensions') |
$propertyNames+=@('OsArchitecture', |
'OsBootDevice', |
'OsBuildNumber', |
'OsBuildType', |
'OsCodeSet', |
'OsCountryCode', |
'OsCSDVersion', |
'OsCurrentTimeZone', |
'OsDataExecutionPrevention32BitApplications', |
'OsDataExecutionPreventionAvailable', |
'OsDataExecutionPreventionDrivers', |
'OsDataExecutionPreventionSupportPolicy', |
'OsDebug', |
'OsDistributed', |
'OsEncryptionLevel', |
'OsForegroundApplicationBoost', |
'OsHardwareAbstractionLayer', |
'OsHotFixes', |
'OsInstallDate', |
'OsLanguage', |
'OsLastBootUpTime', |
'OsLocale', |
'OsLocaleID', |
'OsManufacturer', |
'OsMaxProcessMemorySize', |
'OsMuiLanguages', |
'OsName', |
'OsNumberOfLicensedUsers', |
'OsNumberOfUsers', |
'OsOperatingSystemSKU', |
'OsOrganization', |
'OsOtherTypeDescription', |
'OsPAEEnabled', |
'OsPagingFiles', |
'OsPortableOperatingSystem', |
'OsPrimary', |
'OsProductSuites', |
'OsProductType', |
'OsRegisteredUser', |
'OsSerialNumber', |
'OsServerLevel', |
'OsServicePackMajorVersion', |
'OsServicePackMinorVersion', |
'OsSizeStoredInPagingFiles', |
'OsStatus', |
'OsSuites', |
'OsSystemDevice', |
'OsSystemDirectory', |
'OsSystemDrive', |
'OsTotalSwapSpaceSize', |
'OsTotalVirtualMemorySize', |
'OsTotalVisibleMemorySize', |
'OsType', |
'OsVersion', |
'OsWindowsDirectory') |
$propertyNames+=@('KeyboardLayout', |
'LogonServer', |
'PowerPlatformRole', |
'TimeZone') |
$WindowsPropertyArray=@('WindowsBuildLabEx', |
'WindowsCurrentVersion', |
'WindowsEditionId', |
'WindowsInstallationType', |
'WindowsProductId', |
'WindowsProductName', |
'WindowsRegisteredOrganization', |
'WindowsRegisteredOwner', |
'WindowsSystemRoot', |
'WindowsVersion', |
'WindowsUBR') |
if ([System.Management.Automation.Platform]::IsIoT) |
{ |
Write-Verbose-Verbose -Message 'WindowsInstallDateFromRegistry is not supported on IoT.' |
} |
else |
{ |
$WindowsPropertyArray+='WindowsInstallDateFromRegistry' |
} |
$propertyNames+=$WindowsPropertyArray |
return$propertyNames |
} |
functionNew-ExpectedComputerInfo |
{ |
param([string[]]$propertyNames) |
# create a spoofed object for non-windows to be used |
if ( !$IsWindows ) |
{ |
$expected=New-Object-TypeName PSObject |
foreach ($propertyNamein [string[]]$propertyNames) |
{ |
Add-Member-MemberType NoteProperty -Name $propertyName-Value $null-InputObject $expected |
} |
return$expected |
} |
# P-INVOKE TYPE DEF START ****************************************** |
functionGet-FirmwareType |
{ |
$signature=@' |
[DllImport('kernel32.dll')] |
public static extern bool GetFirmwareType(ref uint firmwareType); |
'@ |
Add-Type-MemberDefinition $signature-Name 'Win32BiosFirmwareType'-Namespace Win32Functions -PassThru |
} |
functionGet-PhysicallyInstalledSystemMemory |
{ |
$signature=@' |
[DllImport('kernel32.dll')] |
[return: MarshalAs(UnmanagedType.Bool)] |
public static extern bool GetPhysicallyInstalledSystemMemory(out ulong MemoryInKilobytes); |
'@ |
Add-Type-MemberDefinition $signature-Name 'Win32PhyicallyInstalledMemory'-Namespace Win32Functions -PassThru |
} |
functionGet-PhysicallyInstalledSystemMemoryCore |
{ |
$signature=@' |
[DllImport('api-ms-win-core-sysinfo-l1-2-1.dll')] |
[return: MarshalAs(UnmanagedType.Bool)] |
public static extern bool GetPhysicallyInstalledSystemMemory(out ulong MemoryInKilobytes); |
'@ |
Add-Type-MemberDefinition $signature-Name 'Win32PhyicallyInstalledMemory'-Namespace Win32Functions -PassThru |
} |
functionGet-PowerDeterminePlatformRole |
{ |
$signature=@' |
[DllImport('Powrprof', EntryPoint = 'PowerDeterminePlatformRoleEx', CharSet = CharSet.Ansi)] |
public static extern uint PowerDeterminePlatformRoleEx(uint version); |
'@ |
Add-Type-MemberDefinition $signature-Name 'Win32PowerDeterminePlatformRole'-Namespace Win32Functions -PassThru |
} |
functionGet-LCIDToLocaleName |
{ |
$signature=@' |
[DllImport('kernel32.dll', SetLastError = true, CharSet = CharSet.Unicode)] |
public static extern int LCIDToLocaleName(uint localeID, System.Text.StringBuilder localeName, int localeNameSize, int flags); |
'@ |
Add-Type-MemberDefinition $signature-Name 'Win32LCIDToLocaleNameDllName'-Namespace Win32Functions -PassThru |
} |
# P-INVOKE TYPE DEF END ****************************************** |
# HELPER METHODS RELYING ON P-INVOKE BEGIN ****************************************** |
functionGet-BiosFirmwareType |
{ |
[int]$firmwareType=0 |
$null= (Get-FirmwareType)::GetFirmwareType([ref]$firmwareType) |
return$firmwareType |
} |
functionGet-CsPhysicallyInstalledSystemMemory |
{ |
param([bool]$isCore=$false) |
# TODO: we need to add support for tests running on core |
# but for now, test is for non-core |
[int] $memoryInKilobytes=0 |
if ($isCore) |
{ |
$null= (Get-PhysicallyInstalledSystemMemoryCore)::GetPhysicallyInstalledSystemMemory([ref]$memoryInKilobytes) |
} |
else |
{ |
$null= (Get-PhysicallyInstalledSystemMemory)::GetPhysicallyInstalledSystemMemory([ref]$memoryInKilobytes) |
} |
return$memoryInKilobytes |
} |
functionGet-PowerPlatformRole |
{ |
$version=0x2 |
$powerRole= (Get-PowerDeterminePlatformRole)::PowerDeterminePlatformRoleEx($version) |
if ($powerRole-gt9) |
{ |
$powerRole=0 |
} |
return$powerRole |
} |
# HELPER METHODS RELYING ON P-INVOKE END ****************************************** |
$cimClassList=@{} |
functionGet-CimClass |
{ |
param([string]$className, [string] $namespace='rootcimv2') |
if (-not$cimClassList.ContainsKey($className)) |
{ |
$cimClassInstance=Get-CimInstance-ClassName $className-Namespace $namespace |
$cimClassList.Add($className,$cimClassInstance) |
} |
return$cimClassList.Get_Item($className) |
} |
functionGet-CimClassPropVal |
{ |
param([string]$className, [string]$propertyName, [string] $namespace='rootcimv2') |
$cimClassInstance=Get-CimClass$className$namespace |
$cimClassInstance.$propertyName |
} |
functionGet-CsNetworkAdapters |
{ |
$networkAdapters=@() |
$adapters=Get-CimClass Win32_NetworkAdapter |
$configs=Get-CimClass Win32_NetworkAdapterConfiguration |
# easy-out: no adapters or configs |
if (!$adapters-or!$configs) { return$null } |
# build config hashtable |
$configHash=@{} |
foreach ($configin$configs) |
{ |
if ($null-ne$config.Index) |
{ |
$configHash.Add([string]$config.Index,$config) |
} |
} |
# easy-out: no config hash items |
if ($configHash.Count-eq0) { return$null } |
foreach ($adapterin$adapters) |
{ |
# Easy skip: adapters that have a null connection status or null index |
if (!$adapter.NetConnectionStatus) { continue } |
# Easy skip: configHash does not contain adapter |
if (!$configHash.ContainsKey([string]$adapter.Index)) { continue } |
$connectionStatus=13# default NetConnectionStatus.Other |
if ($adapter.NetConnectionStatus) { $connectionStatus=$adapter.NetConnectionStatus} |
$config=$configHash.Item([string]$adapter.Index) |
$dHCPEnabled=$null |
$dHCPServer=$null |
$ipAddresses=$null |
if ($connectionStatus-eq2) # 2 = NetConnectionStatus.Connected |
{ |
$dHCPEnabled=$config.DHCPEnabled |
$dHCPServer=$config.DHCPServer; |
$ipAddresses=$config.IPAddress; |
} |
# new-up one adapter object |
$properties= |
@{ |
'Description'=$adapter.Description; |
'ConnectionID'=$adapter.NetConnectionID; |
'ConnectionStatus'=$connectionStatus; |
'DHCPEnabled'=$dHCPEnabled; |
'DHCPServer'=$dHCPServer; |
'IPAddresses'=$ipAddresses; |
} |
$networkAdapter=New-Object-TypeName PSObject -Prop $properties |
# add adapter to list |
$networkAdapters+=$networkAdapter |
} |
return$networkAdapters |
} |
functionGet-CsProcessors |
{ |
$processors=Get-CimClass Win32_Processor |
if (!$processors) {return$null } |
$csProcessors=@() |
foreach ($processorin$processors) |
{ |
# new-up one adapter object |
$properties= |
@{ |
'Name'=$processor.Name; |
'Manufacturer'=$processor.Manufacturer; |
'Description'=$processor.Description; |
'Architecture'=$processor.Architecture; |
'AddressWidth'=$processor.AddressWidth; |
'Availability'=$processor.Availability; |
'CpuStatus'=$processor.CpuStatus; |
'CurrentClockSpeed'=$processor.CurrentClockSpeed; |
'DataWidth'=$processor.DataWidth; |
'MaxClockSpeed'=$processor.MaxClockSpeed; |
'NumberOfCores'=$processor.NumberOfCores; |
'NumberOfLogicalProcessors'=$processor.NumberOfLogicalProcessors; |
'ProcessorID'=$processor.ProcessorID; |
'ProcessorType'=$processor.ProcessorType; |
'Role'=$processor.Role; |
'SocketDesignation'=$processor.SocketDesignation; |
'Status'=$processor.Status; |
} |
$csProcessor=New-Object-TypeName PSObject -Prop $properties |
# add adapter to list |
$csProcessors+=$csProcessor |
} |
$csProcessors |
} |
functionGet-OsHardwareAbstractionLayer |
{ |
$hal=$null |
$systemDirectory=Get-CimClassPropVal Win32_OperatingSystem SystemDirectory |
$halPath=Join-Path-path $systemDirectory-ChildPath 'hal.dll' |
$query='SELECT * FROM CIM_DataFile Where Name='C:WINDOWSsystem32hal.dll'' |
$query=$query-replace'','' |
$instance=Get-CimInstance-Query $query |
if ($instance) |
{ |
$hal= [string]$instance[0].CimInstanceProperties['Version'].Value |
} |
return$hal |
} |
functionGet-OsHotFixes |
{ |
$hotfixes=Get-CimClass Win32_QuickFixEngineering |Select-Object-Property HotFixID,Description,InstalledOn,FixComments |
if (!$hotfixes) {return$null } |
$osHotFixes=@() |
foreach ($hotfixin$hotfixes) |
{ |
$installedOn=$null |
if ($hotfix.InstalledOn) |
{ |
$installedOn=$hotfix.InstalledOn.ToString('M/d/yyyy') |
} |
# new-up one adapter object |
$properties= |
@{ |
'HotFixID'=$hotfix.HotFixID; |
'Description'=$hotfix.Description; |
'InstalledOn'=$installedOn; |
'FixComments'=$hotfix.FixComments; |
} |
$osHotFix=New-Object-TypeName PSObject -Prop $properties |
# add adapter to list |
$osHotFixes+=$osHotFix |
} |
$osHotFixes |
} |
functionGet-OsInUseVirtualMemory |
{ |
$osInUseVirtualMemory=$null |
$os=Get-CimClass Win32_OperatingSystem |
$totalVirtualMemorySize=$os.TotalVirtualMemorySize |
$freeVirtualMemory=$os.FreeVirtualMemory |
if (($totalVirtualMemorySize) -and ($freeVirtualMemory)) |
{ |
$osInUseVirtualMemory=$totalVirtualMemorySize-$freeVirtualMemory |
} |
return$osInUseVirtualMemory |
} |
functionGet-OsServerLevel |
{ |
# translated from cmldet logic (1) RegistryInfo.GetServerLevels; and (2) os.GetOtherInfo() |
$subkey='SoftwareMicrosoftWindows NTCurrentVersionServerServerLevels' |
$regKey= [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey($subkey) |
$serverLevels=@{} |
try |
{ |
if ($null-ne$regKey) |
{ |
$serverLevelNames=$regKey.GetValueNames() |
foreach ($serverLevelNamein$serverLevelNames) |
{ |
if ($regKey.GetValueKind($serverLevelName) -eq4) # RegistryValueKind.DWord 4 |
{ |
$val=$regKey.GetValue($serverLevelName) |
$serverLevels.Add($serverLevelName, [System.Convert]::ToUInt32($val)) |
} |
} |
} |
} |
finally |
{ |
if ($null-ne$regKey) { $regKey.Dispose()} |
} |
if ($null-eq$serverLevels-or$serverLevels.Count-eq0) |
{ |
return$null |
} |
[uint32]$rv |
# computerinfo enum ServerLevel |
# 0 = Unknown |
# 1 = NanoServer |
# 2 = ServerCore |
# 3 = ServerCoreWithManagementTools |
# 4 = FullServer |
if ($serverLevels.ContainsKey('NanoServer') -and$serverLevels['NanoServer'] -eq1) |
{ |
$rv=1# NanoServer |
} |
elseif ($serverLevels.ContainsKey('ServerCore') -and$serverLevels['ServerCore'] -eq1) |
{ |
$rv=2# ServerCore |
if ($serverLevels.ContainsKey('Server-Gui-Mgmt') -and$serverLevels['Server-Gui-Mgmt'] -eq1) |
{ |
$rv=3# ServerCoreWithManagementTools |
if ($serverLevels.ContainsKey('Server-Gui-Shell') -and$serverLevels['Server-Gui-Shell'] -eq1) |
{ |
$rv=4# FullServer |
} |
} |
} |
return$rv |
} |
functionGet-OsSuites |
{ |
param($propertyName) |
$osProductSuites=@() |
$suiteMask=Get-CimClassPropVal Win32_OperatingSystem $propertyName |
if ($suiteMask) |
{ |
foreach($suitein [System.Enum]::GetValues('Microsoft.PowerShell.Commands.OSProductSuite')) |
{ |
if (($suiteMask-band$suite) -ne0) |
{ |
$osProductSuites+=$suite |
} |
} |
} |
return$osProductSuites |
} |
functionGet-HyperVProperty |
{ |
param([string]$propertyName) |
$hypervisorPresent=Get-CimClassPropVal Win32_ComputerSystem HypervisorPresent |
$dataExecutionPrevention_Available=$null |
$secondLevelAddressTranslationExtensions=$null |
$virtualizationFirmwareEnabled=$null |
$vMMonitorModeExtensions=$null |
if (($null-ne$hypervisorPresent) -and ($hypervisorPresent-ne$true)) |
{ |
$dataExecutionPrevention_Available=Get-CimClassPropVal Win32_OperatingSystem DataExecutionPrevention_Available |
$secondLevelAddressTranslationExtensions=Get-CimClassPropVal Win32_Processor SecondLevelAddressTranslationExtensions |
$virtualizationFirmwareEnabled=Get-CimClassPropVal Win32_Processor VirtualizationFirmwareEnabled |
$vMMonitorModeExtensions=Get-CimClassPropVal Win32_Processor VMMonitorModeExtensions |
} |
switch ($propertyName) |
{ |
'HyperVisorPresent' { return$hypervisorPresent } |
'HyperVRequirementDataExecutionPreventionAvailable' { return$dataExecutionPrevention_Available } |
'HyperVRequirementSecondLevelAddressTranslation'{ return$secondLevelAddressTranslationExtensions } |
'HyperVRequirementVirtualizationFirmwareEnabled'{ return$virtualizationFirmwareEnabled } |
'HyperVRequirementVMMonitorModeExtensions' { return$vMMonitorModeExtensions } |
} |
} |
functionGet-KeyboardLayout |
{ |
$keyboards=Get-CimClass Win32_Keyboard |
$result=$null |
if ($keyboards) |
{ |
# cmdlet code comment TODO: handle multiple keyboards? |
# there might be several keyboards found. For the moment |
# we display info for only one |
$layout=$keyboards[0].Layout |
try |
{ |
$layoutAsHex= [System.Convert]::ToUInt32($layout,16) |
if ($null-ne$layoutAsHex) |
{ |
$result=Convert-LocaleIdToLocaleName$layoutAsHex |
} |
} |
catch |
{ |
#swallow |
} |
} |
return$result |
} |
functionGet-OsLanguageName |
{ |
# updated 21May 2016 to follow updated logic from cmdlet |
$localeID=Get-CimClassPropVal Win32_OperatingSystem OSLanguage |
returnConvert-LocaleIdToLocaleName$localeID |
} |
functionConvert-LocaleIdToLocaleName |
{ |
# This is a migrated/translated version of the cmdlet method = LocaleIdToLocaleName() |
# THIS is the comment from the cmdlet |
# CoreCLR's System.Globalization.Culture does not appear to have a constructor |
# that accepts an integer LocalID (LCID) value, so we'll PInvoke native code |
# to get a locale name from an LCID value |
param($localeID) |
$sb= (New-Object System.Text.StringBuilder([int]85)) # 85 = Native.LOCALE_NAME_MAX_LENGTH |
$len= (Get-LCIDToLocaleName)::LCIDToLocaleName($localeID,$sb,$sb.Capacity,0) |
if (($len-gt0) -and ($sb.Length-gt0)) |
{ |
return$sb.ToString() |
} |
return$null |
} |
functionGet-Locale |
{ |
# This is a migrated/translated version of the cmdlet method = Conversion.MakeLocale() |
# This method first tries to convert the string to a hex value |
# and get the CultureInfo object from that value. |
# Failing that it attempts to retrieve the CultureInfo object |
# using the locale string as passed. |
$localeName=$null |
$locale=Get-CimClassPropVal Win32_OperatingSystem Locale |
if ($null-ne$locale) |
{ |
#$localeAsHex = $locale -as [hex] |
$localeAsHex= [System.Convert]::ToUInt32($locale,16) |
if ($null-ne$localeAsHex) |
{ |
try |
{ |
$localeName=Convert-LocaleIdToLocaleName$localeAsHex |
} |
catch |
{ |
# swallow this |
# DEBUGGING |
#return $_.Exception.Message |
} |
} |
if ($null-eq$localeName) |
{ |
try |
{ |
$cultureInfo= (New-Object System.Globalization.CultureInfo($locale)) |
$localeName=$cultureInfo.Name |
} |
catch |
{ |
# swallow this |
} |
} |
} |
return$localeName |
} |
functionGet-OsPagingFiles |
{ |
$osPagingFiles=@() |
$pageFileUsage=Get-CimClass Win32_PageFileUsage |
if ($null-ne$pageFileUsage) |
{ |
foreach ($pageFileItemin$pageFileUsage) |
{ |
$osPagingFiles+=$pageFileItem.Caption |
} |
} |
return [string[]]$osPagingFiles |
} |
functionGet-UnixSecondsToDateTime |
{ |
param([string]$seconds) |
$origin=New-Object-Type DateTime -ArgumentList 1970,1,1,0,0,0,0 |
$origin.AddSeconds($seconds) |
} |
functionGet-WinNtCurrentVersion |
{ |
# This method was translated/converted from cmdlet impl method = RegistryInfo.GetWinNtCurrentVersion(); |
param([string]$propertyName) |
$key='HKLM:SoftwareMicrosoftWindows NTCurrentVersion' |
$regValue= (Get-ItemProperty-Path $key-Name $propertyName-ErrorAction SilentlyContinue).$propertyName |
if ($propertyName-eq'InstallDate') |
{ |
# more complicated case: InstallDate |
if ($regValue) |
{ |
returnGet-UnixSecondsToDateTime$regValue |
} |
} |
else |
{ |
return$regValue |
} |
return$null |
} |
functionGet-ExpectedComputerInfoValue |
{ |
param([string]$propertyName) |
switch ($propertyName) |
{ |
'BiosBIOSVersion' {returnGet-CimClassPropVal Win32_bios BiosVersion} |
'BiosBuildNumber' {returnGet-CimClassPropVal Win32_bios BuildNumber} |
'BiosCaption' {returnGet-CimClassPropVal Win32_bios Caption} |
'BiosCharacteristics' {returnGet-CimClassPropVal Win32_bios BiosCharacteristics} |
'BiosCodeSet' {returnGet-CimClassPropVal Win32_bios CodeSet} |
'BiosCurrentLanguage' {returnGet-CimClassPropVal Win32_bios CurrentLanguage} |
'BiosDescription' {returnGet-CimClassPropVal Win32_bios Description} |
'BiosEmbeddedControllerMajorVersion' {returnGet-CimClassPropVal Win32_bios EmbeddedControllerMajorVersion} |
'BiosEmbeddedControllerMinorVersion' {returnGet-CimClassPropVal Win32_bios EmbeddedControllerMinorVersion} |
'BiosFirmwareType' {returnGet-BiosFirmwareType} |
'BiosIdentificationCode' {returnGet-CimClassPropVal Win32_bios IdentificationCode} |
'BiosInstallableLanguages' {returnGet-CimClassPropVal Win32_bios InstallableLanguages} |
'BiosInstallDate' {returnGet-CimClassPropVal Win32_bios InstallDate} |
'BiosLanguageEdition' {returnGet-CimClassPropVal Win32_bios LanguageEdition} |
'BiosListOfLanguages' {returnGet-CimClassPropVal Win32_bios ListOfLanguages} |
'BiosManufacturer' {returnGet-CimClassPropVal Win32_bios Manufacturer} |
'BiosName' {returnGet-CimClassPropVal Win32_bios Name} |
'BiosOtherTargetOS' {returnGet-CimClassPropVal Win32_bios OtherTargetOS} |
'BiosPrimaryBIOS' {returnGet-CimClassPropVal Win32_bios PrimaryBIOS} |
'BiosReleaseDate' {returnGet-CimClassPropVal Win32_bios ReleaseDate} |
'BiosSerialNumber' {returnGet-CimClassPropVal Win32_bios SerialNumber} |
'BiosSMBIOSBIOSVersion' {returnGet-CimClassPropVal Win32_bios SMBIOSBIOSVersion} |
'BiosSMBIOSPresent' {returnGet-CimClassPropVal Win32_bios SMBIOSPresent} |
'BiosSMBIOSMajorVersion' {returnGet-CimClassPropVal Win32_bios SMBIOSMajorVersion} |
'BiosSMBIOSMinorVersion' {returnGet-CimClassPropVal Win32_bios SMBIOSMinorVersion} |
'BiosSoftwareElementState' {returnGet-CimClassPropVal Win32_bios SoftwareElementState} |
'BiosStatus' {returnGet-CimClassPropVal Win32_bios Status} |
'BiosSystemBiosMajorVersion' {returnGet-CimClassPropVal Win32_bios SystemBiosMajorVersion} |
'BiosSystemBiosMinorVersion' {returnGet-CimClassPropVal Win32_bios SystemBiosMinorVersion} |
'BiosTargetOperatingSystem' {returnGet-CimClassPropVal Win32_bios TargetOperatingSystem} |
'BiosVersion' {returnGet-CimClassPropVal Win32_bios Version} |
'CsAdminPasswordStatus' {returnGet-CimClassPropVal Win32_ComputerSystem AdminPasswordStatus} |
'CsAutomaticManagedPagefile' {returnGet-CimClassPropVal Win32_ComputerSystem AutomaticManagedPagefile} |
'CsAutomaticResetBootOption' {returnGet-CimClassPropVal Win32_ComputerSystem AutomaticResetBootOption} |
'CsAutomaticResetCapability' {returnGet-CimClassPropVal Win32_ComputerSystem AutomaticResetCapability} |
'CsBootOptionOnLimit' {returnGet-CimClassPropVal Win32_ComputerSystem BootOptionOnLimit} |
'CsBootOptionOnWatchDog' {returnGet-CimClassPropVal Win32_ComputerSystem BootOptionOnWatchDog} |
'CsBootROMSupported' {returnGet-CimClassPropVal Win32_ComputerSystem BootROMSupported} |
'CsBootStatus' {returnGet-CimClassPropVal Win32_ComputerSystem BootStatus} |
'CsBootupState' {returnGet-CimClassPropVal Win32_ComputerSystem BootupState} |
'CsCaption' {returnGet-CimClassPropVal Win32_ComputerSystem Caption} |
'CsChassisBootupState' {returnGet-CimClassPropVal Win32_ComputerSystem ChassisBootupState} |
'CsChassisSKUNumber' {returnGet-CimClassPropVal Win32_ComputerSystem ChassisSKUNumber} |
'CsCurrentTimeZone' {returnGet-CimClassPropVal Win32_ComputerSystem CurrentTimeZone} |
'CsDaylightInEffect' {returnGet-CimClassPropVal Win32_ComputerSystem DaylightInEffect} |
'CsDescription' {returnGet-CimClassPropVal Win32_ComputerSystem Description} |
'CsDNSHostName' {returnGet-CimClassPropVal Win32_ComputerSystem DNSHostName} |
'CsDomain' {returnGet-CimClassPropVal Win32_ComputerSystem Domain} |
'CsDomainRole' {returnGet-CimClassPropVal Win32_ComputerSystem DomainRole} |
'CsEnableDaylightSavingsTime' {returnGet-CimClassPropVal Win32_ComputerSystem EnableDaylightSavingsTime} |
'CsFrontPanelResetStatus' {returnGet-CimClassPropVal Win32_ComputerSystem FrontPanelResetStatus} |
'CsHypervisorPresent' {returnGet-CimClassPropVal Win32_ComputerSystem HypervisorPresent} |
'CsInfraredSupported' {returnGet-CimClassPropVal Win32_ComputerSystem InfraredSupported} |
'CsInitialLoadInfo' {returnGet-CimClassPropVal Win32_ComputerSystem InitialLoadInfo} |
'CsInstallDate' {returnGet-CimClassPropVal Win32_ComputerSystem InstallDate} |
'CsKeyboardPasswordStatus' {returnGet-CimClassPropVal Win32_ComputerSystem KeyboardPasswordStatus} |
'CsLastLoadInfo' {returnGet-CimClassPropVal Win32_ComputerSystem LastLoadInfo} |
'CsManufacturer' {returnGet-CimClassPropVal Win32_ComputerSystem Manufacturer} |
'CsModel' {returnGet-CimClassPropVal Win32_ComputerSystem Model} |
'CsName' {returnGet-CimClassPropVal Win32_ComputerSystem Name} |
'CsNetworkAdapters' { returnGet-CsNetworkAdapters } |
'CsNetworkServerModeEnabled' {returnGet-CimClassPropVal Win32_ComputerSystem NetworkServerModeEnabled} |
'CsNumberOfLogicalProcessors' {return [System.Environment]::GetEnvironmentVariable('NUMBER_OF_PROCESSORS')} |
'CsNumberOfProcessors' {returnGet-CimClassPropVal Win32_ComputerSystem NumberOfProcessors } |
'CsOEMStringArray' {returnGet-CimClassPropVal Win32_ComputerSystem OEMStringArray} |
'CsPartOfDomain' {returnGet-CimClassPropVal Win32_ComputerSystem PartOfDomain} |
'CsPauseAfterReset' {returnGet-CimClassPropVal Win32_ComputerSystem PauseAfterReset} |
'CsPCSystemType' {returnGet-CimClassPropVal Win32_ComputerSystem PCSystemType} |
'CsPCSystemTypeEx' {returnGet-CimClassPropVal Win32_ComputerSystem PCSystemTypeEx} |
'CsPhysicallyInstalledMemory' {returnGet-CsPhysicallyInstalledSystemMemory} |
'CsPowerManagementCapabilities' {returnGet-CimClassPropVal Win32_ComputerSystem PowerManagementCapabilities} |
'CsPowerManagementSupported' {returnGet-CimClassPropVal Win32_ComputerSystem PowerManagementSupported} |
'CsPowerOnPasswordStatus' {returnGet-CimClassPropVal Win32_ComputerSystem PowerOnPasswordStatus} |
'CsPowerState' {returnGet-CimClassPropVal Win32_ComputerSystem PowerState} |
'CsPowerSupplyState' {returnGet-CimClassPropVal Win32_ComputerSystem PowerSupplyState} |
'CsPrimaryOwnerContact' {returnGet-CimClassPropVal Win32_ComputerSystem PrimaryOwnerContact} |
'CsPrimaryOwnerName' {returnGet-CimClassPropVal Win32_ComputerSystem PrimaryOwnerName} |
'CsProcessors' { returnGet-CsProcessors } |
'CsResetCapability' {returnGet-CimClassPropVal Win32_ComputerSystem ResetCapability} |
'CsResetCount' {returnGet-CimClassPropVal Win32_ComputerSystem ResetCount} |
'CsResetLimit' {returnGet-CimClassPropVal Win32_ComputerSystem ResetLimit} |
'CsRoles' {returnGet-CimClassPropVal Win32_ComputerSystem Roles} |
'CsStatus' {returnGet-CimClassPropVal Win32_ComputerSystem Status} |
'CsSupportContactDescription' {returnGet-CimClassPropVal Win32_ComputerSystem SupportContactDescription} |
'CsSystemFamily' {returnGet-CimClassPropVal Win32_ComputerSystem SystemFamily} |
'CsSystemSKUNumber' {returnGet-CimClassPropVal Win32_ComputerSystem SystemSKUNumber} |
'CsSystemType' {returnGet-CimClassPropVal Win32_ComputerSystem SystemType} |
'CsThermalState' {returnGet-CimClassPropVal Win32_ComputerSystem ThermalState} |
'CsTotalPhysicalMemory' {returnGet-CimClassPropVal Win32_ComputerSystem TotalPhysicalMemory} |
'CsUserName' {returnGet-CimClassPropVal Win32_ComputerSystem UserName} |
'CsWakeUpType' {returnGet-CimClassPropVal Win32_ComputerSystem WakeUpType} |
'CsWorkgroup' {returnGet-CimClassPropVal Win32_ComputerSystem Workgroup} |
'HyperVisorPresent' {returnGet-HyperVProperty$propertyName} |
'HyperVRequirementDataExecutionPreventionAvailable' {returnGet-HyperVProperty$propertyName} |
'HyperVRequirementSecondLevelAddressTranslation' {returnGet-HyperVProperty$propertyName} |
'HyperVRequirementVirtualizationFirmwareEnabled' {returnGet-HyperVProperty$propertyName} |
'HyperVRequirementVMMonitorModeExtensions' {returnGet-HyperVProperty$propertyName} |
'KeyboardLayout' {returnGet-KeyboardLayout} |
'LogonServer' {return [Microsoft.Win32.Registry]::GetValue('HKEY_Current_UserVolatile Environment','LOGONSERVER','')} |
'OsArchitecture' {returnGet-CimClassPropVal Win32_OperatingSystem OsArchitecture} |
'OsBootDevice' {returnGet-CimClassPropVal Win32_OperatingSystem BootDevice} |
'OsBuildNumber' {returnGet-CimClassPropVal Win32_OperatingSystem BuildNumber} |
'OsBuildType' {returnGet-CimClassPropVal Win32_OperatingSystem BuildType} |
'OsCodeSet' {returnGet-CimClassPropVal Win32_OperatingSystem CodeSet} |
'OsCountryCode' {returnGet-CimClassPropVal Win32_OperatingSystem CountryCode} |
'OsCSDVersion' {returnGet-CimClassPropVal Win32_OperatingSystem CSDVersion} |
'OsCurrentTimeZone' {returnGet-CimClassPropVal Win32_OperatingSystem CurrentTimeZone} |
'OsDataExecutionPrevention32BitApplications' {returnGet-CimClassPropVal Win32_OperatingSystem DataExecutionPrevention_32BitApplications} |
'OsDataExecutionPreventionAvailable' {returnGet-CimClassPropVal Win32_OperatingSystem DataExecutionPrevention_Available} |
'OsDataExecutionPreventionDrivers' {returnGet-CimClassPropVal Win32_OperatingSystem DataExecutionPrevention_Drivers} |
'OsDataExecutionPreventionSupportPolicy' {returnGet-CimClassPropVal Win32_OperatingSystem DataExecutionPrevention_SupportPolicy} |
'OsDebug' {returnGet-CimClassPropVal Win32_OperatingSystem Debug} |
'OsDistributed' {returnGet-CimClassPropVal Win32_OperatingSystem Distributed} |
'OsEncryptionLevel' {returnGet-CimClassPropVal Win32_OperatingSystem EncryptionLevel} |
'OsForegroundApplicationBoost' {returnGet-CimClassPropVal Win32_OperatingSystem ForegroundApplicationBoost} |
# OsFreePhysicalMemory => fragile test: fluid/dynamic (see special cases) |
#'OsFreeSpaceInPagingFiles' {return Get-CimClassPropVal Win32_OperatingSystem FreePhysicalMemory} |
# OsFreeSpaceInPagingFiles => fragile test: fluid/dynamic (see special cases) |
#'OsFreeSpaceInPagingFiles' {return Get-CimClassPropVal Win32_OperatingSystem FreeSpaceInPagingFiles} |
# OsFreeVirtualMemory => fragile test: fluid/dynamic (see special cases) |
#'OsFreeVirtualMemory' {return Get-CimClassPropVal Win32_OperatingSystem FreeVirtualMemory} |
'OsHardwareAbstractionLayer' {returnGet-OsHardwareAbstractionLayer} |
'OsHotFixes' {returnGet-OsHotFixes } |
'OsInstallDate' {returnGet-CimClassPropVal Win32_OperatingSystem InstallDate} |
'OsInUseVirtualMemory' { returnGet-OsInUseVirtualMemory } |
'OsLanguage' {returnGet-OsLanguageName} |
'OsLastBootUpTime' {returnGet-CimClassPropVal Win32_OperatingSystem LastBootUpTime} |
# OsLocalDateTime => fragile test: fluid/dynamic (see special cases) |
#'OsLocalDateTime' {return Get-CimClassPropVal Win32_OperatingSystem LocalDateTime} |
'OsLocale' {returnGet-Locale} |
'OsLocaleID' {returnGet-CimClassPropVal Win32_OperatingSystem Locale} |
'OsManufacturer' {returnGet-CimClassPropVal Win32_OperatingSystem Manufacturer} |
'OsMaxNumberOfProcesses' {returnGet-CimClassPropVal Win32_OperatingSystem MaxNumberOfProcesses} |
'OsMaxProcessMemorySize' {returnGet-CimClassPropVal Win32_OperatingSystem MaxProcessMemorySize} |
'OsMuiLanguages' {returnGet-CimClassPropVal Win32_OperatingSystem MuiLanguages} |
'OsName' {returnGet-CimClassPropVal Win32_OperatingSystem Caption} |
'OsNumberOfLicensedUsers' {returnGet-CimClassPropVal Win32_OperatingSystem NumberOfLicensedUsers} |
# OsNumberOfProcesses => fragile test: fluid/dynamic |
#'OsNumberOfProcesses' {return Get-CimClassPropVal Win32_OperatingSystem NumberOfProcesses} |
'OsNumberOfUsers' {returnGet-CimClassPropVal Win32_OperatingSystem NumberOfUsers} |
'OsOperatingSystemSKU' {returnGet-CimClassPropVal Win32_OperatingSystem OperatingSystemSKU} |
'OsOrganization' {returnGet-CimClassPropVal Win32_OperatingSystem Organization} |
'OsOtherTypeDescription' {returnGet-CimClassPropVal Win32_OperatingSystem OtherTypeDescription} |
'OsPAEEnabled' {returnGet-CimClassPropVal Win32_OperatingSystem PAEEnabled} |
'OsPagingFiles' {returnGet-OsPagingFiles} |
'OsPortableOperatingSystem' {returnGet-CimClassPropVal Win32_OperatingSystem PortableOperatingSystem} |
'OsPrimary' {returnGet-CimClassPropVal Win32_OperatingSystem Primary} |
'OsProductSuites' {returnGet-OsSuites OSProductSuite } |
'OsProductType' {returnGet-CimClassPropVal Win32_OperatingSystem ProductType} |
'OsRegisteredUser' {returnGet-CimClassPropVal Win32_OperatingSystem RegisteredUser} |
'OsSerialNumber' {returnGet-CimClassPropVal Win32_OperatingSystem SerialNumber} |
'OsServerLevel' {returnGet-OsServerLevel} |
'OsServicePackMajorVersion' {returnGet-CimClassPropVal Win32_OperatingSystem ServicePackMajorVersion} |
'OsServicePackMinorVersion' {returnGet-CimClassPropVal Win32_OperatingSystem ServicePackMinorVersion} |
'OsSizeStoredInPagingFiles' {returnGet-CimClassPropVal Win32_OperatingSystem SizeStoredInPagingFiles} |
'OsStatus' {returnGet-CimClassPropVal Win32_OperatingSystem Status} |
'OsSuites' {returnGet-OsSuites SuiteMask } |
'OsSystemDevice' {returnGet-CimClassPropVal Win32_OperatingSystem SystemDevice} |
'OsSystemDirectory' {returnGet-CimClassPropVal Win32_OperatingSystem SystemDirectory} |
'OsSystemDrive' {returnGet-CimClassPropVal Win32_OperatingSystem SystemDrive} |
'OsTotalSwapSpaceSize' {returnGet-CimClassPropVal Win32_OperatingSystem TotalSwapSpaceSize} |
'OsTotalVirtualMemorySize' {returnGet-CimClassPropVal Win32_OperatingSystem TotalVirtualMemorySize} |
'OsTotalVisibleMemorySize' {returnGet-CimClassPropVal Win32_OperatingSystem TotalVisibleMemorySize} |
'OsType' {returnGet-CimClassPropVal Win32_OperatingSystem OSType } |
# OsUptime => fragile test: fluid/dynamic |
#'OsUptime' {return Get-CimClassPropVal Win32_OperatingSystem Uptime} |
'OsVersion' {returnGet-CimClassPropVal Win32_OperatingSystem Version} |
'OsWindowsDirectory' {return [System.Environment]::GetEnvironmentVariable('windir')} |
'PowerPlatformRole' { returnGet-PowerPlatformRole } |
'TimeZone' {return ([System.TimeZoneInfo]::Local).DisplayName} |
'WindowsBuildLabEx' { returnGet-WinNtCurrentVersion BuildLabEx } |
'WindowsCurrentVersion' { returnGet-WinNtCurrentVersion CurrentVersion} |
'WindowsEditionId' { returnGet-WinNtCurrentVersion EditionID} |
'WindowsInstallationType' { returnGet-WinNtCurrentVersion InstallationType} |
'WindowsInstallDateFromRegistry' { returnGet-WinNtCurrentVersion InstallDate} |
'WindowsProductId' { returnGet-WinNtCurrentVersion ProductId} |
'WindowsProductName' { returnGet-WinNtCurrentVersion ProductName} |
'WindowsRegisteredOrganization' {returnGet-WinNtCurrentVersion RegisteredOrganization} |
'WindowsRegisteredOwner' {returnGet-WinNtCurrentVersion RegisteredOwner} |
'WindowsVersion' {returnGet-WinNtCurrentVersion ReleaseId} |
'WindowsUBR' {returnGet-WinNtCurrentVersion UBR} |
'WindowsSystemRoot' {return [System.Environment]::GetEnvironmentVariable('SystemRoot')} |
default {return'Unknown/unsupported propertyName = $propertyName'} |
} |
} |
$expected=New-Object-TypeName PSObject |
foreach ($propertyNamein [string[]]$propertyNames) |
{ |
$expected|Add-Member-MemberType NoteProperty -Name $propertyName-Value (Get-ExpectedComputerInfoValue$propertyName) |
} |
return$expected |
} |
try { |
#skip all tests on non-windows platform |
$originalDefaultParameterValues=$PSDefaultParameterValues.Clone() |
$PSDefaultParameterValues['it:skip'] =!$IsWindows |
Describe 'Tests for Get-ComputerInfo: Ensure Type returned'-tags 'CI','RequireAdminOnWindows' { |
It 'Verify type returned by Get-ComputerInfo' { |
$computerInfo=Get-ComputerInfo |
$computerInfo| Should -BeOfType 'Microsoft.PowerShell.Commands.ComputerInfo' |
} |
It 'Verify progress records in Get-ComputerInfo' { |
try { |
$j=Start-Job { Get-ComputerInfo } |
$j|Wait-Job |
$j.ChildJobs[0].Progress | Should -HaveCount 9 |
$j.ChildJobs[0].Progress[-1].RecordType | Should -Be ([System.Management.Automation.ProgressRecordType]::Completed) |
} |
finally { |
$j|Remove-Job |
} |
} |
} |
Describe 'Tests for Get-ComputerInfo'-tags 'Feature','RequireAdminOnWindows' { |
Context 'Validate All Properties' { |
BeforeAll { |
# do this once here rather than multiple times in Test 01 |
$computerInformation=Get-ComputerInfoForTest |
$propertyNames=Get-PropertyNamesForComputerInfoTest |
$Expected=New-ExpectedComputerInfo$propertyNames |
$testCases=$propertyNames|ForEach-Object { @{ 'Property'=$_ } } |
} |
# |
# Test 01. Standard Property test - No property filter applied |
# This is done with a set of test cases to improve failure investigation |
# since the data we get back comes from a number of sources, it will be |
# easier to debug the problem if we know *all* the failures |
# issue: https://github.com/PowerShell/PowerShell/issues/4762 |
# CsPhysicallyInstalledMemory not available when run in nightly builds |
It 'Test 01. Standard Property test - all properties (<property>)'-testcase $testCases-Pending { |
param ( $property ) |
$specialProperties='CsNetworkAdapters','CsProcessors','OsHotFixes' |
if ( $specialProperties-contains$property ) |
{ |
$ObservedList=$ComputerInformation.$property |
$ExpectedList=$Expected.$property |
$SpecialPropertyList= ($ObservedList)[0].psobject.properties.name |
Compare-Object$ObservedList$ExpectedList-property $SpecialPropertyList| Should -BeNullOrEmpty |
} |
else |
{ |
$left=$computerInformation.$property |
$right=$Expected.$Property |
# if we have a list, we need to compare it appropriately |
if ( $left-is [Collections.IList] ) |
{ |
$left=$left-join':' |
$right=$right-join':' |
} |
$left| Should -Be $right |
} |
} |
} |
Context 'Filter Variations' { |
# |
# Test 02.001 Filter Property - Property filter with one valid item |
# |
It 'Test 02.001 Filter Property - Property filter with one valid item' { |
$propertyNames=@('BiosBIOSVersion') |
$expectedProperties=@('BiosBIOSVersion') |
$propertyFilter='BiosBIOSVersion' |
$computerInfoWithProp=Get-ComputerInfoForTest-properties $propertyFilter |
$computerInfoWithProp| Should -BeOfType [pscustomobject] |
@($computerInfoWithProp.psobject.properties).count | Should -Be 1 |
$computerInfoWithProp.$propertyFilter| Should -Be $expected.$propertyFilter |
} |
# |
# Test 02.002 Filter Property - Property filter with three valid items |
# |
It 'Test 02.002 Filter Property - Property filter with three valid items' { |
$propertyNames=@('BiosBIOSVersion','BiosBuildNumber','BiosCaption') |
$expectedProperties=@('BiosBIOSVersion','BiosBuildNumber','BiosCaption') |
$propertyFilter=@('BiosBIOSVersion','BiosBuildNumber','BiosCaption') |
$computerInfoWithProp=Get-ComputerInfoForTest-properties $propertyFilter |
$computerInfoWithProp| Should -BeOfType [pscustomobject] |
@($computerInfoWithProp.psobject.properties).count | Should -Be 3 |
foreach($propertyin$propertyFilter) { |
$ComputerInfoWithProp.$property| Should -Be $Expected.$property |
} |
} |
# |
# Test 02.003 Filter Property - Property filter with one invalid item |
# |
It 'Test 02.003 Filter Property - Property filter with one invalid item' { |
$propertyNames=$null |
$expectedProperties=$null |
$propertyFilter=@('BiosBIOSVersionXXX') |
$computerInfoWithProp=Get-ComputerInfoForTest-properties $propertyFilter |
$computerInfoWithProp| Should -BeOfType [pscustomobject] |
@($computerInfoWithProp.psobject.properties).count | Should -Be 0 |
} |
# |
# Test 02.004 Filter Property - Property filter with four invalid items |
# |
It 'Test 02.004 Filter Property - Property filter with four invalid items' { |
$propertyNames=$null |
$expectedProperties=$null |
$propertyFilter=@('BiosBIOSVersionXXX','InvalidProperty1','InvalidProperty2','InvalidProperty3') |
$computerInfoWithProp=Get-ComputerInfoForTest-properties $propertyFilter |
$computerInfoWithProp| Should -BeOfType [pscustomobject] |
@($computerInfoWithProp.psobject.properties).count | Should -Be 0 |
} |
# |
# Test 02.005 Filter Property - Property filter with valid and invalid items: ver #1 |
# |
It 'Test 02.005 Filter Property - Property filter with valid and invalid items: ver #1' { |
$propertyNames=@('BiosCodeSet','BiosCurrentLanguage','BiosDescription') |
$expectedProperties=@('BiosCodeSet','BiosCurrentLanguage','BiosDescription') |
$propertyFilter=@('InvalidProperty1','BiosCodeSet','BiosCurrentLanguage','BiosDescription') |
$computerInfoWithProp=Get-ComputerInfoForTest-properties $propertyFilter |
$computerInfoWithProp| Should -BeOfType [pscustomobject] |
$realProperties=$propertyFilter|Where-Object { $_-notmatch'^InvalidProperty[0-9]+' } |
@($computerInfoWithProp.psobject.properties).count | Should -Be $realProperties.Count |
foreach ( $propertyin$realProperties ) |
{ |
$computerInfoWithProp.$property| Should -Be $expected.$property |
} |
} |
# |
# Test 02.006 Filter Property - Property filter with valid and invalid items: ver #2 |
# |
It 'Test 02.006 Filter Property - Property filter with valid and invalid items: ver #2' { |
$propertyNames=@('BiosCodeSet','BiosCurrentLanguage','BiosDescription') |
$expectedProperties=@('BiosCodeSet','BiosCurrentLanguage','BiosDescription') |
$propertyFilter=@('BiosCodeSet','InvalidProperty1','BiosCurrentLanguage','BiosDescription','InvalidProperty2') |
$computerInfoWithProp=Get-ComputerInfoForTest-properties $propertyFilter |
$computerInfoWithProp| Should -BeOfType [pscustomobject] |
$realProperties=$propertyFilter|Where-Object { $_-notmatch'^InvalidProperty[0-9]+' } |
@($computerInfoWithProp.psobject.properties).count | Should -Be $realProperties.Count |
foreach ( $propertyin$realProperties ) |
{ |
$computerInfoWithProp.$property| Should -Be $expected.$property |
} |
} |
# |
# Test 02.007 Filter Property - Property filter with wild card: ver #1 |
# |
It 'Test 02.007 Filter Property - Property filter with wild card: ver #1' { |
$propertyNames=@('BiosCaption','BiosCharacteristics','BiosCodeSet','BiosCurrentLanguage') |
$expectedProperties=@('BiosCaption','BiosCharacteristics','BiosCodeSet','BiosCurrentLanguage') |
$propertyFilter=@('BiosC*') |
$computerInfoWithProp=Get-ComputerInfoForTest-properties $propertyFilter |
$computerInfoWithProp| Should -BeOfType [pscustomobject] |
@($computerInfoWithProp.psobject.properties).count | Should -Be $expectedProperties.Count |
foreach ( $propertyin$expectedProperties ) |
{ |
$computerInfoWithProp.$property| Should -Be $expected.$property |
} |
} |
# |
# Test 02.008 Filter Property - Property filter with wild card and fixed |
# |
It 'Test 02.008 Filter Property - Property filter with wild card and fixed' { |
$propertyNames=@('BiosCaption','BiosCharacteristics','BiosCodeSet','BiosCurrentLanguage','CsCaption') |
$expectedProperties=@('BiosCaption','BiosCharacteristics','BiosCodeSet','BiosCurrentLanguage','CsCaption') |
$propertyFilter=@('BiosC*','CsCaption') |
$computerInfoWithProp=Get-ComputerInfoForTest-properties $propertyFilter |
$computerInfoWithProp| Should -BeOfType [pscustomobject] |
@($computerInfoWithProp.psobject.properties).count | Should -Be $expectedProperties.Count |
foreach ( $propertyin$expectedProperties ) |
{ |
$computerInfoWithProp.$property| Should -Be $expected.$property |
} |
} |
# |
# Test 02.009 Filter Property - Property filter with wild card, fixed and invalid |
# |
It 'Test 02.009 Filter Property - Property filter with wild card, fixed and invalid' { |
$propertyNames=@('BiosCaption','BiosCharacteristics','BiosCodeSet','BiosCurrentLanguage','CsCaption') |
$expectedProperties=@('BiosCaption','BiosCharacteristics','BiosCodeSet','BiosCurrentLanguage','CsCaption') |
$propertyFilter=@('CsCaption','InvalidProperty1','BiosC*') |
$computerInfoWithProp=Get-ComputerInfoForTest-properties $propertyFilter |
$computerInfoWithProp| Should -BeOfType [pscustomobject] |
@($computerInfoWithProp.psobject.properties).count | Should -Be $expectedProperties.Count |
foreach ( $propertyin$expectedProperties ) |
{ |
$computerInfoWithProp.$property| Should -Be $expected.$property |
} |
} |
# |
# Test 02.010 Filter Property - Property filter with wild card invalid |
# |
It 'Test 02.010 Filter Property - Property filter with wild card invalid' { |
$propertyNames=$null |
$expectedProperties=$null |
$propertyFilter=@('BiosBIOSVersionX*') |
$computerInfoWithProp=Get-ComputerInfoForTest-properties $propertyFilter |
$computerInfoWithProp| Should -BeOfType [pscustomobject] |
@($computerInfoWithProp.psobject.properties).count | Should -Be 0 |
} |
} |
} |
Describe 'Special Case Tests for Get-ComputerInfo'-tags 'Feature','RequireAdminOnWindows' { |
BeforeAll { |
if ($IsWindows) |
{ |
Add-Type-Name 'slc'-Namespace Win32Functions -MemberDefinition @' |
[DllImport('slc.dll', CharSet = CharSet.Unicode)] |
public static extern int SLGetWindowsInformationDWORD(string licenseProperty, out int propertyValue); |
'@ |
# Determine if the Software Licensing for CodeIntegrity is enabled |
functionHasDeviceGuardLicense |
{ |
try |
{ |
$policy=$null |
if ([Win32Functions.slc]::SLGetWindowsInformationDWORD('CodeIntegrity-AllowConfigurablePolicy', [Ref]$policy) -eq0-and$policy-eq1) |
{ |
return$true |
} |
} |
catch |
{ |
# fall through |
} |
return$false |
} |
functionGet-DeviceGuard |
{ |
$returnValue=@{ |
SmartStatus=0# Off |
AvailableSecurityProperties=$null |
CodeIntegrityPolicyEnforcementStatus=$null |
RequiredSecurityProperties=$null |
SecurityServicesConfigured=$null |
SecurityServicesRunning=$null |
UserModeCodeIntegrityPolicyEnforcementStatus=$null |
} |
try |
{ |
$instance=Get-CimInstance Win32_DeviceGuard -Namespace 'rootMicrosoftWindowsDeviceGuard'-ErrorAction Stop |
$ss=$instance.VirtualizationBasedSecurityStatus; |
if ($null-ne$ss) |
{ |
$returnValue.SmartStatus=$ss; |
} |
$returnValue.AvailableSecurityProperties=$instance.AvailableSecurityProperties |
$returnValue.CodeIntegrityPolicyEnforcementStatus=$instance.CodeIntegrityPolicyEnforcementStatus |
$returnValue.RequiredSecurityProperties=$instance.RequiredSecurityProperties |
$returnValue.SecurityServicesConfigured=$instance.SecurityServicesConfigured |
$returnValue.SecurityServicesRunning=$instance.SecurityServicesRunning |
$returnValue.UserModeCodeIntegrityPolicyEnforcementStatus=$instance.UserModeCodeIntegrityPolicyEnforcementStatus |
} |
catch |
{ |
# Swallow any errors and keep the deviceGuardInfo properties empty |
# This is what the cmdlet is expected to do |
} |
return$returnValue |
} |
$observed=Get-ComputerInfoForTest |
} |
} |
It 'Test for DeviceGuard properties'-Pending { |
if (-not (HasDeviceGuardLicense)) |
{ |
$observed.DeviceGuardSmartStatus| Should -Be 0 |
$observed.DeviceGuardRequiredSecurityProperties| Should -BeNullOrEmpty |
$observed.DeviceGuardAvailableSecurityProperties| Should -BeNullOrEmpty |
$observed.DeviceGuardSecurityServicesConfigured| Should -BeNullOrEmpty |
$observed.DeviceGuardSecurityServicesRunning| Should -BeNullOrEmpty |
$observed.DeviceGuardCodeIntegrityPolicyEnforcementStatus| Should -BeNullOrEmpty |
$observed.DeviceGuardUserModeCodeIntegrityPolicyEnforcementStatus| Should -BeNullOrEmpty |
} |
else |
{ |
$deviceGuard=Get-DeviceGuard |
# can't get amended qualifiers using cim cmdlets so we define them here |
$requiredSecurityPropertiesValues=@{ |
'1'='BaseVirtualizationSupport' |
'2'='SecureBoot' |
'3'='DMAProtection' |
'4'='SecureMemoryOverwrite' |
'5'='UEFICodeReadonly' |
'6'='SMMSecurityMitigations1.0' |
} |
$smartStatusValues=@{ |
'0'='Off' |
'1'='Enabled' |
'2'='Running' |
} |
$securityServicesRunningValues=@{ |
'0'='0' |
'1'='CredentialGuard' |
'2'='HypervisorEnforcedCodeIntegrity' |
} |
$observed.DeviceGuardSmartStatus| Should -Be (Get-StringValuesFromValueMap-valuemap $smartStatusValues-values $deviceGuard.SmartStatus) |
if ($deviceGuard.RequiredSecurityProperties-eq$null) |
{ |
$observed.DeviceGuardRequiredSecurityProperties| Should -BeNullOrEmpty |
} |
else |
{ |
$observed.DeviceGuardRequiredSecurityProperties| Should -Not-BeNullOrEmpty |
[string]::Join(',',$observed.DeviceGuardRequiredSecurityProperties) | Should -Be (Get-StringValuesFromValueMap-valuemap $requiredSecurityPropertiesValues-values $deviceGuard.RequiredSecurityProperties) |
} |
$observed.DeviceGuardAvailableSecurityProperties| Should -Be $deviceGuard.AvailableSecurityProperties |
$observed.DeviceGuardSecurityServicesConfigured| Should -Be $deviceGuard.SecurityServicesConfigured |
if ($deviceGuard.SecurityServicesRunning-eq$null) |
{ |
$observed.DeviceGuardSecurityServicesRunning| Should -BeNullOrEmpty |
} |
else |
{ |
$observed.DeviceGuardSecurityServicesRunning| Should -Not-BeNullOrEmpty |
[string]::Join(',',$observed.DeviceGuardSecurityServicesRunning) | Should -Be (Get-StringValuesFromValueMap-valuemap $securityServicesRunningValues-values $deviceGuard.SecurityServicesRunning) |
} |
$observed.DeviceGuardCodeIntegrityPolicyEnforcementStatus| Should -Be $deviceGuard.CodeIntegrityPolicyEnforcementStatus |
$observed.DeviceGuardUserModeCodeIntegrityPolicyEnforcementStatus| Should -Be $deviceGuard.UserModeCodeIntegrityPolicyEnforcementStatus |
} |
} |
# |
# TESTS FOR SPECIAL CASE PROPERTIES (i.e. those that are fluid/changing |
# |
It '(special case) Test for property = OsFreePhysicalMemory' { |
($observed.OsFreePhysicalMemory-gt0) | Should -BeTrue |
} |
It '(special case) Test for property = OsFreeSpaceInPagingFiles'-Skip:([System.Management.Automation.Platform]::IsIoT -or!$IsWindows) { |
($observed.OsFreeSpaceInPagingFiles-gt0) | Should -BeTrue |
} |
It '(special case) Test for property = OsFreeVirtualMemory' { |
($observed.OsFreeVirtualMemory-gt0) | Should -BeTrue |
} |
It '(special case) Test for property = OsLocalDateTime' { |
$computerInfo=Get-ComputerInfoForTest |
$testEndTime=Get-Date |
$computerInfo.OsLocalDateTime| Should -BeGreaterThan $testStartTime |
$computerInfo.OsLocalDateTime| Should -BeLessThan $testEndTime |
} |
It '(special case) Test for property = OsMaxNumberOfProcesses' { |
($observed.OsMaxNumberOfProcesses-gt0) | Should -BeTrue |
} |
It '(special case) Test for property = OsNumberOfProcesses' { |
($observed.OsNumberOfProcesses-gt0) | Should -BeTrue |
} |
It '(special case) Test for property = OsUptime' { |
($observed.OsUptime.Ticks-gt0) | Should -BeTrue |
} |
It '(special case) Test for property = OsInUseVirtualMemory' { |
($observed.OsInUseVirtualMemory-gt0) | Should -BeTrue |
} |
It '(special case) Test for Filter Property - Property filter with special wild card * and fixed' { |
$propertyFilter=@('BiosC*','*') |
$computerInfo=Get-ComputerInfo-Property $propertyFilter |
$computerInfo| Should -BeOfType Microsoft.PowerShell.Commands.ComputerInfo |
} |
} |
} |
finally |
{ |
$global:PSDefaultParameterValues=$originalDefaultParameterValues |
} |
Copy lines Copy permalink
Active5 years, 1 month ago
![Suite Suite](/uploads/1/2/5/8/125845691/431588664.jpg)
System.Environment.OSVersion does not appear to indicate which Edition of Windows 2003 is installed (Standard, Enterprise, DataCenter).
Is there any way to access this information using managed code only?
I know I can use P/Invoke to call GetVersionEx and examine OSVERSIONINFOEX.wSuiteMask to get this info, but I'm looking for a simpler solution.
Update
Using WMI looks like the way to go, though the OSProductSuite property of Win32_OperatingSystem looks more reliable than the Name property. Here's sample code:
Joe
JoeJoe104k2424 gold badges158158 silver badges290290 bronze badges
3 Answers
You could execute the following WMI query:
SELECT name FROM Win32_OperatingSystem
It returns something like this:
Microsoft Windows Server 2003 Standard Edition|C:WINDOWS|DeviceHarddisk0Partition1
This article explains how to perform WMI queries using .NET.
user128300
I'm not aware of any way to do this using only managed code.
There is some code here using GetVersionEx that should encapsulate things for you nicely though.
CocowallaCocowalla8,74555 gold badges4848 silver badges8282 bronze badges
![Osproductsuite Osproductsuite](/uploads/1/2/5/8/125845691/115407979.png)
I just wanted to add a smaller snippet of code for anyone who needs it.
GarrettGarrett35911 gold badge66 silver badges2020 bronze badges