SCClient.psm1
<#
.Synopsis Get pending updates on the client. .Description You can use this commandlet to check the pending updates on the client. .Parameter ComputerName The computer you like to target. .Parameter Credential The credentials you like to use to manage the target computer. .Example Get-SCClientPendingUpdate Get all Pending updates on the local computer. .Example Get-SCClientPendingUpdate -UpdateID "UpdateID" Get Pending updates on the local computer with a specific UpdateID. .Example Get-SCClientPendingUpdate -ArticleID "ArticleID" Get Pending updates on the local computer with a specific ArticleID. .Example Get-SCClientPendingUpdate -ComputerName "ClientName" -Credential "CredentialObject" Get all Pending updates on the remote computer. .Example Get-SCClientPendingUpdate -ComputerName "ClientName" -Credential "CredentialObject" -UpdateID "UpdateID" Get Pending updates on the remote computer with a specific UpdateID. .Example Get-SCClientPendingUpdate -ComputerName "ClientName" -Credential "CredentialObject" -ArticleID "ArticleID" Get Pending updates on the remote computer with a specific ArticleID. #> function Get-SCClientPendingUpdate { param( [Parameter(Mandatory=$false)] [string] $ComputerName="localhost", [Parameter(Mandatory=$false)] [pscredential] [System.Management.Automation.Credential()] $Credential, [Parameter(Mandatory=$false)] [string] $UpdateID="%", [Parameter(Mandatory=$false)] [string] $ArticleID="%" ) if($(Test-Connection -ComputerName $ComputerName -Count 1 -BufferSize 10 -Quiet)) { $modulepath = $PSCommandPath.Replace("\SCClient.psm1","") [xml]$XmlComplianceStates = Get-Content -Path $modulepath\ComplianceStateUpdates.xml [xml]$XmlEvaluationStates = Get-Content -Path $modulepath\EvaluationStateUpdates.xml if($ComputerName -eq "localhost") { $updates = Get-CimInstance -Namespace "Root\ccm\ClientSDK" -Query "SELECT * FROM CCM_SoftwareUpdate WHERE UpdateID like '$UpdateID' AND ArticleID like '$ArticleID'" -ErrorAction Stop } else { if($Credential) { $session = New-CimSession -Credential $Credential -ComputerName $ComputerName } else { $session = New-CimSession -ComputerName $ComputerName } $updates = Get-CimInstance -Namespace "Root\ccm\ClientSDK" -Query "SELECT * FROM CCM_SoftwareUpdate WHERE UpdateID like '$UpdateID' AND ArticleID like '$ArticleID'" -CimSession $session -ErrorAction Stop Remove-CimSession $session } foreach($update in $updates) { foreach($ComplianceState in $($XmlComplianceStates.states.option)) { if($ComplianceState.value -eq $update.ComplianceState) { $ComplianceStateProp=$ComplianceState.state } } foreach($EvaluationState in $($XmlEvaluationStates.states.option)) { if($EvaluationState.value -eq $update.EvaluationState) { $EvaluationStateProp=$EvaluationState.state } } $props = [ordered]@{ Name = $update.Name; ArticleID = $update.ArticleID; BulletinID = $update.BulletinID; UpdateID = $update.UpdateID; ExclusiveUpdate = $update.ExclusiveUpdate; ComplianceState = $ComplianceStateProp; EvaluationState = $EvaluationStateProp; PercentComplete = $update.PercentComplete; MaxExecutionTime = $update.MaxExecutionTime; URL = $update.URL; ErrorCode = $update.ErrorCode; RebootOutsideServiceWindows = $update.RebootOutsideServiceWindows; StartTime = $update.RebootOutsideServiceWindows; Publisher = $update.Publisher; UserUIExperience = $update.UserUIExperience; PSComputerName = $update.PSComputerName; PSCredential = $Credential; } New-Object -property $props -TypeName psobject } } else { Write-Error "The computer you try to manage is offline." -Category ConnectionError } } <# .Synopsis Get installed software on the client. .Description You can use this commandlet to list all installed software on the client. .Parameter ComputerName The computer you like to target. .Parameter Credential The credentials you like to use to manage the target computer. .Example Get-SCClientInstalledSoftware Get all installed software on the local computer. .Example Get-SCClientInstalledSoftware -ComputerName "ClientName" -Credential "CredentialObject" Get all installed software on the remote computer. #> function Get-SCClientInstalledSoftware { param( [Parameter(Mandatory=$false)] [string] $ComputerName="localhost", [Parameter(Mandatory=$false)] [pscredential] [System.Management.Automation.Credential()] $Credential ) if($(Test-Connection -ComputerName $ComputerName -Count 1 -BufferSize 10 -Quiet)) { if($ComputerName -eq "localhost") { $InstalledApps = Get-CimInstance -Namespace "root\cimv2\sms" -Query "select * from SMS_InstalledSoftware" -ErrorAction Stop } else { if($Credential) { $session = New-CimSession -Credential $Credential -ComputerName $ComputerName } else { $session = New-CimSession -ComputerName $ComputerName } $InstalledApps = Get-CimInstance -Namespace "root\cimv2\sms" -Query "select * from SMS_InstalledSoftware" -CimSession $session -ErrorAction Stop Remove-CimSession $session } return $InstalledApps|Select-Object ProductName,Publisher,InstalledLocation,ProductVersion,VersionMajor,VersionMinor,ServicePack,SoftwareCode,UninstallString,LocalPackage,InstallDate } else { Write-Error "The computer you try to manage is offline." -Category ConnectionError } } <# .Synopsis Get applications deployed to the client. .Description You can use this commandlet to check the applications deployed to the client. .Parameter ComputerName The computer you like to target. .Parameter Credential The credentials you like to use to manage the target computer. .Example Get-SCClientApplication Get all applications deployed to the local computer. .Example Get-SCClientApplication -ComputerName "ClientName" -Credential "CredentialObject" Get all applications deployed to the remote computer. #> function Get-SCClientApplication { param( [Parameter(Mandatory=$false)] [string] $ComputerName="localhost", [Parameter(Mandatory=$false)] [pscredential] [System.Management.Automation.Credential()] $Credential ) if($(Test-Connection -ComputerName $ComputerName -Count 1 -BufferSize 10 -Quiet)) { $modulepath = $PSCommandPath.Replace("\SCClient.psm1","") [xml]$XmlEvaluationStates = Get-Content -Path $modulepath\EvaluationStateApps.xml if($ComputerName -eq "localhost") { $applications = Get-CimInstance -Namespace "Root\ccm\ClientSDK" -Query "SELECT * FROM CCM_application" -ErrorAction Stop } else { if($Credential) { $session = New-CimSession -Credential $Credential -ComputerName $ComputerName } else { $session = New-CimSession -ComputerName $ComputerName } $applications = Get-CimInstance -CimSession $session -Namespace "Root\ccm\ClientSDK" -Query "SELECT * FROM CCM_application" -ErrorAction Stop Remove-CimSession $session } foreach($application in $applications) { switch($application.EnforcePreference) { 0{$EnforcePreferenceProp="Immediate"} 1{$EnforcePreferenceProp="NonBusinessHours"} 2{$EnforcePreferenceProp="AdminSchedule"} default{$EnforcePreferenceProp="Unknown"} } foreach($EvaluationState in $($XmlEvaluationStates.states.option)) { if($EvaluationState.value -eq $application.EvaluationState) { $EvaluationStateProp=$EvaluationState.state } } $props = [ordered]@{ Name = $application.Name; Publisher = $application.Publisher; Id = $application.Id; InstallState = $application.InstallState; EvaluationState = $EvaluationStateProp; ResolvedState = $application.ResolvedState; ErrorCode = $application.ErrorCode; ApplicabilityState = $application.ApplicabilityState; EnforcePreference = $EnforcePreferenceProp; ConfigurationState = $application.ConfigurationState; PercentComplete = $application.PercentComplete; AllowedActions = $application.AllowedActions; IsMachineTarget = $application.IsMachineTarget; IsPreflightOnly = $application.IsPreflightOnly; RebootOutsideServiceWindow = $application.RebootOutsideServiceWindow; OverrideServiceWindow = $application.OverrideServiceWindow; StartTime = $application.StartTime; Deadline = $application.Deadline; LastEvalTime = $application.LastEvalTime; LastInstallTime = $application.LastInstallTime; NotifyUser = $application.NotifyUser; UserUIExperience = $application.UserUIExperience; } New-Object -property $props -TypeName psobject } } else { Write-Error "The computer you try to manage is offline." -Category ConnectionError } } <# .Synopsis Get info about last update scan. .Description You can use this commandlet to view details of the last update scan. .Parameter ComputerName The computer you like to target. .Parameter Credential The credentials you like to use to manage the target computer. .Example Get-SCClientUpdateScanHistory Get all Pending updates on the local computer. .Example Get-SCClientUpdateScanHistory -ComputerName "ClientName" -Credential "CredentialObject" Get all Pending updates on the remote computer. #> function Get-SCClientUpdateScanHistory { param( [Parameter(Mandatory=$false)] [string] $ComputerName="localhost", [Parameter(Mandatory=$false)] [pscredential] [System.Management.Automation.Credential()] $Credential ) if($(Test-Connection -ComputerName $ComputerName -Count 1 -BufferSize 10 -Quiet)) { if($ComputerName -eq "localhost") { $ScanHistory = Get-CimInstance -Namespace "root\ccm\scanagent" -Query "SELECT * FROM CCM_scanupdatesourcehistory" -ErrorAction Stop } else { if($Credential) { $session = New-CimSession -Credential $Credential -ComputerName $ComputerName } else { $session = New-CimSession -ComputerName $ComputerName } $ScanHistory = Get-CimInstance -CimSession $session -Namespace "root\ccm\scanagent" -Query "SELECT * FROM CCM_scanupdatesourcehistory" -ErrorAction Stop Remove-CimSession $session } return $ScanHistory|select-Object ScanMethod,Valid,ValidTTL,UpdateSourceID,UpdateSourceVersion,LastCompletionTime } else { Write-Error "The computer you try to manage is offline." -Category ConnectionError } } <# .Synopsis Check for running Windows Update Scan Jobs. .Description You can use this commandlet to check if there are any Windows Update Scan Jobs running. .Parameter ComputerName The computer you like to target. .Parameter Credential The credentials you like to use to manage the target computer. .Example Get-SCClientScanJob Get all Windows Update Scan Jobs on the local computer. .Example Get-SCClientScanJob -ComputerName "ClientName" -Credential "CredentialObject" Get all Windows Update Scan Jobs on the remote computer. #> function Get-SCClientScanJob { param( [Parameter(Mandatory=$false)] [string] $ComputerName="localhost", [Parameter(Mandatory=$false)] [pscredential] [System.Management.Automation.Credential()] $Credential ) if($(Test-Connection -ComputerName $ComputerName -Count 1 -BufferSize 10 -Quiet)) { if($ComputerName -eq "localhost") { $ScanJob = Get-CimInstance -Namespace "root\ccm\scanagent" -Query "SELECT * FROM CCM_ScanJobInstance" -ErrorAction Stop } else { if($Credential) { $session = New-CimSession -Credential $Credential -ComputerName $ComputerName } else { $session = New-CimSession -ComputerName $ComputerName } $ScanJob = Get-CimInstance -CimSession $session -Namespace "root\ccm\scanagent" -Query "SELECT * FROM CCM_ScanJobInstance" -ErrorAction Stop Remove-CimSession $session } return $ScanJob|select-Object ScanUpdateSourceScanMethod,ScanUpdateSourceID,CurrentLocation,Locations,LocationTimeout,CategoryScan,RetryScan,ForcedScan,ScanState,ScanIsClientOnInternet } else { Write-Error "The computer you try to manage is offline." -Category ConnectionError } } <# .Synopsis Install updates .Description You can use this commandlet to install a specific update or all updates. .Parameter ComputerName The computer you like to target. .Parameter Credential The credentials you like to use to manage the target computer. .Example Start-SCClientInstallUpdate -UpdateID "UpdateID" Install an update on the local computer .Example Start-SCClientInstallUpdate Install all update on the local computer .Example Start-SCClientInstallUpdate -ComputerName "ClientName" -Credential "CredentialObject" -UpdateID "UpdateID" Install an update with the specified UpdateID on the target computer .Example Start-SCClientInstallUpdate -ComputerName "ClientName" -Credential "CredentialObject" Install all updates on the target computer #> function Start-SCClientInstallUpdate { param( [Parameter(Mandatory=$false)] [string[]] $ComputerName="localhost", [Parameter(Mandatory=$false)] [pscredential] [System.Management.Automation.Credential()] $Credential, [Parameter(Mandatory=$false)] [string] $UpdateID="%" ) if($(Test-Connection -ComputerName $ComputerName -Count 1 -BufferSize 10 -Quiet)) { if($ComputerName -eq "localhost") { [System.Management.ManagementObject[]] $a = get-WmiObject -query "SELECT * FROM CCM_SoftwareUpdate WHERE UpdateID like '$UpdateID'" -namespace "ROOT\ccm\ClientSDK" -ErrorAction Stop ([wmiclass]'ROOT\ccm\ClientSDK:CCM_SoftwareUpdatesManager').InstallUpdates($a) } else { if($Credential) { Invoke-Command $ComputerName -ScriptBlock{ param ([string] $arg1 = $UpdateID) [System.Management.ManagementObject[]] $a = Get-WmiObject -query "SELECT * FROM CCM_SoftwareUpdate WHERE UpdateID like '$arg1'" -namespace "ROOT\ccm\ClientSDK" -ErrorAction Stop ([wmiclass]'ROOT\ccm\ClientSDK:CCM_SoftwareUpdatesManager').InstallUpdates($a) } -ArgumentList $UpdateID -Credential $Credential } else { Invoke-Command $ComputerName -ScriptBlock{ param ([string] $arg1 = $UpdateID) [System.Management.ManagementObject[]] $a = Get-WmiObject -query "SELECT * FROM CCM_SoftwareUpdate WHERE UpdateID like '$arg1'" -namespace "ROOT\ccm\ClientSDK" -ErrorAction Stop ([wmiclass]'ROOT\ccm\ClientSDK:CCM_SoftwareUpdatesManager').InstallUpdates($a) } -ArgumentList $UpdateID } } } else { Write-Error "The computer you try to manage is offline." -Category ConnectionError } } <# .Synopsis Install updates .Description You can use this commandlet to install a specific update or all updates. .Parameter ComputerName The computer you like to target. .Parameter Credential The credentials you like to use to manage the target computer. .Example Start-SCClientInstallApplication -Id "AppId" Install an application with the specified Application Id on the local computer .Example Start-SCClientInstallApplication -ComputerName "ClientName" -Credential "CredentialObject" -Id "AppId" Install an application with the specified Application Id on the target computer #> function Start-SCClientInstallApplication { param( [Parameter(Mandatory=$false)] [string] $ComputerName="localhost", [Parameter(Mandatory=$false)] [pscredential] [System.Management.Automation.Credential()] $Credential, [Parameter(Mandatory=$true)] [string] $Id ) if($(Test-Connection -ComputerName $ComputerName -Count 1 -BufferSize 10 -Quiet)) { if($ComputerName -eq "localhost") { [System.Management.ManagementObject[]] $a = get-WmiObject -query "SELECT * FROM CCM_Application WHERE Id like '$Id'" -namespace "ROOT\ccm\ClientSDK" -ErrorAction Stop $RELPATH = $a.__RELPATH -split "," if($RELPATH[1].Contains("TRUE")) { $IsMachineTarget = $true } else { $IsMachineTarget = $false } $revision = $RELPATH[2].Substring(10) $revision = $revision.Substring(0,$revision.Length-1) ([wmiclass]'ROOT\ccm\ClientSdk:CCM_Application').Install($Id, $revision, $IsMachineTarget, 0, 'Normal', $False) } else { if($Credential) { Invoke-Command $ComputerName -ScriptBlock{ param ([string] $arg1 = $Id) [System.Management.ManagementObject[]] $a = Get-WmiObject -query "SELECT * FROM CCM_Application WHERE Id like '$arg1'" -namespace "ROOT\ccm\ClientSDK" -ErrorAction Stop $RELPATH = $a.__RELPATH -split "," if($RELPATH[1].Contains("TRUE")) { $IsMachineTarget = $true } else { $IsMachineTarget = $false } $revision = $RELPATH[2].Substring(10) $revision = $revision.Substring(0,$revision.Length-1) ([wmiclass]'ROOT\ccm\ClientSdk:CCM_Application').Install($arg1, $revision, $IsMachineTarget, 0, 'Normal', $False) } -ArgumentList $Id -Credential $Credential } else { Invoke-Command $ComputerName -ScriptBlock{ param ([string] $arg1 = $Id) [System.Management.ManagementObject[]] $a = Get-WmiObject -query "SELECT * FROM CCM_Application WHERE Id like '$arg1'" -namespace "ROOT\ccm\ClientSDK" -ErrorAction Stop $RELPATH = $a.__RELPATH -split "," if($RELPATH[1].Contains("TRUE")) { $IsMachineTarget = $true } else { $IsMachineTarget = $false } $revision = $RELPATH[2].Substring(10) $revision = $revision.Substring(0,$revision.Length-1) ([wmiclass]'ROOT\ccm\ClientSdk:CCM_Application').Install($arg1, $revision, $IsMachineTarget, 0, 'Normal', $False) } -ArgumentList $Id } } } else { Write-Error "The computer you try to manage is offline." -Category ConnectionError } } <# .Synopsis Start a Software Updates Assignments Evaluation Cycle .Description You can use this commandlet to start a Software Updates Assignments Evaluation Cycle or Software Update Deployment Evaluation Cycle .Parameter ComputerName The computer you like to target. .Parameter Credential The credentials you like to use to manage the target computer. .Example Start-SCClientUpdateDeploymentEval Start Software Updates Assignments Evaluation Cycle on the local computer .Example Start-SCClientUpdateDeploymentEval -ComputerName "ClientName" -Credential "CredentialObject" Start Software Updates Assignments Evaluation Cycle on the remote computer #> function Start-SCClientUpdateDeploymentEval { param( [Parameter(Mandatory=$false)] [string] $ComputerName="localhost", [Parameter(Mandatory=$false)] [pscredential] [System.Management.Automation.Credential()] $Credential ) if($(Test-Connection -ComputerName $ComputerName -Count 1 -BufferSize 10 -Quiet)) { if($ComputerName -eq "localhost") { ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000108}') } else { if($Credential) { Invoke-Command $ComputerName -ScriptBlock{ ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000108}') } -Credential $Credential } else { Invoke-Command $ComputerName -ScriptBlock{ ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000108}') } } } } else { Write-Error "The computer you try to manage is offline." -Category ConnectionError } } <# .Synopsis Start a Software Update Scan Cycle .Description You can use this commandlet to start a Software Update Scan Cycle .Parameter ComputerName The computer you like to target. .Parameter Credential The credentials you like to use to manage the target computer. .Example Start-SCClientUpdateScan Start Software Update Scan Cycle on the local computer .Example Start-SCClientUpdateScan -ComputerName "ClientName" -Credential "CredentialObject" Start Software Update Scan Cycle on the remote computer #> function Start-SCClientUpdateScan { param( [Parameter(Mandatory=$false)] [string] $ComputerName="localhost", [Parameter(Mandatory=$false)] [pscredential] [System.Management.Automation.Credential()] $Credential ) if($(Test-Connection -ComputerName $ComputerName -Count 1 -BufferSize 10 -Quiet)) { if($ComputerName -eq "localhost") { ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000113}') } else { if($Credential) { Invoke-Command $ComputerName -ScriptBlock{ ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000113}') } -Credential $Credential } else { Invoke-Command $ComputerName -ScriptBlock{ ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000113}') } } } } else { Write-Error "The computer you try to manage is offline." -Category ConnectionError } } <# .Synopsis Start a Machine Policy Retrieval and Evaluation Cycle. .Description You can use this commandlet to start a Machine Policy Retrieval and Evaluation Cycle. .Parameter ComputerName The computer you like to target. .Parameter Credential The credentials you like to use to manage the target computer. .Example Start-SCClientMachinePolicyEval Start Machine Policy Retrieval and Evaluation Cycle on the local computer .Example Start-SCClientMachinePolicyEval -ComputerName "ClientName" -Credential "CredentialObject" Start Machine Policy Retrieval and Evaluation Cycle on the remote computer #> function Start-SCClientMachinePolicyEval { param( [Parameter(Mandatory=$false)] [string] $ComputerName="localhost", [Parameter(Mandatory=$false)] [pscredential] [System.Management.Automation.Credential()] $Credential ) if($(Test-Connection -ComputerName $ComputerName -Count 1 -BufferSize 10 -Quiet)) { if($ComputerName -eq "localhost") { ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000021}') ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000022}') } else { if($Credential) { Invoke-Command $ComputerName -ScriptBlock{ ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000021}') ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000022}') } -Credential $Credential } else { Invoke-Command $ComputerName -ScriptBlock{ ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000021}') ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000022}') } } } } else { Write-Error "The computer you try to manage is offline." -Category ConnectionError } } <# .Synopsis Start a Application Deployment Evaluation Cycle. .Description You can use this commandlet to start a Application Deployment Evaluation Cycle. .Parameter ComputerName The computer you like to target. .Parameter Credential The credentials you like to use to manage the target computer. .Example Start-SCClientApplicationEval Start Application Deployment Evaluation Cycle on the local computer .Example Start-SCClientApplicationEval -ComputerName "ClientName" -Credential "CredentialObject" Start Application Deployment Evaluation Cycle on the remote computer #> function Start-SCClientApplicationEval { param( [Parameter(Mandatory=$false)] [string] $ComputerName="localhost", [Parameter(Mandatory=$false)] [pscredential] [System.Management.Automation.Credential()] $Credential ) if($(Test-Connection -ComputerName $ComputerName -Count 1 -BufferSize 10 -Quiet)) { if($ComputerName -eq "localhost") { ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000121}') } else { if($Credential) { Invoke-Command $ComputerName -ScriptBlock{ ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000121}') } -Credential $Credential } else { Invoke-Command $ComputerName -ScriptBlock{ ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000121}') } } } } else { Write-Error "The computer you try to manage is offline." -Category ConnectionError } } <# .Synopsis Start a Client Repair. .Description You can use this commandlet to start a Client Repair. .Parameter ComputerName The computer you like to target. .Parameter Credential The credentials you like to use to manage the target computer. .Example Start-SCClientRepair Repair the client on the local computer .Example Start-SCClientRepair -ComputerName "ClientName" -Credential "CredentialObject" Repair the client on the remote computer #> function Start-SCClientRepair { param( [Parameter(Mandatory=$false)] [string] $ComputerName="localhost", [Parameter(Mandatory=$false)] [pscredential] [System.Management.Automation.Credential()] $Credential ) if($(Test-Connection -ComputerName $ComputerName -Count 1 -BufferSize 10 -Quiet)) { if($ComputerName -eq "localhost") { ([wmiclass]'ROOT\ccm:SMS_Client').RepairClient() } else { if($Credential) { Invoke-Command $ComputerName -ScriptBlock{ ([wmiclass]'ROOT\ccm:SMS_Client').RepairClient() } -Credential $Credential } else { Invoke-Command $ComputerName -ScriptBlock{ ([wmiclass]'ROOT\ccm:SMS_Client').RepairClient() } } } } else { Write-Error "The computer you try to manage is offline." -Category ConnectionError } } <# .Synopsis Reset the Machine Policy. .Description You can use this commandlet to reset the Client Policy. .Parameter ComputerName The computer you like to target. .Parameter Credential The credentials you like to use to manage the target computer. .Example Start-SCClientResetMachinePolicy Reset the Machine Policy on the local computer .Example Start-SCClientResetMachinePolicy -ComputerName "ClientName" -Credential "CredentialObject" Reset the Machine Policy on the remote computer #> function Start-SCClientResetMachinePolicy { param( [Parameter(Mandatory=$false)] [string] $ComputerName="localhost", [Parameter(Mandatory=$false)] [pscredential] [System.Management.Automation.Credential()] $Credential ) if($(Test-Connection -ComputerName $ComputerName -Count 1 -BufferSize 10 -Quiet)) { if($ComputerName -eq "localhost") { ([wmiclass]'ROOT\ccm:SMS_Client').ResetPolicy(0) ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000040}') ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000021}') } else { if($Credential) { Invoke-Command $ComputerName -ScriptBlock{ ([wmiclass]'ROOT\ccm:SMS_Client').ResetPolicy(0) ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000040}') ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000021}') } -Credential $Credential } else { Invoke-Command $ComputerName -ScriptBlock{ ([wmiclass]'ROOT\ccm:SMS_Client').ResetPolicy(0) ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000040}') ([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule('{00000000-0000-0000-0000-000000000021}') } } } } else { Write-Error "The computer you try to manage is offline." -Category ConnectionError } } |