Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Start-Process issue

$
0
0

Can someone please help me with the following question.

I have an odd problem with Start-Process cmdlet but only when running in with a script via unattended mode e.g. from the Windows Task Scheduler (or other scheduling software like Jenkins)

I have this scenario

Two users UserA and UserB (Active Directory Users)

UserA has basic privileges, UserB has high privileges

I have two scripts Script1.ps1  and Script2.ps1

Part way through script1 I need to invoke script2 (probably using start-process as I need to pass credentials and arguments and also wait for the process to finish before returning.

The weird this is all of this runs OK when run manually from the PowerShell prompt e.g.  ./Script1.ps1  (but not when run via a scheduler as mentioned above)

Contents of script1.ps1

***************************

<#

Do some stuff
Do some more stuff

#>

$cred_password = ConvertTo-SecureString "Password01" -AsPlainText -Force

$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist"Domain\UserB", $cred_password

 

Start-Process C:\windows\system32\windowspowershell\v1.0\PowerShell.exe  -credential $Cred  -Wait -Args "-file C:\Script2.ps1"

******************************

The contents of script2.ps1 are not important at this stage it just does some stuff that require the rights of UserB to work, hence starting the process as UserB via the $Cred object.

When running script1.ps1 manually all works fine, when running script1.ps1 via a scheduler script2.ps1 does not appear to run at all and there appears to be no errors.

I have tried various things like adding the  -noprofile and  -executionpolicy bypass when invoking Powershell.exe above 

 

This made no difference; this appears to happen on all versions on PowerShell. 

Thanks All

__AAnotherUser

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles