在本地计算机上使用powershell启动-进程时的奇怪行为。

问题描述 投票:0回答:1

我在windows调度器中有一个任务,它在域/用户1下运行powerhell脚本ScriptScheduler.ps1。它在域/用户1下运行powerhell脚本ScriptScheduler.ps1.这个脚本在域/用户2下运行另一个GenerateAndApplyACLforMultipleProjects.ps1.当我在域/用户1下交互运行时,一切正常。但是,当我使用schedule时,我看到进程开始了,但什么也没发生。第二个脚本的抄写文件没有创建。我唯一得到的是,应用程序日志中的事件26,关于powershell启动0xc0000142的错误。

GenerateAndApplyACLforMultipleProjects.ps1 start code:

Start-Process -FilePath C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ArgumentList -WindowStyle Hidden -NonInteractive  -ExecutionPolicy Bypass –Noprofile  -file "C:\DATA\ProjectServices\SetProjectPermissions\SCRIPTS\GenerateAndApplyACLforMultipleProjects.ps1" -Verb RunAs -Credential $Credentials -PassThru
Transcript ScriptScheduler.ps1

**********************
Windows PowerShell transcript start
Start time: 20200422212501
Username: Domain\User1
RunAs User: Domain\User1
Machine: TEST-PC (Microsoft Windows NT 6.1.7601 Service Pack 1)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Noninteractive -ExecutionPolicy Bypass –Noprofile -file C:\DATA\Projects\ScriptScheduer\SCRIPTS\ScriptScheduler.ps1
Process ID: 5980
PSVersion: 5.1.14409.1018
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.14409.1018
BuildVersion: 10.0.14409.1018
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is C:\DATA\Projects\ScriptScheduler\LOGS\Transcript.log
Logging initialized.
Script scheduler started.
Run script @{Name=GenerateAndApplyACLforMultipleProjects; Path=C:\DATA\ProjectServices\SetProjectPermissions\SCRIPTS\GenerateAndApplyACLforMultipleProjects.ps1; UserName=Domain\User2; Credentials=System.Management.Automation.PSCredential; LogFile=C:\DATA\Projects\ScriptScheduler\LOGS\Daily.log; Evaluate=True; WorkDir=C:\DATA\ProjectServices\SetProjectPermissions\SCRIPTS} with evaluate.

GenerateAndApplyACLforMultipleProjects

Handles NPM(K) PM(K) WS(K) CPU(s)   Id SI ProcessName
------- ------ ----- ----- ------   -- -- -----------
             0     0     0        5592


Processing results.
Seconds run: [2.446404], task count: [1], task name: [GenerateAndApplyACLforMultipleProjects] errors count: [0].
Script scheduler exited.
PS>$global:?
True
**********************
Windows PowerShell transcript end
End time: 20200422212503
**********************  
powershell credentials start-process
1个回答
0
投票

这是...

Start-Process -FilePath C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ArgumentList -WindowStyle Hidden -NonInteractive  -ExecutionPolicy Bypass –Noprofile  -file "C:\DATA\ProjectServices\SetProjectPermissions\SCRIPTS\GenerateAndApplyACLforMultipleProjects.ps1" -Verb RunAs -Credential $Credentials -PassThru

... 是运行计划任务的错误方式。除非当你运行这个任务时,$credentials已经在内存中,否则$credentials是空的。

通过ST运行PowerShell命令和脚本是一个有据可查且经常使用的用例。

您可以使用ST GUI来设置这一点,并确保您选择正确的身份来使用,或者使用PowerShell来创建ST。[视频]

文件----------。

新安排的任务 - docs.microsoft.com

设置-计划任务 - docs.microsoft.com

© www.soinside.com 2019 - 2024. All rights reserved.