Functions/Report/Get-SOCatClients.psm1

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#region: Get-SOCatClients
<#
 .Synopsis
 Lists all Catalyst Clients from your StoreOnce system(s).
 
 .Description
 Lists all Catalyst Clients from your StoreOnce system(s).
 
 .Example
 Get-SOCatClients
 
#Requires PS -Version 4.0
#>

function Get-SOCatClients {
    [CmdletBinding()]
    param (

    )
    Process {
        if (!$Global:SOConnections) {throw "No StoreOnce Appliance(s) connected! Use 'Connect-SOAppliance'"}
        $SOCatClients =  @()
        
        ForEach ($SOConnection in $($Global:SOConnections)) {
            if (Test-IP -IP $($SOConnection.Server)) {
                $SIDCall = @{uri = "https://$($SOConnection.Server)/storeonceservices/cluster/servicesets/";
                            Method = 'GET';
                            Headers = @{Authorization = 'Basic ' + $($SOConnection.EncodedPassword);
                                        Accept = 'text/xml'
                            } 
                        } 
                
                $SIDsResponse = Invoke-RestMethod @SIDCall
                $SIDCount = ($SIDsResponse.document.servicesets.serviceset).count
                if ($SIDCount -eq $null) {$SIDCount = 1}
                
                for ($x = 1; $x -le $SIDCount; $x++ ){
                    $ClientReq = @{uri = "https://$($SOConnection.Server)/storeonceservices/cluster/servicesets/$x/services/cat/configs/clients/";
                                Method = 'GET';
                                Headers = @{Authorization = 'Basic ' + $($SOConnection.EncodedPassword);
                                            Accept = 'text/xml'
                                } 
                            } 
                    $ClientResponse = Invoke-RestMethod @ClientReq
                
                    [Array] $Name = $ClientResponse.document.clients.client.properties.name
                    [Array] $ID = $ClientResponse.document.clients.client.properties.id
                    [Array] $Description = $ClientResponse.document.clients.client.properties.description
                    [Array] $canCreateStores = $ClientResponse.document.clients.client.properties.canCreateStores
                    [Array] $canSetServerProperties = $ClientResponse.document.clients.client.properties.canSetServerProperties
                    [Array] $canManageClientPermissions = $ClientResponse.document.clients.client.properties.canManageClientPermissions
                    $ClientCount = ($Name).count
                            
                    for ($i = 0; $i -lt $ClientCount; $i++ ){
                                
                        $row = [PSCustomObject] @{
                            System = $($SOConnection.Server)
                            SIDCount = [String] $SIDCount
                            SSID = $x
                            Name = $Name[$i]
                            ID = $ID[$i]
                            Description = $Description[$i]
                            canCreateStores = $canCreateStores[$i]
                            canSetServerProperties = $canSetServerProperties[$i]
                            canManageClientPermissions = $canManageClientPermissions[$i]
                        }
                        $SOCatClients += $row
                
                    }
                }
            
            }
        } 
            
    Return $SOCatClients
    }
}
#endregion