Skip to content

List Collection Variables - Powershell

Featured Replies

Hello I would like to know how to list collection variables with powershell

  • Author

Thanks Kevlar01 I just succeed at the same time you posted ;)

 

Param(
[string]$Collection
)
#/ Session Creation /*---------------------------------------------------------------------------------------------
Try {
$MySession = New-PSSession $ServerHostName
}
Catch{
Write-Host "Error: $($_.Exception.Message)"
}
#/-----------------------------------------------------------------------------------------------------------------
#/-----------------------------------------------------------------------------------------------------------------
#/-----------------------------------------------------------------------------------------------------------------
Invoke-Command -session $MySession -ArgumentList $Collection -script {
param ($Collection)
#/ Import Module + Change Drive /*---------------------------------------------------------------------------------
Import-Module "Path TO Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1"
$SCCMDrv = Get-PSDrive -PSProvider CMSite
cd "$($SCCMDrv):"
#/-----------------------------------------------------------------------------------------------------------------
$CollectionInfos = Get-WmiObject -Namespace "Root\SMS\Site_$SiteCode" -Class SMS_Collection -Filter "Name='$Collection'" | Select CollectionID
$CollectionID = $CollectionInfos.CollectionID
$MyCollection = Get-WmiObject -Namespace Root\SMS\Site_$SiteCode -Class SMS_CollectionSettings -Filter "CollectionID = '$CollectionID'"
$MyCollection.Get()
foreach($Value in $MyCollection.CollectionVariables) {
$Value
# OR $Value.Name
}
Exit
}
You can call your script by using the following command : Powershell -ExecutionPolicy Unrestricted -File ListDeviceCollectionVariables.ps1 -Collection "My Collection Name"
  • 11 months later...

Hello - I'm a complete noob to powershell. I have attempted to run your script but receive "You cannot call a method on a null-valued expression." Is the 'null valued expression '$Value'? It's the only variable that isn't defined. Also, once I have it working, I want it to output both a collection's variable along with it's value. Any help you can provide would be greatly appreciated.

 

Gil

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.