Functions/Get-PARServer.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 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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
Function Get-PARServer { <# .SYNOPSIS Gets OS resource information from remote vault .DESCRIPTION Returns details of CPU, Memory & Free Disk space from remote vault, as well as details of installed components. .PARAMETER Server The name or address of the remote Vault server to target with PARClient .PARAMETER Password The password for remote operations via PARClient as a secure string .PARAMETER Credential The password for remote operations via PARClient held in a credential object .PARAMETER PassFile The path to a "password" file created by PARClient.exe, containing the encrypted password value used for remote operations via PARClient .EXAMPLE Get-PARServer -Server EPV1 Returns object containing current resource consumption & installed component names & versions. #> [CmdletBinding()] Param( [Parameter( Mandatory = $true, ValueFromPipelineByPropertyName = $true )] [string]$Server, [Parameter( Mandatory = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName = "Password" )] [securestring]$Password, [Parameter( Mandatory = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName = "Credential" )] [pscredential]$Credential, [Parameter( Mandatory = $True, ValueFromPipelineByPropertyName = $True, ParameterSetName = "PassFile" )] [string]$PassFile ) Process { Try { $ErrorActionPreference = "Stop" $PSBoundParameters["CommandParameters"] = "GetCPU" $CPU = Invoke-PARClient @PSBoundParameters $PSBoundParameters["CommandParameters"] = "GetDiskUsage" $Disk = Invoke-PARClient @PSBoundParameters $PSBoundParameters["CommandParameters"] = "GetMemoryUsage" $Memory = Invoke-PARClient @PSBoundParameters $PSBoundParameters["CommandParameters"] = "List" $Components = Invoke-PARClient @PSBoundParameters If($CPU.StdOut) { $CPU = ($CPU.StdOut | Select-String '(\d+\.\d+)' -AllMatches).Matches.Value } Else {$CPU = $null} If($Disk.StdOut) { $Disk = $Disk.StdOut | Select-String '(.+)' -AllMatches | ForEach-Object { $DiskInfo = $_.Line.Split(" ") For ($i = 0 ; $i -lt $DiskInfo.count ; $i += 3) { $Drive = $DiskInfo[$i..($i + 3)] [PSCustomObject]@{ "Drive" = $Drive[0] "FreeSpace(MB)" = ($Drive[1] | Select-String '(\d+)' -AllMatches).Matches.Value "FreeSpace(%)" = ($Drive[2] | Select-String '(\d+\.\d+)' -AllMatches).Matches.Value } } } } Else {$Disk = $null} If($Memory.StdOut) { $Memory = ($Memory.StdOut | Select-String '(.+)' -AllMatches).Matches.Value | ForEach-Object { $MemoryInfo = $_.Split(":") $MemoryData = ($MemoryInfo[1] | Select-String '(\S+)' -AllMatches).Matches.Value [PSCustomObject]@{ "MemoryType" = ($MemoryInfo[0].Split(" "))[0] "Total(K)" = (($MemoryData[0]).Split("=")[1] | Select-String '(\d+)' -AllMatches).Matches.Value "Free(K)" = (($MemoryData[1]).Split("=")[1] | Select-String '(\d+)' -AllMatches).Matches.Value "Used(%)" = (($MemoryData[2]).Split("=")[1] | Select-String '(\d+\.\d+)' -AllMatches).Matches.Value } } } Else {$Memory = $null} If($Components.StdOut) { $Components = ($Components.StdOut | Select-String '(.+)' -AllMatches).Matches.Value | ForEach-Object { $Component = $_.Split(" ") $Version = ($_ | Select-String "(\d+\D\d+\D\d+\D\d+)" -AllMatches).Matches.Value [PSCustomObject]@{ Component = $Component[0] Version = $Version } } } Else {$Components = $null} [PSCustomObject]@{ "Server" = $Server.ToUpper() "CPU(%)" = $CPU "Disk" = $Disk "Memory" = $Memory "Components" = $Components } } Catch {throw $_} } } |