0

I am running below script on my system to perform all sccm client actions trigger and getting below error.

Run-SCCMClientAction : Connecting to remote server DD4 failed with the following error message : The WS-Management service cannot process the request. The service is 
configured to not accept any remote shell requests. For more information, see the about_Remote_Troubleshooting Help topic.
At line:60 char:2
+  Run-SCCMClientAction -Computername $env:COMPUTERNAME -ClientAction A ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Run-SCCMClientAction
Function Run-SCCMClientAction {
        [CmdletBinding()]
                
        # Parameters used in this function
        param
        ( 
            [Parameter(Position=0, Mandatory = $True, HelpMessage="Provide PC names", ValueFromPipeline = $true)] 
            [string[]]$Computername,
 
           [ValidateSet('MachinePolicy', 
                        'DiscoveryData', 
                        'ComplianceEvaluation', 
                        'AppDeployment',  
                        'HardwareInventory', 
                        'UpdateDeployment', 
                        'UpdateScan', 
                        'SoftwareInventory')] 
            [string[]]$ClientAction
   
        ) 
        $ActionResults = @()
        Try { 
                $ActionResults = Invoke-Command -ComputerName $Computername {param($ClientAction)
 
                        Foreach ($Item in $ClientAction) {
                            $Object = @{} | select "Action name",Status
                            Try{
                                $ScheduleIDMappings = @{ 
                                    'MachinePolicy'        = '{00000000-0000-0000-0000-000000000021}'; 
                                    'DiscoveryData'        = '{00000000-0000-0000-0000-000000000003}'; 
                                    'ComplianceEvaluation' = '{00000000-0000-0000-0000-000000000071}'; 
                                    'AppDeployment'        = '{00000000-0000-0000-0000-000000000121}'; 
                                    'HardwareInventory'    = '{00000000-0000-0000-0000-000000000001}'; 
                                    'UpdateDeployment'     = '{00000000-0000-0000-0000-000000000108}'; 
                                    'UpdateScan'           = '{00000000-0000-0000-0000-000000000113}'; 
                                    'SoftwareInventory'    = '{00000000-0000-0000-0000-000000000002}'; 
                                }
                                $ScheduleID = $ScheduleIDMappings[$item]
                                Write-Verbose "Processing $Item - $ScheduleID"
                                [void]([wmiclass] "root\ccm:SMS_Client").TriggerSchedule($ScheduleID);
                                $Status = "Success"
                                Write-Verbose "Operation status - $status"
                            }
                            Catch{
                                $Status = "Failed"
                                Write-Verbose "Operation status - $status"
                            }
                            $Object."Action name" = $item
                            $Object.Status = $Status
                            $Object
                        }
 
            } -ArgumentList $ClientAction -ErrorAction Stop | Select-Object @{n='PCName';e={$_.pscomputername}},"Action name",Status
        }  
        Catch{
            Write-Error $_.Exception.Message 
        }   
        Return $ActionResults           
 }
 Run-SCCMClientAction -Computername $env:COMPUTERNAME -ClientAction AppDeployment
3
  • The machine(s) the actions are run against need to allow PS Remoting. For a simple test, pick one system, run on it this PowerShell Enable-PSRemoting -Force; and then try to run the remote SCCM stuff against it. If that works, that's what you need. Look into setting GPOs to configure on lots of machines/servers at large scale. Otherwise, you might to ensure there are no restriction set based on IP subnet(s), etc. in another configuration hopefully the command and your testing you get lucky and that's the solution. Let me know how it goes. Commented Nov 19, 2022 at 4:15
  • @VomitIT-ChunkyMessStyle Can't we run this script without enabling PSRemoting. RDP is not enabled. And I want every user to run this script on their systems.
    – Suraj
    Commented Nov 19, 2022 at 4:34
  • Not per Try{} command $ActionResults = Invoke-Command -ComputerName $Computername because Invoke-Command needs to be able to remotely access PowerShell as far as I know. Commented Nov 19, 2022 at 4:41

1 Answer 1

0

To run the script, simply make it part of a configuration item and add it to a baseline. Deploy the baseline to the collection where you want the script to run. Once done, the client will download a copy of the script and execute it.

That being said, also make sure that you have configured your client settings properly as you shouldn't really need to force these actions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .