![](/img/trans.png)
[英]PowerShell - ShouldProcess not working when called from inside Invoke-Command
[英]Inconsistent PowerShell when command is called via Invoke-Command
我有一个简单的 Get-ScheduledTask 命令,它给了我一个简单的 output:
Get-ScheduledTask | select -last 1
TaskPath TaskName State
-------- -------- -----
\Microsoft\Windows\WS\ WSTask Ready
当我通过 Invoke-Command 调用这个相同的命令时(从上面的同一台计算机上运行),我有时会得到一个非常相似的 output:
Invoke-Command -ComputerName PRD-APIEXT001 -ScriptBlock {Get-ScheduledTask |select -last 1 } -Credential $cred
TaskPath TaskName State PSComputerName
-------- -------- ----- --------------
\Microsoft\Windows\WS\ WSTask Ready PRD-APIEXT001
但有时,我会得到更详细的 output:
Invoke-Command -ComputerName PRD-APIEXT001 -ScriptBlock {Get-ScheduledTask |select -last 1} -Credential $cred
PSComputerName : PRD-APIEXT001
RunspaceId : [REDACTED]
Actions : {MSFT_TaskComHandlerAction}
Author : Microsoft Corporation
Date : 2010-10-27T17:18:44.0816608
Description : Windows Store Maintenance Task
Documentation :
Principal : MSFT_TaskPrincipal2
SecurityDescriptor : [REDACTED]
Settings : MSFT_TaskSettings3
Source : wsservice.dll
State : 3
TaskName : WSTask
TaskPath : \Microsoft\Windows\WS\
Triggers :
URI : \Microsoft\Windows\WS\WSTask
Version :
我不知道为什么它有时是简单的 output,有时是冗长的 output,除了它似乎只在一个方向上改变; 从冗长到简单。 That is, once a PowerShell session shows the simple output, it never seems to go back to the verbose output. 但有时,曾经显示冗长 output 的 session 会切换到简单的。
现在,我从这个 StackOverflow 问题中知道 Invoke-Command 将属性添加到它返回的每个 object 中。
但是我仍然不知道为什么它有时会给出基于表的 output,有时会给我一个属性列表,如 output。
谁能告诉我这里可能会发生什么?
我正在使用 PowerShell 版本 5.1.14409.1018。
看起来在加载 ScheduledTasks 模块之前,无论是使用 import-module 还是在本地运行 get-scheduledtask,都不会加载该类型 object 的显示信息。
Import-Module ScheduledTasks
icm localhost { get-scheduledtask | select -last 1 } # elevated prompt for localhost
TaskPath TaskName
-------- --------
\Microsoft\XblGameSave\ XblGameSaveTaskLogon
Get-ScheduledTask | select -last 1 | get-member | findstr TypeName
TypeName:
'Microsoft.Management.Infrastructure.CimInstance#Root/Microsoft/Windows/TaskScheduler/MSFT_ScheduledTask'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.