Product: PowerShell Universal
Version: 5.0.8
Hi,
I´m new to Powershell Universal and we are in a POC with version 5.0.8 on IIS at the moment.
Seems pretty good but we have a problem using PSCredentials.
I searched in the forum but haven’t found a solution jet. Maybe someone has a solution for my issue.
We can use PSCredentials defined within a script but this doesn’t help us very much because we want the password to be secret and not part of the script.
Also we can use PSCredentials for RunAs the whole script which is good.
But we can’t use the PSCredential in the param block of a script while using a stored user. It seems like there is no credential transfered to the script.
For test I created a non secret value an this is used perfect within the script.
Please see the example script I use for testing:
param (
$partest,
[PSCredential]$Cred
)
$wikiuser = "WikiUser"
$pw = "Password"
$secstr = New-Object -TypeName System.Security.SecureString
$pw.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}
$CredWiki = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $wikiuser, $secstr
$var = $Variable:test
$currUser = whoami
write-output "Result check"
write-output "===================================="
write-output "RunAs User stored in SecretVault:"
write-output $currUser
write-Output "------------------------------------"
Write-Output "Testparameter:"
write-Output $partest
write-Output "------------------------------------"
Write-Output "Wikiuser defined in script:"
write-output $CredWiki.UserName
write-Output "------------------------------------"
Write-Output "Any user stored in SecretVault via parameter:"
write-output $Cred.UserName
write-Output "------------------------------------"
Write-Output "Variable 'test' stored in variable:"
Write-Output $var
and here is the result:
Result check
====================================
RunAs User stored in SecretVault:
domain\sccm_operator
------------------------------------
Testparameter:
Testparameter
------------------------------------
Wikiuser defined in script:
WikiUser
------------------------------------
Any user stored in SecretVault via parameter:
------------------------------------
Variable 'test' stored in variable:
This is a test output
Thank you in advance and best regards
Steffen