Subscribe

Connect to WFA vi web services using machine domain account?

All, I am creating a script that will invoke a WF via web services (so it can be scheduled).  However, the user does not want to store the credentials within the script file. What are my options? Should I import the wfa module and get wfa credentials, or is there a better way?

Re: Connect to WFA vi web services using machine domain account?

Stephen2,

       You can't import the WFA module outside of WFA commands and call the Get-WfaCredentials to get credentials. This won't work.

I suggest you use the REST api ApiExecutionResource to get the credentials. The following code works fine ( crudely written, but commented every step )

=====

#wfa Credentials. Modify it as your settings. My WFA HTTP port is 90.

$user = "admin"

$pass = "admin"

#Create Credential object for WFA login

$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force

$cred = New-Object System.Management.Automation.PSCredential ($user, $secpasswd)

#API to get the genericSession element. This ONLY works with localhost

$add = "http://localhost:90/rest/execution/api/create"

#Invoke REST API

$wf=Invoke-RestMethod -Uri $add -Method Post -Credential $cred -ContentType "application/xml" -Headers @{"Authorization"="Basic YWRtaW46YWRtaW4="}

#Obtain the UUID from generi session element.

$uuid= $wf.genericSession.uuid

#The Cluster/Array or any host whose Credentials you require. You need to have the credentials already saved in WFA

$host_name = "1.2.3.4"

#API to get the Username/Password in plain text

$add2 = "http://localhost:90/rest/execution/api/$uuid/credentials?hostId=$host_name"

#Invoke REST API

$wf2=Invoke-RestMethod -Uri $add2 -Method Get -Credential $cred -ContentType "application/xml" -Headers @{"Authorization"="Basic YWRtaW46YWRtaW4="}

# Get Username/Password form the returned XML object

$userName = $wf2.userCredentials.userName

$PlainPassword = $wf2.userCredentials.password

#Create Secure String for the Password

$secPassword = ConvertTo-SecureString $PlainPassword -AsPlainText -Force

#Build credential object

$Creds = New-Object System.Management.Automation.PSCredential ($userName, $secPassword)

#This Credentail $Creds can be used in the remaining code.

=====

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.