- This topic has 2 replies, 1 voice, and was last updated May 30, 2018 by John K.
API/Powershell ZVM authentication
You must be logged in to create new topics.
Click here to login
Powershell version: 5.1 / ZVR Version: 5.5 Update1
I’m trying to do some testing with PowerShell and rest API. When using an example script from the White Paper “Automating Zerto Virtual Replication with PowerShell and REST APIs” (page 9) I’m having some authentication issues. I receive the exception error below. The problem seems to be, at some point during the script it changes the user name by using two “\\”, even though I enter the user name as “blah\username”. I’ve tried various ways of inserting the user name, but the “\\” keeps appearing and this is what seems to be causing the auth failure.
Any suggestions on why the extra back slash is appearing?
Exception : System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
TargetObject : System.Net.HttpWebRequest
CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
ErrorDetails : {“Message”:”Failed logging in to blah-vcenter with username blah\\username. Error was ‘Cannot complete login due to an incorrect user name or
password.'”}
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, <No file>: line 59
PipelineIterationInfo : {}
PSMessageDetails :
You cannot call a method on a null-valued expression.
At line:67 char:1
+ $xZertoSession = $xZertoSessionResponse.headers.get_item(“x-zerto-ses …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Hard coding credentials seems to work, but using “read-host” to create the user name and password (asSecureString) seem to cause the issue.
Same with Get-credentials.
It maybe the secure string and the double \ in the error message is misleading?
Seems to work when using “Get-Credential” and amending the following line … “$AuthInfo = (“{0}:{1}” -f $credentials.UserName,$credentials.getnetworkcredential().Password)”