InputObject管道到Cmdlet-CM-RemoveDevice

时间:2018-07-13 10:15:17

标签: powershell sccm

我正在编写迁移脚本的这一部分:

Kind                                                   | Example
==============================================================================================
Reference to a static method                           | ContainingClass::staticMethodName
-------------------------------------------------------+--------------------------------------
Reference to an instance method of a particular object | containingObject::instanceMethodName
-------------------------------------------------------+--------------------------------------
Reference to an instance method of an arbitrary object | ContainingType::methodName
of a particular type                                   |
-------------------------------------------------------+--------------------------------------
Reference to a constructor                             | ClassName::new
==============================================================================================

我收到此错误:

The input object cannot be bound to any parameters for the command either
because the command does not take pipeline input or the input and its
properties do not match any of the parameters that take pipeline input.
     + CategoryInfo          : InvalidArgument: ([SecurityVerbs(..."USER1";

查看帮助,它查看此cmdlet只能接受InputObject的输入

-InputObject
Specifies a device object. To obtain a device object, use the Get-CMDevice cmdlet.

Type:   IResultObject
Position:   0
Default value:  None


Accept pipeline input:  True (ByValue)
Accept wildcard characters: False
-Name
Specifies the name of a device.

Type:   String
Aliases:    DeviceName
Position:   0
Default value:  None
Accept pipeline input:  False
Accept wildcard characters: False

然后我尝试了这个:

$devnames = Get-CMDevice -Name ($Site + "CSP*") | Remove-CMDevice

我可以看到,也许我需要以某种方式将管道第一部分中的设备转换为输入对象“值”?我以为除非我使用$Site = Read-Host -Prompt "Enter 3 Letter Site Code" $devnames = Get-CMDevice -Name ($Site + "*") foreach ($device in $devicenames) { Remove-CMDevice $device } 等,否则它们是最后一步。有谁知道我要去哪里错了?

1 个答案:

答案 0 :(得分:0)

这有效-归功于@Ansgar

 $devicenames = (Get-CMDevice -Name ($Site + "CSP*")).Name
    ForEach ($device in $devicenames) 
    { Remove-CMDevice -DeviceName $Device -Force } 
相关问题