How to Pass password to Run as a Network Account in powershell RRS feed

  • Question

  • Hello,

    I ve been asked to raise this as a new topic as given in the link. The response also says that it is not possible to pass the password of a network account in powershell. How else can I implement the requirement?

    My requirement is that, I am need to run the powershell script via a network account. The powershell is called via a script on an ETL tool. When I ask it to print the output of the below command, the output says " Enter the password of domain\username:". 

    PS > runas /user:{domain}\{username} powershell -file {nameOfPowershellScript.ps1}

    Hence I had to modify the code to pass the password also in the same command. I am new to powershell scripting and the below command doesn't work. Please suggest the appropriate way to pass the password of the network account.

     Referred to a link 

    $password = Get-Content c:\temp\password.txt | ConvertTo-SecureString 

    $credential = New-Object System.Management.Automation.PSCredential "CachedUser",$password 

    PS > runas /user:{domain}\{username} powershell -file {nameOfPowershellScript.ps1}

    PS >$credential.Password | ConvertFrom-SecureString | Set-Content c:\temp\password.txt 

    • Edited by Shweth Friday, March 14, 2014 3:00 PM Refered link provided
    Wednesday, March 12, 2014 9:56 AM