-
Notifications
You must be signed in to change notification settings - Fork 0
/
SCCM.RemoteConnection.ExportCollectionTxt
23 lines (19 loc) · 1.26 KB
/
SCCM.RemoteConnection.ExportCollectionTxt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<#
############################################################################################################
# Pierranchis # Description: Exports all members of #
# Export Collection Members to Text file # defined collection(s) to text file #
# Created: 10/24/2018 # #
############################################################################################################
#>
# Variables
$SCCMServerName = "SCCM Server Name"
$CollectionID_01 = "acd00001"
$OutputID_01 = "\\filepath\filename.txt"
#Connect to SCCM remotely
$session = New-PSSession -ComputerName $SCCMServerName -ConfigurationName Microsoft.PowerShell32
Invoke-Command -Session $session -ScriptBlock { Import-Module -Name "$(split-path $Env:SMS_ADMIN_UI_PATH)\ConfigurationManager.psd1"; Set-Location -path "$(Get-PSDrive -PSProvider CMSite):\" -verbose }
Import-PSSession -Session $session -Module ConfigurationManager -AllowClobber
# Query collection and export to text file
Get-CMCollectionMember -CollectionId $CollectionID_01 | Select-Object -ExpandProperty Name | out-file $OutputID_01
# Log out of remote session
Remove-PSsession $session