Hi all,
I'm just trying to get a script to auomatically launch a process as a different user. The credentials are temporarily stored in an XML (yes, I know it's not ideal but I'm okay with that as it's just a pointless system in my little sandbox play pit). The script
looks something like this...
$xml = [xml](get-content "C:\MyFolder\a.xml")
$Username = $xml.credentials.Username
$password = ConvertTo-SecureString ($xml.credentials.password) -AsPlainText -Force
$domain = $xml.credentials.Domain
$FQDNUsername = "$domain/$username"
$adminCreds = New-Object System.Management.Automation.PSCredential($FQDNusername,$password)
Start-Process -FilePath "C:\Windows\System32\Notepad.exe" -Credential $adminCreds
This results in "The username or password is incorrect". I know this is not the case as the XML details have been used earlier in the process (not for PowerShell though) and I have viewed the content using $adminCreds.GetNetworkCredential().username
and password and they are correct.
If I populate $adminCreds just using a standard $adminCreds = Get-Credential then everything works fine.
Anyone got any ideas on why it doesn't work when building the credential using New-Object?
TIA
Baz