HP OneView Manual del usuario

Página 280

Advertising
background image

$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"
$exitquery = 0
}

} while ($exitquery -eq 0)
}
else
{
Write-Host "improper filepath or no permission to write to given directory"
Write-EventLog -EventId 100 -LogName Application -Source backup.ps1 -Message "Improper filepath,
$storagepath " $_.Exception.message
return
}
}

$savedLoginJson = Get-Content $storagepath

Write-Host "Run backup?"

$continue = 0
do
{
$earlyExit = Read-Host
if ($earlyExit[0] -eq 'n')
{
return
}
elseif ($earlyExit[0] -ne 'y')
{
Write-Host "please respond with a y or n"
}
else
{
$continue = 1
}

} while ($continue -eq 0)

}
else
{
return $loginJson
}
}
elseif ($args.count -ne 1)
{
Write-Host "Incorrect number of arguments, use either filepath parameter or no parameters."
return

}
else

280 Ejemplos de secuencias de comandos de copia de seguridad y restauración

Advertising