HP Matrix 7.2 KVM Private Cloud Backup and Restore

Table Of Contents
.INPUTS
None, this function does not take inputs.
.OUTPUTS
Returns an object that contains the login name, password, and host name to connect
to.
.EXAMPLE
$variable = queryfor-credentials #runs function, saves json object to variable.
#>
if ($args[0] -eq $null)
{
Write-Host "Enter Appliance name (https://ipaddress)"
$appliance = Read-Host
# Correct some common errors
$appliance = $appliance.Trim().ToLower()
if (!$appliance.StartsWith("https://"))
{
if ($appliance.StartsWith("http://"))
{
$appliance = $appliance.Replace("http","https")
} else {
$appliance = "https://" + $appliance
}
}
Write-Host "Enter Username"
$username = Read-Host -AsSecureString | ConvertFrom-SecureString
Write-Host "Enter password"
$SecurePassword = Read-Host -AsSecureString | ConvertFrom-SecureString
Write-Host "Would you like to save these credentials to a file? (username and password
encrypted)"
$saveQuery = Read-Host
$loginVals = [pscustomobject]@{ userName = $username; password = $SecurePassword; hostname
= $appliance }
$loginJson = $loginVals | convertTo-json
$global:interactiveMode = 1
if ($saveQuery[0] -eq "y") #enters into the mode to save the credentials
{
Write-Host "Enter file path and file name to save credentials (example:
C:\users\bob\machine1.txt)"
$storagepath = Read-Host
try
{
$loginJson | Out-File $storagepath -NoClobber -ErrorAction stop
}
catch [System.Exception]
{
Write-Host $_.Exception.message
if ($_.Exception.getType() -eq [System.IO.IOException]) # file already exists throws an
IO exception
{
do
{
Write-Host "Overwrite existing credentials for this machine?"
[string]$overwriteQuery = Read-Host
if ($overwriteQuery[0] -eq 'y')
{
$loginJson | Out-File $storagepath -ErrorAction stop
$exitquery = 1
}
elseif ($overwriteQuery[0] -eq 'n')
{
$exitquery = 1
}
else
{
Write-Host "please respond with a y or n"
38