Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell管道:将System.ServiceProcess.ServiceController转换为PSObject_Powershell - Fatal编程技术网

Powershell管道:将System.ServiceProcess.ServiceController转换为PSObject

Powershell管道:将System.ServiceProcess.ServiceController转换为PSObject,powershell,Powershell,我一直认为Powershell管道是通过名称或类型匹配实现的(如中所述)。对我来说没关系。但Powershell如何实现以下示例: > Get-Service "*win*" | ForEach-Object { Write-Host $_.DisplayName} Get Service返回类型为System.ServiceProcess.ServiceController的对象,确定。但是Foreach对象只接受PSObject作为InputObject: > Get-Help

我一直认为Powershell管道是通过名称或类型匹配实现的(如中所述)。对我来说没关系。但Powershell如何实现以下示例:

> Get-Service "*win*" | ForEach-Object { Write-Host $_.DisplayName}
Get Service
返回类型为
System.ServiceProcess.ServiceController
的对象,确定。但是
Foreach对象
只接受
PSObject
作为
InputObject

> Get-Help ForEach-Object -Parameter inputobject

    -InputObject <PSObject>
     ...
     Accept pipeline input?       True (ByValue)
>获取每个对象的帮助-参数inputobject
-输入对象
...
接受管道输入?真(按值)
我的问题:Powershell如何将任何给定对象(因为
Foreach对象
可以接受任何输入对象)转换为
PsObject


Thx

我想说的是,文件是问题所在。如果执行此操作:
Get Service“*win*”| ForEach对象{$\uu0.GetType()}
您将看到它们仍然是ForEach对象中的ServiceController对象。