#Import ConfigMgr PSH Module

Import-Module
$env:SMS_ADMIN_UI_PATH.Replace("\bin\i386","\bin\configurationmanager.psd1")

 

#Get the CMSITE SiteCode

$SiteCode = Get-PSDrive -PSProvider CMSITE

 

# Change the connection context

Set-Location "$($SiteCode.Name):\"

 

$BoundaryList = Get-CMBoundary

foreach($Boundary in $BoundaryList){

    New-CMDeviceCollection -Name $Boundary.DisplayName
-LimitingCollectionName "All Systems"

}

$Boundaries represents the entire collection of Boundary objects. When you
use $Boundaries.DisplayName, PowerShell is echoing out the DisplayName
property from ALL the Boundary objects, which results in an array of
strings, rather than a single String, which the New-CMDeviceCollection
cmdlet is expecting to be passed into its -Name parameter.

 

Cheers,

Trevor Sullivan

 

From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com]
On Behalf Of Marcum, John
Sent: Monday, January 20, 2014 11:06 AM
To: Scripting List (scripting@lists.myITforum.com)
Subject: [scripting] PoSH Create Collection

 

Can someone please tell me why this doesn't work?

 

#Import ConfigMgr PSH Module

Import-Module
$env:SMS_ADMIN_UI_PATH.Replace("\bin\i386","\bin\configurationmanager.psd1")

 

#Get the CMSITE SiteCode

$SiteCode = Get-PSDrive -PSProvider CMSITE

 

# Change the connection context

Set-Location "$($SiteCode.Name):\"

 

$Boundaries = Get-CMBoundary

foreach($item in $Boundaries){

    New-CMDeviceCollection -Name $Boundaries.DisplayName
-LimitingCollectionName "All Systems"

    }

 

Here's the error:

 

New-CMDeviceCollection : Cannot convert 'System.Object[]' to the type
'System.String' required by parameter 'Name'. Specified method is not
supported.

At line:10 char:34

+     New-CMDeviceCollection -Name $Boundaries.DisplayName
-LimitingCollectionName ... 

 

 

  _____  

John Marcum
Sr. Desktop Architect

Bradley Arant Boult Cummings LLP

  _____  

 

 

  _____  


Confidentiality Notice: This e-mail is from a law firm and may be protected
by the attorney-client or work product privileges. If you have received this
message in error, please notify the sender by replying to this e-mail and
then delete it from your computer.

 



Reply via email to