The Active Roles SDK provides the following sample script which demonstrates one method of how to handle the value passed by a SecureString parameter:
#The following script function is intended to be used by a Script activity included in an automation workflow. This #function starts Windows service "QSVC" on the remote computers specified by workflow parameter #"Computers". To perform this task, the function logs on to each remote computer with the user name and #password specified by the "LogonName" parameter and "Password" parameter, respectively.
#The workflow parameters used by this script must be configured as follows:
#Computers - Multi-valued, String parameter
#LogonName - Single-valued, String parameter
#Password - Single-valued, SecureString parameter
#For instructions on how to create a workflow parameter, see the Active Roles Administrator Guide.
Function StartService()
{
$computers = $workflow.ParameterEx("Computers")
$logonName = $workflow.Parameter("LogonName")
$password = $workflow.Parameter("Password")
$securePassword = ConvertTo-SecureString $Security.Cryptography.decryptfromstring($password) -asplaintext -force
$cred = New-Object System.Management.Automation.PSCredential ($logonName, $securePassword)
foreach ($computer in $computers)
{
trap {continue}
$ps = New-PSSession -computername $computer -Credential $cred
Invoke-Command -session $ps -scriptblock { Start-Service QCSVC }
Remove-PSSession $ps
}
}
© ALL RIGHTS RESERVED. Terms of Use Privacy Cookie Preference Center