Skip to content

Instantly share code, notes, and snippets.

View Kaidja's full-sized avatar

Kaido Järvemets Kaidja

View GitHub Profile
@Kaidja
Kaidja / Clean-CMSoftwareUpdateGroup
Created December 6, 2017 11:53
Cleanup ConfigMgr Software Update Group
Set-CMSoftwareUpdateGroup -Name 'SUM WRK 2017 11 November' -ClearExpiredSoftwareUpdate -ClearSupersededSoftwareUpdate
Import-Module $env:SMS_ADMIN_UI_PATH.Replace("\bin\i386","\bin\configurationmanager.psd1")
$CMSite = Get-PSProvider -PSProvider CMSITE
Set-Location -Path "$($CMSite.Drives.Name):\"
# 2017 Software Update Groups
#Create new Software Update Group for 2017 Updates
New-CMSoftwareUpdateGroup -Name 'SUM WRK 2017 Compliance'
#Get 2017 Software Updates Groups
$SWGroups = Get-CMSoftwareUpdateGroup -Name 'SUM WRK 2017*' -ForceWildcardHandling |
$CollectionMembers = Get-CMCollectionMember -CollectionId PS10008E
foreach($Member in $CollectionMembers){
$ResourceQuery = Get-CimInstance `
-Namespace 'Root\SMS\Site_PS1' `
-Query "Select * from SMS_R_System where ResourceID=$($Member.ResourceID)"
$ResourceQuery.ResourceNames
}
Invoke-WsusServerCleanup `
-CleanupObsoleteComputers `
-CleanupObsoleteUpdates `
-CleanupUnneededContentFiles `
-CompressUpdates `
-DeclineExpiredUpdates `
-DeclineSupersededUpdates
#How many devices in Active Directory
Get-ADComputer -Filter * | Measure-Object
#How many disabled devices in Active Directory
Get-ADComputer -Filter {(Enabled -eq $False)} | Measure-Object
#AD Computer account last logon date
Get-ADComputer -Identity KLASSB315-2 -Properties LastLogonDate
#AD Computer account last logon date in days
$ADComputerInfo = Get-ADComputer -Identity PC1 -Properties LastLogonDate
$TimeSpan = New-TimeSpan -Start $ADComputerInfo.LastLogonDate -End (Get-Date)
$TimeSpan.Days
#Check if device exists in Configuration Manager
Import-Module $env:SMS_ADMIN_UI_PATH.Replace("\bin\i386","\bin\configurationmanager.psd1")
$CMSite = Get-PSProvider -PSProvider CMSITE
Set-Location -Path "$($CMSite.Drives.Name):\"
#Query against Configuration Manager
$ADComputerInfo = Get-ADComputer -Identity PC1
Get-CMDevice -Name $ADComputerInfo.Name
Import-Module $env:SMS_ADMIN_UI_PATH.Replace("\bin\i386","\bin\configurationmanager.psd1")
$CMSite = Get-PSProvider -PSProvider CMSITE
Set-Location -Path "$($CMSite.Drives.Name):\"
Invoke-CMQuery -Name 'All Non-Client Systems'
Import-CMMaintenanceWindows.ps1 -MWsInputFile E:\Scripts\MW\Maintenance_Solution.csv -Delimiter ',' -Preview