Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- If (! $VCSA) {
- If (Test-Path $Credfile) {
- $LoadedCredentials = Import-Clixml $Credfile
- $creds = New-Object System.Management.Automation.PsCredential($LoadedCredentials.Username,($LoadedCredentials.Password | ConvertTo-SecureString))
- $Services = get-wmiobject -Credential $creds win32_service -ComputerName $VIServer -ErrorAction SilentlyContinue| Where {$_.DisplayName -like "VMware*" }
- } Else {
- $Services = get-wmiobject win32_service -ComputerName $VIServer -ErrorAction SilentlyContinue | Where {$_.DisplayName -like "VMware*" }
- if ($Error[0].Exception.Message -match "Access is denied.") {
- # Access Denied Error found so asking to store windows credentials in a file for future use
- Write-Host "Current windows credentials do not allow for access to WMI on the host $VIServer, please enter Administrator credentials for this check to work, these will be stored in an encrypted file: $credfile"
- $Credential = Get-Credential
- $Pass = $credential.Password | ConvertFrom-SecureString
- $Username = $Credential.UserName
- $Store = "" | Select Username, Password
- $Store.Username = $Username
- $Store.Password = $Pass
- $Store | Export-Clixml $credfile
- $Services = get-wmiobject win32_service -ComputerName $VIserver -ErrorAction SilentlyContinue | Where {$_.DisplayName -like "VMware*" }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement