Trying to use Microsoft.PowerShell.SecretStore to work with PWs

Hi Everyone,
I have been trying to use the modules:

I am trying to save my admin PW in the vault, then use that in a script so I do not have to type it.

I think I almost have it working, albeit in a very convoluted manner. I am hoping for some pointers on how to do this better? or even how to do it at all at this point :slight_smile:

What I think the problem is,the $UserPW variable is not just containing the PW, it looks like this when I output it to screen:


I was thinking If I can remove the 1st 2 lines from that variable, maybe it would work? idk

Here is my code:

$vaultpassword = (Import-CliXml C:\Temp\ITScript\vaultpassword.xml).Password
Unlock-SecretStore -Password $vaultpassword
$UserName = 'mk-1st\mk'
$UserPW = (Get-Secret -Name Secret1).GetNetworkCredential() | Select-Object Password
[securestring]$secStringPassword = ConvertTo-SecureString -String $UserPW -AsPlainText -Force
$userCredential = New-Object System.Management.Automation.PSCredential ($UserName,$secStringPassword)
Start-Process -Path "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe" -Credential ($userCredential)

I get the user name or password is incorrect, and my PS never loads.



I never used this module myself. But since we use objects and porperties in PowerShell it should be


instead of just


That worked, Thanks so much for taking a look!