syparon Posted May 23, 2014 Report post Posted May 23, 2014 Hello I would like to know how to list collection variables with powershell Quote Share this post Link to post Share on other sites More sharing options...
kevlar01 Posted May 23, 2014 Report post Posted May 23, 2014 Check this blogpost: http://it.peikkoluola.net/2013/09/30/display-a-sccm-collection-variable-and-its-value/ Quote Share this post Link to post Share on other sites More sharing options...
syparon Posted May 23, 2014 Report post Posted May 23, 2014 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" 2 Quote Share this post Link to post Share on other sites More sharing options...
grosales Posted April 27, 2015 Report post Posted April 27, 2015 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 Quote Share this post Link to post Share on other sites More sharing options...