计划任务中的 Powershell 模块

标签 powershell scheduled-tasks powershell-module

关于模块,我不太明白......

如果我作为普通用户这样做

get-module -listavailable 

我得到这样的结果:

Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules

ModuleType Name                                ExportedCommands
---------- ----                                ----------------
Manifest   ADRMS                               {Update-ADRMS, Unins
Manifest   AppLocker                           {Set-AppLockerPolicy
Manifest   BestPractices                       {Get-BpaModel, Invok
Manifest   BitsTransfer                        {Add-BitsFile, Remov
Manifest   CimCmdlets                          {Get-CimAssociatedIn
Script     DSV
Script     DSVAsset                            {Get-HTMLPage, Get-H
Script     DSVDB                               {Execute-UpdateULLoC
Script     DSVHnas                             {Get-HNASFileScan, B
Script     DSVLog                              {Start-DSVTranscript
Script     Experimental.IO                     {Where-Wildcard, Get
Manifest   FailoverClusters                    {Add-ClusterDisk, Ad
Script     ISE                                 {New-IseSnippet, Imp
Manifest   Microsoft.PowerShell.Diagnostics    {Get-WinEvent, Get-C
Manifest   Microsoft.PowerShell.Host           {Start-Transcript, S
Manifest   Microsoft.PowerShell.Management     {Add-Content, Clear-
Manifest   Microsoft.PowerShell.Security       {Get-Acl, Set-Acl, G
Manifest   Microsoft.PowerShell.Utility        {Format-List, Format
Manifest   Microsoft.WSMan.Management          {Disable-WSManCredSS
Script     Module                              {New-PSScript, New-G
Script     PSDiagnostics                       {Disable-PSTrace, Di
Script     PSFTP                               {Send-FTPItem, Recei
Binary     PSScheduledJob                      {New-JobTrigger, Add
Manifest   PSWorkflow                          {New-PSWorkflowExecu
Manifest   PSWorkflowUtility                   Invoke-AsWorkflow
Manifest   ServerManager                       {Get-WindowsFeature,
Manifest   TroubleshootingPack                 {Get-Troubleshooting
Manifest   WebAdministration                   {Start-WebCommitDela

这就是我所期望的......

但是当从计划任务(使用不同的用户)执行相同的操作时,我得到了:

Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules

ModuleType Name                                ExportedCommands                
---------- ----                                ----------------                
Manifest   BitsTransfer                        {Add-BitsFile, Remove-BitsTra...
Manifest   CimCmdlets                          {Get-CimAssociatedInstance, G...
Script     ISE                                 {New-IseSnippet, Import-IseSn...
Manifest   Microsoft.PowerShell.Diagnostics    {Get-WinEvent, Get-Counter, I...
Manifest   Microsoft.PowerShell.Host           {Start-Transcript, Stop-Trans...
Manifest   Microsoft.PowerShell.Management     {Add-Content, Clear-Content, ...
Manifest   Microsoft.PowerShell.Security       {Get-Acl, Set-Acl, Get-PfxCer...
Manifest   Microsoft.PowerShell.Utility        {Format-List, Format-Custom, ...
Manifest   Microsoft.WSMan.Management          {Disable-WSManCredSSP, Enable...
Script     PSDiagnostics                       {Disable-PSTrace, Disable-PSW...
Binary     PSScheduledJob                      {New-JobTrigger, Add-JobTrigg...
Manifest   TroubleshootingPack                 {Get-TroubleshootingPack, Inv...
Manifest   WebAdministration                   {Start-WebCommitDelay, Stop-W...

为什么这两者之间有区别?

我很困惑,因为我实际上感兴趣的模块是我自己创建并放入文件夹的模块:

C:\Windows\system32\WindowsPowerShell\v1.0\Modules

除了通过计划任务运行之外,这似乎工作正常。

我错过了什么?我忘记了什么?

此外 - 我可以确认两者的 $env:PSModulePath 是相同的:

C:\Users\GRIT.SVC.IPPlan\Documents\WindowsPowerShell\Modules;
C:\Windows\system32\WindowsPowerShell\v1.0\Modules\;
C:\Program Files\Common Files\Microsoft Lync Server 2013\Modules\;
C:\Program Files\Quest Software\Management Shell for AD\;
C:\Program Files\Microsoft Monitoring Agent\Agent\PowerShell\;
C:\Program Files\System Center Operations Manager 2012\Powershell\

当然用户路径除外。

最佳答案

发现问题...

它与 ExecutionPolicy 无关 - 直接路径也无法加载模块...

一旦找到,事情就简单多了......

问题是 64/32 位......

模块位于 C:\Windows\System32\WindowsPowerShell\v1.0\Modules

但是任务正在执行

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe

因此模块应位于 C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules

但是感谢您的关注。

关于计划任务中的 Powershell 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26217183/

相关文章:

background - WP8 : Any idea why OnInvoke not called in derived ScheduledTaskAgent

powershell - VS Code - Powershell 模块 - 命令无法识别

powershell - 安装包和 NuGet 包安装位置 - 安装到哪里?

excel - 如何将Excel中的图表复制到Word中?

Azure:将powershell的结果存储到存储帐户中

powershell - 获取出站 IP 范围 azure 网站 PowerShell

powershell - 在批处理脚本中执行 powershell 命令时转义字符

javascript - Azure 上使用 javascript 运行网页的计划任务

mysql - 在确定的时间安排查询执行

powershell - 如何解决 PowerShell V5 中的模块嵌套限制已超出错误?