Log $ScriptName $GLOBAL:INFO_LEVEL "Script is starting. Running, as ($whoami)."
LoadPowerShellSDK $ScriptName
Write-Host "Verifying endpoint: $Endpoint ..."
if ([string]::IsNullOrWhiteSpace($Username)) {
Write-Host "Invalid username: $Username"
Write-Host "Please make sure a RunAs account for $Endpoint is added to the 'FlashArray Admin Account' profile"
exit
}
if ([string]::IsNullOrEmpty($Password)) {
Write-Host "Invalid password. Please make sure a RunAs account for $Endpoint is added to the 'FlashArray Admin Account' profile."
exit
}
try {
$Password = $Password | ConvertTo-SecureString -AsPlainText -Force
$IgnoreCertErrors = GetIgnoreCertErrors $true
$FlashArray = New-PfaArray -EndPoint $Endpoint -UserName $Username -Password $Password -ClientName $GLOBAL:clientName -ClientVersion $GLOBAL:mpVersion -IgnoreCertificateError:$IgnoreCertErrors -HttpTimeOutInMilliSeconds 60000
Write-Host "Success. $Endpoint is accessible."
Disconnect-PfaArray -Array $FlashArray
} catch {
$msg = "Connection to array failed on these credentials. $Username. `nCheck that the PurePowershell cmdlet is installed, and your credentials are correct. `nError: $_"
Write-Host $msg
Log $ScriptName $GLOBAL:ERROR_LEVEL $msg
exit
}
}
function SetLogLevel ($LogLevel){
Write-Host "Setting LogLevel to $LogLevel"
if ($LogLevel -ge 1 -and $LogLevel -le 4){
New-Item -Path HKLM:\SOFTWARE\PureStorage\SCOM -Name LogLevel -Force
Set-Item -Path HKLM:\SOFTWARE\PureStorage\SCOM\LogLevel -Value $LogLevel
$GLOBAL:CURRENT_LOG_LEVEL = $LogLevel
}
}
function GetLogLevel ($default){
if (Test-Path HKLM:\SOFTWARE\PureStorage\SCOM\LogLevel){
$item = Get-ItemProperty "HKLM:\SOFTWARE\PureStorage\SCOM\LogLevel"
$log_level = $item.'(default)'
$log_level
}
else
{
$default
}
}
function SetIgnoreCertErrors ($value){
Write-Host "Setting IgnoreCertErros to $value"
New-Item -Path HKLM:\SOFTWARE\PureStorage\SCOM -Name IgnoreCertErrors -Force
Set-Item -Path HKLM:\SOFTWARE\PureStorage\SCOM\IgnoreCertErrors -Value $value
}
function GetIgnoreCertErrors ($default){
if (Test-Path HKLM:\SOFTWARE\PureStorage\SCOM\IgnoreCertErrors){
$item = Get-ItemProperty "HKLM:\SOFTWARE\PureStorage\SCOM\IgnoreCertErrors"
$log_level = [bool]($item.'(default)')
$log_level
}
else
{
$default
}
}