Laczymy sie do VC / ESX/ESXi uzywajac credentials z pliku


Zamiast za kazdym razem utozsamiac sie podajac login/pass , mozemy wykorzystac mechanizm credentials ktore jest do naszej dyspozycji.
Connect-VIserver posiada przelacznik -credentials.
Zgodnie z opisem:
http://www.vmware.com/support/developer/windowstoolkit/wintk40u1/html/Connect-VIServer.html
“Specify a PSCredential object that contains credentials for authenticating with the server”
Zatem musimy najpierw stworzyc obiekt PSCredential:
$mycred=get-credential
write-host “Please type file location to store credential”
$file=read-host
$mycred.Password | ConvertFrom-SecureString | Set-content $file
write-host “Credential file was created”

-> Od teraz dysponujemy plikiem z haslem zapisanym w miejscu podanym w $file.

Mozemy zatem napisac funkcje ktora nas autoryzuje :
function authorize
{
if(test-path -PathType leaf $file)
{
write-host “Using authorization file “$file
$password = Get-Content $file | ConvertTo-SecureString
$cred = New-Object System.Management.Automation.PsCredential(“USER”,$password)
return $cred
}
else
{
write-host “No authorization file found”`n”Terminating.”
break
}
}

Potem mozemy w skryptach uzywac juz polaczenie wywolywanego:
$credential=authorize()
connect-viserver A.B.C.D -credential $credential

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s