Public/LocalGroup.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
31
32
33
34
<#
.SYNOPSIS
    Test if a local group exists.
.DESCRIPTION
    Test if a local group exists.
.PARAMETER Target
    The local group name to test for. Eg 'Administrators'
.PARAMETER Should
    A Script Block defining a Pester Assertion.
.EXAMPLE
    LocalGroup 'Administrators' { should not BeNullOrEmpty }
.EXAMPLE
    LocalGroup 'BadGroup' { should BeNullOrEmpty }
.NOTES
    Assertions: BeNullOrEmpty
#>

    
function LocalGroup {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory, Position=1)]
        [Alias('Name')]
        [string]$Target,
        
        [Parameter(Mandatory, Position=2)]
        [scriptblock]$Should
    )

    $expression = {Get-CimInstance -ClassName Win32_Group -Filter "Name = '$Target'"}
    
    $params = Get-PoshspecParam -TestName LocalGroup -TestExpression $expression @PSBoundParameters
    
    Invoke-PoshspecExpression @params
}