错误 - 无法将参数绑定到参数 'InputObject',因为它为空
Error - Cannot bind argument to parameter 'InputObject' because it is null
我正在使用 SCCM 2016,Windows Server 2012。我正在使用下面的代码将 collection 移动到另一个文件夹。我收到错误消息 Move-CMObject : Cannot bind argument to parameter 'InputObject' because it is null.
我已经通过 Google 研究了错误,但我仍然无法理解 'InputObject' 为何为空。我已经看到其他 PS 脚本以相同的方式格式化,它是一个有效的脚本。我想知道如何解决此问题并将 collection 移动到另一个文件夹。
$sitecode = "123"
$colltomove = "SLS00287"
$destcollfolder = '$($sitecode):\DeviceCollection\Test Operational'
$collID = Get-CMCollection -Name $colltomove
Move-CMObject -InputObject $collID -FolderPath $destcollfolder
您看到的错误告诉我们 $collID
是 $null
- 表明 Get-CMCollection
调用没有 return 任何东西。
如您所见,SLS00287
是 Collection ID,而不是名称,因此请先更新它:
$deviceCollection = Get-CMDeviceCollection -CollectionId -CollectionID $colltomove
接下来,为了让 PowerShell 正确扩展 $destcollfolder
中的 $siteCode
变量,您需要使用 double-quotes ("
) 而不是 single-quotes ('
):
$destcollfolder = "$($sitecode):\DeviceCollection\Test Operational"
最后,我建议在调用时利用管道绑定 Move-CMObject
:
$deviceCollection |Move-CMObject -FolderPath $destcollfolder
我正在使用 SCCM 2016,Windows Server 2012。我正在使用下面的代码将 collection 移动到另一个文件夹。我收到错误消息 Move-CMObject : Cannot bind argument to parameter 'InputObject' because it is null.
我已经通过 Google 研究了错误,但我仍然无法理解 'InputObject' 为何为空。我已经看到其他 PS 脚本以相同的方式格式化,它是一个有效的脚本。我想知道如何解决此问题并将 collection 移动到另一个文件夹。
$sitecode = "123"
$colltomove = "SLS00287"
$destcollfolder = '$($sitecode):\DeviceCollection\Test Operational'
$collID = Get-CMCollection -Name $colltomove
Move-CMObject -InputObject $collID -FolderPath $destcollfolder
您看到的错误告诉我们 $collID
是 $null
- 表明 Get-CMCollection
调用没有 return 任何东西。
如您所见,SLS00287
是 Collection ID,而不是名称,因此请先更新它:
$deviceCollection = Get-CMDeviceCollection -CollectionId -CollectionID $colltomove
接下来,为了让 PowerShell 正确扩展 $destcollfolder
中的 $siteCode
变量,您需要使用 double-quotes ("
) 而不是 single-quotes ('
):
$destcollfolder = "$($sitecode):\DeviceCollection\Test Operational"
最后,我建议在调用时利用管道绑定 Move-CMObject
:
$deviceCollection |Move-CMObject -FolderPath $destcollfolder