Manning
Manning

Reputation: 99

Error - Cannot bind argument to parameter 'InputObject' because it is null

I am using SCCM 2016, Windows Server 2012. I am using the code below to move a collection to another folder. I get the error message Move-CMObject : Cannot bind argument to parameter 'InputObject' because it is null.

I've researched the error via Google but I still can't understand how 'InputObject' is null. I have seen other PS script formatted the same way and it is a working script. I'd like to know how to fix this and move the collection to another folder.

$sitecode = "123"
$colltomove = "SLS00287"
$destcollfolder = '$($sitecode):\DeviceCollection\Test Operational' 

$collID = Get-CMCollection -Name $colltomove
Move-CMObject -InputObject $collID -FolderPath $destcollfolder

Upvotes: 0

Views: 2416

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174815

The error you see tells us that $collID is $null - indicating that the Get-CMCollection call didn't return anything.

As you've found, SLS00287 is the Collection ID, not the name, so update that first:

$deviceCollection = Get-CMDeviceCollection -CollectionId -CollectionID $colltomove

Next, in order to have PowerShell correctly expand the $siteCode variable in $destcollfolder, you need to use double-quotes (") rather than single-quotes ('):

$destcollfolder = "$($sitecode):\DeviceCollection\Test Operational"

Finally, I'd suggest taking advantage of pipeline binding when invoking Move-CMObject:

$deviceCollection |Move-CMObject -FolderPath $destcollfolder

Upvotes: 1

Related Questions