Public/Get-PrtgCredentialUsage.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
35
36
37
38
39
function Get-PrtgCredentialUsage {
    [CmdletBinding()]

    Param (
        [Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
        [int[]]$ObjectId
    )

    BEGIN {
        $VerbosePrefix = "Get-PrtgCredentialUsage:"
        if (!($global:PrtgServerObject.Connected)) {
            try {
                Throw
            } catch {
                $PSCmdlet.ThrowTerminatingError([HelperProcessError]::throwCustomError(1000, $global:PrtgServerObject.Hostname))
            }
        }

        $ReturnData = @()
    }

    PROCESS {
        Write-Verbose "$VerbosePrefix Checking Credential Usage for Object: $($ObjectId[0])"
        $New = "" | Select-Object -Property ObjectId, ObjectType, WindowsDomain, WindowsUsername, LinuxUsername, EsxUsername, SnmpV3User
        $New.ObjectId = $ObjectId[0]
        $New.ObjectType = $_.GetType().Name
        $New.WindowsDomain = Get-PrtgObjectProperty -Property windowslogindomain -ObjectId $ObjectId
        $New.WindowsUsername = Get-PrtgObjectProperty -Property windowsloginusername -ObjectId $ObjectId
        $New.LinuxUsername = Get-PrtgObjectProperty -Property linuxloginusername -ObjectId $ObjectId
        $New.EsxUsername = Get-PrtgObjectProperty -Property esxuser -ObjectId $ObjectId
        $New.SnmpV3User = Get-PrtgObjectProperty -Property snmpuser -ObjectId $ObjectId

        $ReturnData += $New
    }

    END {
        $ReturnData
    }
}