Skip to content

Instantly share code, notes, and snippets.

@DexterPOSH
Created February 21, 2015 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DexterPOSH/dd4b41d2abbc80f47f4d to your computer and use it in GitHub Desktop.
Save DexterPOSH/dd4b41d2abbc80f47f4d to your computer and use it in GitHub Desktop.
#http://www.powtoon.com/show/fSSkwprWGjy/configmgr-12-powershell/#/
#region Get Started
#You can open the PowerShell Console pre-loaded using the ConfigMgr Console
#Load the ConfigMgr Module
Import-Module -Name "$(split-path $Env:SMS_ADMIN_UI_PATH)\ConfigurationManager.psd1"
#get all the CM Cmdlets
Get-Command -Module ConfigurationManager
#CMSite PSprovider
#Look at help
Update-Help -Module ConfigurationManager
Help Get-CMApplication -full
#Open a PSSession and import the ConfigMgr Module (using Invoke-Command)
$session = New-PSSession -ComputerName DexSCCM
Invoke-Command -Session $session -ScriptBlock {Import-Module -Name "$(split-path $Env:SMS_ADMIN_UI_PATH)\ConfigurationManager.psd1"; Set-Location -Path "DEX:"}
Invoke-Command -ScriptBlock {Get-CMSite} -Session $session
#endregion Get Started
#region Boundaries
#Get list of all Boundaries
Get-CMBoundary
#create a new Boundary
New-CMBoundary -Name TestBoundary -Type IPSubnet -Value '10.1.1.0/16' -Verbose
#Remove a boundary
Get-CMBoundary -Name TestBoundary | Remove-CMBoundary
#endregion Boundaries
#region Boundary Groups
New-CMBoundaryGroup -Name DexLabDPGroup -DefaultSiteCode DEX -Description "DP Group for Dex's LAB"
#endregion
#region Collections
#create a Collection
New-CMDeviceCollection -Name TestCollection -LimitingCollectionName "All Systems" | Tee-Object -Variable testCollection
#Add a Direct MembershipQueryRule
Add-CMDeviceCollectionDirectMembershipRule -Collection $testCollection -Resource (Get-CMDevice -Name DexExch ) -Verbose
#Add a Query MembershipRule
#endregion Collections
#region Folders
#create Folders under Device Collections using CMSite PSProvider
Set-Location -Path DEX:\DeviceCollection
#create the same hierarchy under the Applications
New-Item -Name Corp-Dex -Verbose
Set-Location -Path .\Corp-Dex
New-Item -Name "Server2012"
New-Item -Name "Server2008"
New-Item -Name "Deleteme"
Remove-Item -Path .\Deleteme
#endregion Folders
#Let's make a structure similar to an OU in my AD
Import-Module -Name ActiveDirectory
Set-Location -Path "AD:\OU=Corp-Dex,DC=dex,DC=com"
$childs = Get-ChildItem
Set-Location -Path "DEX:"
$childs | foreach -process { New-CMDeviceCollection -Name $_.name -LimitingCollectionId SMS00001 -Verbose } | ForEach-Object { Move-CMObject -FolderPath "Dex:\DeviceCollection\Corp-Dex\$($_.Name)" -InputObject $_ }
#region Applications
#create a new Application
New-CMApplication -Name "7-zip" -Description "7-zip" -SoftwareVersion "1.51" -AutoInstall $true
#Add the Deployment type automatically from the MSI
Add-CMDeploymentType -ApplicationName "7-zip" -InstallationFileLocation "\\dexsccm\Packages\7z920-x64.msi" -MsiInstaller -AutoIdentifyFromInstallationFile -ForceForUnknownPublisher $true -InstallationBehaviorType InstallForSystem
#Distribute the Content to the DP Group
Start-CMContentDistribution -ApplicationName "7-zip" -DistributionPointGroupName "DexLabDPGroup" -Verbose
#start the Deployment
Start-CMApplicationDeployment -CollectionName "Server2012" -Name "7-zip" -DeployAction Install -DeployPurpose Available -UserNotification DisplayAll -AvaliableDate (get-date) -AvaliableTime (get-date) -TimeBaseOn LocalTime -Verbose
#Run the Deployment Summarization
Invoke-CMDeploymentSummarization -CollectionName "Server2012" -Verbose
Invoke-CMClientNotification -DeviceCollectionName "Server2012" -NotificationType RequestMachinePolicyNow -Verbose
#endregion Applications
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment