Skip to content

Instantly share code, notes, and snippets.

Avatar

Kaido Järvemets Kaidja

View GitHub Profile
@Kaidja
Kaidja / Clean-CMSoftwareUpdateGroup
Created Dec 6, 2017
Cleanup ConfigMgr Software Update Group
View Clean-CMSoftwareUpdateGroup
Set-CMSoftwareUpdateGroup -Name 'SUM WRK 2017 11 November' -ClearExpiredSoftwareUpdate -ClearSupersededSoftwareUpdate
View Consolidate-ConfigMgrSWGroups.ps1
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 |
View Get-ConfigMgrResourceFQDN
$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
}
View Invoke-WsusServerCleanup
Invoke-WsusServerCleanup `
-CleanupObsoleteComputers `
-CleanupObsoleteUpdates `
-CleanupUnneededContentFiles `
-CompressUpdates `
-DeclineExpiredUpdates `
-DeclineSupersededUpdates
View AD devices count
#How many devices in Active Directory
Get-ADComputer -Filter * | Measure-Object
View Disabled devices in Active Directory
#How many disabled devices in Active Directory
Get-ADComputer -Filter {(Enabled -eq $False)} | Measure-Object
View Check if device exists in Configuration Manager
#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
View Getting data from ConfigMgr - Invoke-CMQuery
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'
View AD computer LastLogonDate
#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
View Preview Maintenance Windows before import
Import-CMMaintenanceWindows.ps1 -MWsInputFile E:\Scripts\MW\Maintenance_Solution.csv -Delimiter ',' -Preview
You can’t perform that action at this time.