我正在尝试创build一个计划任务,将:
该脚本完全从控制台执行,但甚至不会开始执行任务。
#Stop an error from occurring when a transcript is already stopped $ErrorActionPreference="SilentlyContinue" Stop-Transcript | out-null #Reset the error level before starting the transcript $ErrorActionPreference="Continue" Start-Transcript -path C:\temp\Shutdown_NonProductionVMs.log -append #Add the VMWare Snap-in Add-PSSnapin -Name VMWare.VimAutomation.Core #Get the Credentials $creds = Get-VICredentialStoreItem -file C:\temp\pscreds.creds #Connect to the server using the credentials file Connect-VIServer -Server $creds.host -User $creds.User -Password $creds.Password #Get all VMs within the non-production VMs folder and then shut them down #NOTE the -WhatIf tag, which will stop it from shutting down the VMs until we're sure the script is good. Get-Folder -Name "03. Non-Production VMs" | Get-VM | Shutdown-VMGuest -WhatIf #Clean Up Disconnect-VIServer -Force -Confirm:$false Remove-PSSnapin -Name VMWare.VimAutomation.Core Stop-Transcript
有任何想法吗? 在此先感谢您的帮助!
如果您在交互式“控制台”会话中启动Powershell,则最有可能启动64位版本的Powershell。 (可执行文件将驻留在Windows \ System32中。)还可以通过执行驻留在Windows \ SysWOW64中的版本从64位Windows启动32位Powershell。 确保您知道哪个版本的Task Scheduler正在启动。
请记住,每个Powershell版本都有一个完全独立的执行策略。 所以你需要设置执行策略两次,以覆盖Powershell的32位和64位版本。
您尝试加载的pipe理单元也很重要。 某些pipe理单元和COM对象只能在32位或64位环境中加载。 但是,我刚刚在安装了PowerCLI的Server 2008 R2服务器上进行了testing,并且在加载在两种环境中引用的pipe理单元时都没有问题。 所以我不认为这是这个问题。 但是这仍然是需要考虑的事情。 这可能取决于您安装的PowerCLI版本。 确保从32位和64位PSshell加载pipe理单元。
最后,你能告诉我们你的计划任务中的操作屏幕是什么意思吗? 你正在运行什么确切的命令行(W /参数)? 如果运行诸如cmd /c powershell.exe c:\yourscript.ps1 2>&1> C:\debug.txt您可能会得到更多的debugging信息
它也可能有助于从32位和64位环境中为我们提供Get-ExecutionPolicy -List的输出。
另外在你的post中你提到:
任务只是继续运行。 我没有得到任何结果,并没有终止。
这通常表示它正在等待用户input。
编辑:错别字,错别字eveyrwhere