|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + Test the value of a CimObject Property. |
| 4 | +.DESCRIPTION |
| 5 | + Test the value of a CimObject Property. The Class can be provided with the Namespace. See Example. |
| 6 | +.PARAMETER ClassName |
| 7 | + Specifies the name of the CIM class for which to retrieve the CIM instances. Can be just the ClassName |
| 8 | + in the default namespace or in the form of namespace/className to access other namespaces. |
| 9 | +.PARAMETER Property |
| 10 | + Specifies an instance property to retrieve. |
| 11 | +.PARAMETER Should |
| 12 | + A Script Block defining a Pester Assertion. |
| 13 | +.EXAMPLE |
| 14 | + CimObject Win32_OperatingSystem SystemDirectory { Should Be C:\WINDOWS\system32 } |
| 15 | +.EXAMPLE |
| 16 | + CimObject root/StandardCimv2/MSFT_NetOffloadGlobalSetting ReceiveSideScaling { Should Be Enabled } |
| 17 | +.NOTES |
| 18 | + Assertions: Be, BeExactly, Match, MatchExactly |
| 19 | +#> |
| 20 | +function CimObject { |
| 21 | + [CmdletBinding()] |
| 22 | + param( |
| 23 | + [Parameter(Mandatory, Position=1)] |
| 24 | + [Alias("ClassName")] |
| 25 | + [string]$Target, |
| 26 | + |
| 27 | + [Parameter(Mandatory, Position=2)] |
| 28 | + [string]$Property, |
| 29 | + |
| 30 | + [Parameter(Mandatory, Position=3)] |
| 31 | + [scriptblock]$Should |
| 32 | + ) |
| 33 | + |
| 34 | + |
| 35 | + $expression = "Get-CimInstance" |
| 36 | + |
| 37 | + if ($Target -match '/') |
| 38 | + { |
| 39 | + $lastIndexOfSlash = $Target.LastIndexOf('/') |
| 40 | + |
| 41 | + $class = $Target.Substring($lastIndexOfSlash + 1) |
| 42 | + $namespace = $Target.Substring(0,$lastIndexOfSlash) |
| 43 | + |
| 44 | + $PSBoundParameters["Target"] = $class |
| 45 | + $PSBoundParameters.Add("Qualifier", $namespace) |
| 46 | + |
| 47 | + $expression = {Get-CimInstance -ClassName $Target -Namespace $Qualifier} |
| 48 | + } |
| 49 | + else |
| 50 | + { |
| 51 | + $expression = {Get-CimInstance -ClassName $Target} |
| 52 | + } |
| 53 | + |
| 54 | + $params = Get-PoshspecParam -TestName CimObject -TestExpression $expression @PSBoundParameters |
| 55 | + |
| 56 | + Invoke-PoshspecExpression @params |
| 57 | +} |
0 commit comments