Get a PSCredential instance representing the built-in Local System account

Running PowerShell 5.0 on Windows 10 Build 10240. I need to get an instance PSCredential

that contains the LocalSystem context. How can I achieve this?

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

+3


source to share


1 answer


From the documentation you linked to:

This account does not have a password . If you specify the LocalSystem account when calling the CreateService or ChangeServiceConfig function, any password information that you provide is ignored.



So, just put "any password information" in the constructor pscredential

:

$Username = "NT AUTHORITY\SYSTEM"
$Password = "whatever you feel like" | ConvertTo-SecureString -AsPlainText -Force
$LocalSystemCreds = New-Object -TypeName pscredential -ArgumentList $Username,$Password

      

+2


source







All Articles