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 InputObject管道到Cmdlet-CM RemoveDevice_Powershell_Sccm - Fatal编程技术网

Powershell InputObject管道到Cmdlet-CM RemoveDevice

Powershell InputObject管道到Cmdlet-CM RemoveDevice,powershell,sccm,Powershell,Sccm,我正在编写迁移脚本的这一部分: $devnames = Get-CMDevice -Name ($Site + "CSP*") | Remove-CMDevice 我得到这个错误: 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

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

$devnames = Get-CMDevice -Name ($Site + "CSP*") | Remove-CMDevice
我得到这个错误:

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";
我可以看到,也许我需要以某种方式将管道第一部分的设备转换为输入对象“值”?除非我使用了
|选择名称
等,否则我认为它们是正确的。因此,我对最后一步感到困惑。有人知道我哪里出了问题吗?

这很有效-归功于@Ansgar

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

目标cmdlet似乎不接受按属性名称(仅按值)进行的管道输入,因此我将尝试扩展输入对象的
name
属性:
(Get CMDevice-name($Site+“CSP*”)).Name | Remove CMDevice
对我不起作用。遗憾的是@Ansgar无法将输入对象绑定到该命令的任何参数,因为该命令不接受管道输入,或者输入及其属性与接受管道输入的任何参数都不匹配。+CategoryInfo:InvalidArgument:(DEV01:PSObject)[Remove CMDevice],ParameterBindingException+FullyQualifiedErrorId:InputObject NotBound,Microsoft.ConfigurationManagement.Cmdlet.Collections.Commands.RemoveDeviceCommand,然后您很可能不得不使用循环,例如:
Get CMDevice-Name($Site+“CSP*”)| ForEach对象{Remove CMDevice$}
。我不知道为什么在某些情况下需要这样做,但我遇到过这样的情况:根据文档,cmdlet应该接受管道输入,但没有接受。关于按值理论和名称@ansgar wiechers仅供参考(无法测试atm)。(设备和许多其他对象的)名称在SCCM中不是唯一的,因此它不是一种安全的方法。Id将是唯一的,所以可能这就是所需要的。试图验证我的假设,即需要Id,但截至SCCM 1802,这似乎是固定的。原来的管道现在似乎可以正常工作了。令人惊讶的是,这对$Site=“ABC”$csv=Import csv“C:csv.csv”foreach($csv中的行){Get-CMBoundary-BoundaryName$line.Name | Where-Object{$\ Value-eq$line.Subnet-和$\ ShortCode-eq“$Site”}| ForEach对象{Remove-CMBoundary-Id$|.BoundaryID}
$Site = Read-Host -Prompt "Enter 3 Letter Site Code"
$devnames = Get-CMDevice -Name ($Site + "*")

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