#Requires -Version 4.0 <# .SYNOPSIS Gets MSA 2060 disk health information .DESCRIPTION Gets MSA 2060 disk health information .PARAMETER MsaHostName Specifies the IP address, host name or fqdn of the MSA system .PARAMETER Credential Specifies a PSCredential object that contains credentials for authenticating with the server. .NOTES Author: kurator | lagerhaus128.ch Revision 0: Initial revision .EXAMPLE Import-Module E:\git\iteres-script-collection\powershell\MsaHealth.psm1 $Credential = New-Object System.Management.Automation.PSCredential -ArgumentList 'manage',('manage' | ConvertTo-SecureString -AsPlainText -Force) Get-MsaDiskHealthData -MsaHostName '172.29.105.25' -Credential $Credential .LINK https://www.lagerhaus128.ch/?p=1312 #> Function Get-MsaDiskHealthData { [CmdletBinding()] param( [Parameter(Mandatory="true")][String]$MsaHostName, [Parameter(Mandatory="true")][PSCredential]$Credential ) Try { $hasher = [System.Security.Cryptography.HashAlgorithm]::Create('sha256') $hash = $hasher.ComputeHash([System.Text.Encoding]::UTF8.GetBytes(('{0}_{1}' -f $credential.GetNetworkCredential().UserName,$credential.GetNetworkCredential().Password))) $MsaCredentialHash = (([System.BitConverter]::ToString($hash)).Replace('-', '')).ToLower() Add-Type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy $SessionKeyResponse = Invoke-WebRequest -Uri ('https://{0}/api/login/{1}' -f $MsaHostName,$MsaCredentialHash) if((([XML]$SessionKeyResponse.Content).RESPONSE.OBJECT.PROPERTY| Where-Object {$_.name -eq 'response-type'}).'#text' -eq 'Success') { $SessionKey = [String](([XML]$SessionKeyResponse.Content).RESPONSE.OBJECT.PROPERTY| Where-Object {$_.name -eq 'response'}).'#text' } Else { throw 'Unable to get session key' } $ShowDisks = Invoke-WebRequest -Uri ('https://{0}/api/show/disks' -f $MsaHostName) -Headers @{'sessionKey' = $SessionKey;'dataType' = 'ipa'} -Method Get $ReturnArray = New-Object System.Collections.ArrayList ([XML]($ShowDisks.Content)).RESPONSE.OBJECT | Where-Object {$_.name -eq 'drive'} | ForEach-Object { $ReturnArray.Add( [PSCustomObject]@{ 'enclosure-id' = ($_.PROPERTY | Where-Object {$_.name -eq 'enclosure-id'}).'#text' 'drawer-id' = ($_.PROPERTY | Where-Object {$_.name -eq 'drawer-id'}).'#text' 'slot' = ($_.PROPERTY | Where-Object {$_.name -eq 'slot'}).'#text' 'temperature-status' = ($_.PROPERTY | Where-Object {$_.name -eq 'temperature-status'}).'#text' 'health' = ($_.PROPERTY | Where-Object {$_.name -eq 'health'}).'#text' } ) | Out-Null } return $ReturnArray Remove-Variable ReturnArray Remove-Variable ShowDisks Remove-Variable SessionKey Remove-Variable SessionKeyResponse Remove-Variable mSACredentialHash Remove-Variable hash Remove-Variable hasher } Catch { Write-Error $_.Exception.Message } } Export-ModuleMember -Function Get-MsaDiskHealthData <# .SYNOPSIS Gets MSA 2060 system health information .DESCRIPTION Gets MSA 2060 system health information .PARAMETER MsaHostName Specifies the IP address, host name or fqdn of the MSA system .PARAMETER Credential Specifies a PSCredential object that contains credentials for authenticating with the server. .NOTES Author: kurator | lagerhaus128.ch Revision 0: Initial revision .EXAMPLE Import-Module E:\git\iteres-script-collection\powershell\MsaHealth.psm1 $Credential = New-Object System.Management.Automation.PSCredential -ArgumentList 'manage',('manage' | ConvertTo-SecureString -AsPlainText -Force) Get-MsaSystemHealth -MsaHostName '172.29.105.25' -Credential $Credential .LINK https://www.lagerhaus128.ch/?p=1312 #> Function Get-MsaSystemHealth { [CmdletBinding()] param( [Parameter(Mandatory="true")][String]$MsaHostName, [Parameter(Mandatory="true")][PSCredential]$Credential ) Try { $hasher = [System.Security.Cryptography.HashAlgorithm]::Create('sha256') $hash = $hasher.ComputeHash([System.Text.Encoding]::UTF8.GetBytes(('{0}_{1}' -f $credential.GetNetworkCredential().UserName,$credential.GetNetworkCredential().Password))) $MsaCredentialHash = (([System.BitConverter]::ToString($hash)).Replace('-', '')).ToLower() Add-Type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy $SessionKeyResponse = Invoke-WebRequest -Uri ('https://{0}/api/login/{1}' -f $MsaHostName,$MsaCredentialHash) if((([XML]$SessionKeyResponse.Content).RESPONSE.OBJECT.PROPERTY| Where-Object {$_.name -eq 'response-type'}).'#text' -eq 'Success') { $SessionKey = [String](([XML]$SessionKeyResponse.Content).RESPONSE.OBJECT.PROPERTY| Where-Object {$_.name -eq 'response'}).'#text' } Else { throw 'Unable to get session key' } $ShowSystem = Invoke-WebRequest -Uri 'https://172.29.105.25/api/show/system' -Headers @{'sessionKey' = $SessionKey;'dataType' = 'ipa'} -Method Get return ((([XML]($ShowSystem.Content)).RESPONSE.OBJECT | Where-Object {$_.name -eq 'system-information'}).PROPERTY | Where-Object {$_.name -eq 'health'}).'#text' Remove-Variable ReturnArray Remove-Variable ShowSystem Remove-Variable SessionKey Remove-Variable SessionKeyResponse Remove-Variable mSACredentialHash Remove-Variable hash Remove-Variable hasher } Catch { Write-Error $_.Exception.Message } } Export-ModuleMember -Function Get-MsaSystemHealth