1

I have a powershell script and from inside this, i want to run a batch script as differend user. That means i have a AD service user account and with this i must run the batch script. It must work like a scheduled task in windows, where you can run it as differend user without store the password.

Now the question is how i can run the batch script from inside a powershell script with the service user and don't need to store the password in the Powershell script?

i have tried this:

Start-Process -Credentil "Domain\Account" -FilePath "CMD.exe" -Argumentlist "/c C:\myScript.cmd"

The result is that a window pops up where i must typ in the password for the service user.

Can any one help me with this?

Thank you and best regards, Nico

1 Answer 1

1

You need to register system scheduler task with credentials or store password in the script:

$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))
Start-Process -Credential $credentials -FilePath "cmd.exe"
Sign up to request clarification or add additional context in comments.

2 Comments

First of all thank you for your fast answer. With "you need to register system scheduled task" you mean i must create a scheduled task via the GUI of windows for scheduled tasks? My problem is, that it is not allowed to store the password for the AD service account inside the script as plain text.
You can register task from UI or from PowerShell (there is a tutorial duffney.io/Create-ScheduledTasks-SecurePassword). But what is important you need register it for specified user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.