PSCredential for Nt Authority accounts

This topic contains 3 replies, has 2 voices, and was last updated by  Brian 4 weeks, 1 day ago.

  • Author
    Posts
  • #84470

    Brian
    Participant

    I'm trying to capture NT Authority accounts in a variable for the purpose of creating services and scheduled tasks. It won't let me create the object with the password. However if I include a "dummy" password, utilizing it in New-Service or DSC states the password is wrong.

    $cred = new-object -typename System.Management.Automation.PSCredential("NT Authority\Network Service",$(ConvertTo-SecureString 'adsf' -AsPlainText -Force))

    or
    $cred = get-credential -username 'NT Authority\Network Service' -msg 'whats the password'

    So my question is, how can I capture the credentials in a Powershell Object so I can easily reuse it with other powershell commands.

  • #84473

    Jon
    Participant

    Network service doesn't have a password. You should just be able to store nt authority\network service in a standard variable and for say something like register-scheduledtask put the variable in the -user paramaters

    $user = "nt authority\network service"
    register-scheduledtask -name taskname -user $user
  • #84475

    Jon
    Participant

    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-service?view=powershell-5.1

    -Credential
    Specifies a user account that has permission to perform this action.
    Type a user name, such as User01 or Domain01\User01, or enter a PSCredential object,

  • #84502

    Brian
    Participant

    What about DSC properties that only accept PSCredential objects?

    xScheduledTask -module xComputerManagement

    https://github.com/PowerShell/xComputerManagement

You must be logged in to reply to this topic.