Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #***************************************************
- # THE FOLLOWING SCRIPT WILL CREATE A
- # COLLECTION BASED ON AN ACTIVE
- # DIRECTORY SECURITY GROUP
- #***************************************************
- #####################PARAMETERS#####################
- #
- #ENTER NAME OF THE AD SECURITY GROUP #
- $ADSecurityGroup = "SG_APP_Notepad++"
- #
- #ENTER NAME OF APPLICATION/PACKAGE
- $PackageName = "Notepad++"
- #
- #ENTER NAME OF THE AD NETBIOS NAME #
- $DomainName = "JVTEST"
- ####################################################
- #
- #*********** DO NOT EDIT BELOW THIS LINE ***********
- #
- ####################################################
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #
- #Load Configuration Manager PowerShell Module
- Import-module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5)+ '\ConfigurationManager.psd1')
- #
- #Get SiteCode
- $SiteCode = Get-PSDrive -PSProvider CMSITE
- Set-location $SiteCode":"
- #
- #Error Handling and output
- Clear-Host
- $ErrorActionPreference= 'SilentlyContinue'
- #
- #
- $InstCollectionName = 'Install '+$PackageName
- $UninstCollectionName = 'Uninstall '+$PackageName
- #
- #ENTER NAME OF ACTIVE DIRECTORY SECURITY GROUP#
- $SecurityGroupName = $DomainName+'\\'+$ADSecurityGroup
- #
- #
- #Limiting COLLECTION
- $LimitingCollection = 'All Systems'
- #
- #
- #ENTER COLLECTION SCHEDULE DATE#
- $ScheduleDate = "09/09/2019 9:00 PM"
- $ScheduleDay = "Sunday"
- #
- #DEFINE DEPLOYMENT SCHEDULE
- $Schedule1 = New-CMSchedule -Start $ScheduleDate -DayOfWeek $ScheduleDay -RecurCount 1
- #
- #
- $QueryRuleName = 'Q_AD_'+$PackageName
- #
- $SecurityGroupQuery = "select * from SMS_R_System where SMS_R_System.SystemGroupName = '$SecurityGroupName' "
- #
- $AppDetectionQuery = "select distinct SMS_R_System.ResourceId, SMS_R_System.ResourceType, SMS_R_System.Name, SMS_R_System.SMSUniqueIdentifier, SMS_R_System.ResourceDomainORWorkgroup, SMS_R_System.Client from SMS_R_System inner join SMS_G_System_ADD_REMOVE_PROGRAMS_64 on SMS_G_System_ADD_REMOVE_PROGRAMS_64.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_ADD_REMOVE_PROGRAMS on SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID = SMS_R_System.ResourceId where SMS_G_System_ADD_REMOVE_PROGRAMS_64.DisplayName like '%$PackageName%' or SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName like '%$PackageName%'"
- #
- #Perform the SCCM Magic
- #Create Installation Groups
- New-CMDeviceCollection -Name $InstCollectionName -Comment "This collection checks for AD Group Membership and performs an automated install, or allows users to perform an install of $PackageName via Software Center" -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule1 -RefreshType Both
- #
- Add-CMDeviceCollectionQueryMembershipRule -CollectionName $InstCollectionName -QueryExpression $SecurityGroupQuery -RuleName $QueryRuleName
- #
- New-CMApplicationDeployment -CollectionName $InstCollectionName -Name $PackageName -DeployAction Install -DeployPurpose Required -UserNotification DisplaySoftwareCenterOnly -AvailableDateTime (get-date) -OverrideServiceWindow $True -TimeBaseOn LocalTime
- #
- #Create Uninstallation Groups
- New-CMDeviceCollection -Name $UninstCollectionName -Comment "This collection checks for AD Group Membership and performs an automated uninstall, or allows users to perform an uninstall of $PackageName via Software Center if the Device is not a member of the AD Group" -LimitingCollectionName $LimitingCollection -RefreshSchedule $Schedule1 -RefreshType Both
- #
- Add-CMDeviceCollectionQueryMembershipRule -CollectionName $UninstCollectionName -QueryExpression $AppDetectionQuery -RuleName "Q_Check_For_$PackageName"
- Add-CMDeviceCollectionExcludeMembershipRule -CollectionName $UninstCollectionName -ExcludeCollectionName $InstCollectionName
- #
- New-CMApplicationDeployment -CollectionName $UninstCollectionName -Name $PackageName -DeployAction Uninstall -DeployPurpose Required -UserNotification DisplaySoftwareCenterOnly -AvailableDateTime (get-date) -OverrideServiceWindow $True -TimeBaseOn LocalTime
- #
- #Uncomment if item is a Package (Not used/tested)
- #New-CMPackageDeployment -PackageName "$PackageName" -ProgramName "$PackageName" -CollectionName "$CollectionName" -StandardProgram -FastNetworkOption DownloadContentFromDistributionPointAndRunLocally -SlowNetworkOption DownloadContentFromDistributionPointAndLocally -Comment $PackageName -DeployPurpose Available
- #
- CD ([Environment]::GetFolderPath("Desktop"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement