Jump to content


syparon

List Collection Variables - Powershell

Recommended Posts

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"
  • Like 2

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.