locked
Get-Credential can Start-Process but a credential object cannot RRS feed

  • Question

  • 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

    Tuesday, May 14, 2019 10:24 AM

Answers

  • Try a backslash.

    $FQDNUsername = "$domain\$username"

    • Marked as answer by SurfKing Tuesday, May 14, 2019 1:10 PM
    Tuesday, May 14, 2019 12:44 PM

All replies

  • Try a backslash.

    $FQDNUsername = "$domain\$username"

    • Marked as answer by SurfKing Tuesday, May 14, 2019 1:10 PM
    Tuesday, May 14, 2019 12:44 PM
  • Oh random creative expletives!!!

    Thanks and sorry. It's been a long day :)
    Tuesday, May 14, 2019 1:10 PM