6

Running PowerShell version 5.0 on Windows 10 Build 10240. I need to obtain a PSCredential instance that contains the LocalSystem context. How can I achieve this?

https://msdn.microsoft.com/en-us/library/windows/desktop/ms684190(v=vs.85).aspx

  • Possible duplicate of [Create PSCredential without a password](https://stackoverflow.com/questions/6839102/create-pscredential-without-a-password) – jpmc26 Jul 10 '18 at 07:28

1 Answers1

6

From the documentation you linked to:

This account does not have a password. If you specify the LocalSystem account in a call to the CreateService or ChangeServiceConfig function, any password information you provide is ignored.

So, just supply "any password information" in the pscredential constructor:

$Username = "NT AUTHORITY\SYSTEM"
$Password = "whatever you feel like" | ConvertTo-SecureString -AsPlainText -Force
$LocalSystemCreds = New-Object -TypeName pscredential -ArgumentList $Username,$Password
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
  • If I try to start a process using that credential, it fails saying "This command cannot be run due to the error: The user name or password is incorrect." `Start-Process -FilePath notepad -Credential $LocalSystemCreds -Wait;` –  Jul 22 '15 at 22:17
  • You won't be able to do so, no. The only way to do so, AFAIK, is using [psexec](https://technet.microsoft.com/en-us/sysinternals/bb897553.aspx): `psexec -i -s notepad` – Mathias R. Jessen Jul 22 '15 at 22:22
  • 1
    Specifying a dummy password worked for me in Windows Server 2016 Datacenter in an Azure VM using PS 5.1.14393.3053. I just used `$Username = ".\LocalSystem"` as I understand [LocalSystem's authorization includes `NT AUTHORITY\SYSTEM` and more](https://learn.microsoft.com/en-us/windows/win32/services/localsystem-account). – Palec Jul 15 '19 at 18:07