Find Installed Software
Find all software which ‘Name’ contains ‘symantec’
Get-WmiObject -Class win32_product -Filter "Name like '%symantec%'"
Uninstall Software
> $sw = Get-WmiObject -Class win32_product -Filter "Name like '%symantec%'"
> $sw.Uninstall()
__GENUS : 2
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH :
__PROPERTY_COUNT : 1
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
ReturnValue : 0 <-- Check ReturnValue is equal 0
PSComputerName :
SCCM Client
Run SCCM Cycles
To run SCCM cycles I created a helper function, which I call from subsequent functions
function _sccm-cycle() {
param(
[Parameter(Mandatory = $true, Position = 0)]
[String]$cycleID
)
$cycles = (
'{00000000-0000-0000-0000-000000000121}', # ApplicationDeployment Evaluation Cycle
'{00000000-0000-0000-0000-000000000003}', # DiscoveryData Collection Cycle
'{00000000-0000-0000-0000-000000000010}', # FileCollection Cycle
'{00000000-0000-0000-0000-000000000001}', # HardwareInventory Cycle
'{00000000-0000-0000-0000-000000000021}', # MachinePolicy Retrieval Cycle
'{00000000-0000-0000-0000-000000000002}', # SoftwareInventory Cycle
'{00000000-0000-0000-0000-000000000031}', # SoftwareMetering Usage Report Cycle
'{00000000-0000-0000-0000-000000000114}', # SoftwareUpdate Deployment Evaluation Cycle
'{00000000-0000-0000-0000-000000000113}', # SoftwareUpdate Scan Cycle
'{00000000-0000-0000-0000-000000000111}', # StateMessage Refresh
'{00000000-0000-0000-0000-000000000026}', # UserPolicy Retrieval Cycle
'{00000000-0000-0000-0000-000000000027}', # UserPolicy Evaluation Cycle
'{00000000-0000-0000-0000-000000000032}', # WindowsInstallers Source List Update Cycle
'{00000000-0000-0000-0000-000000000022}' # MachinePolicy Evaluation Cycle
)
if($cycles.contains($cycleID)) {
Invoke-WMIMethod -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule $cycleID
} elseif($cycleID.tolower() -eq "all") {
$cycles | % {
write-host "Trigger schedule: $($_)"
Invoke-WMIMethod -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule $_
sleep 1
}
} else {
write-warning "Did not find cycle identifier $cycleID not found!"
write-error "$cycleID is not a valid identifier!"
return $false;
}
}
The following susequent functions I created, are the most frequent commands I use
function sccm-applicationDeploymentEvaluationCycle() {
_sccm-cycle('{00000000-0000-0000-0000-000000000121}');
}
function sccm-machinePolicyRetrievalCycle() {
_sccm-cycle('{00000000-0000-0000-0000-000000000021}');
}
Clear SCCM Caches
function sccm-clearLocalCache() {
## Initialize the CCM resource manager com object
[__comobject]$CCMComObject = New-Object -ComObject 'UIResource.UIResourceMgr'
## Get the CacheElementIDs to delete
$CacheInfo = $CCMComObject.GetCacheInfo().GetCacheElements()
## Remove cache items
ForEach ($CacheItem in $CacheInfo) {
$null = $CCMComObject.GetCacheInfo().DeleteCacheElement([string]$($CacheItem.CacheElementID))
}
}
Get Status of Application
> $sw = Get-WmiObject -Namespace "root\ccm\ClientSDK" -Class CCM_Application | ? {$_.name -eq "Name of Software"}
> $sw.InstallState
NotInstalled
Trigger Installation of Application
Function sccm-triggerAppInstallation {
Param (
[String][Parameter(Mandatory=$True, Position=0)] $AppName,
[ValidateSet("Install","Uninstall")]
[String][Parameter(Mandatory=$True, Position=1)] $Method,
[String][Parameter(Mandatory=$False)] $Computername=$env:computername
)
Begin {
$Application = (Get-CimInstance -ClassName CCM_Application -Namespace "root\ccm\clientSDK" -ComputerName $Computername | Where-Object {$_.Name -like $AppName})
$Args = @{
EnforcePreference = [UINT32] 0
Id = "$($Application.id)"
IsMachineTarget = $Application.IsMachineTarget
IsRebootIfNeeded = $False
Priority = 'High'
Revision = "$($Application.Revision)"
}
}
Process {
Invoke-CimMethod -Namespace "root\ccm\clientSDK" -ClassName CCM_Application -ComputerName $Computername -MethodName $Method -Arguments $Args
}
End {}
}