About_Remote_Troubleshooting, invoke-command, WinRM and many recommended documentation pages have been queried, and I have also searched stackoverflow and found no solution.
You can use Get-WindowsCapability to query normally, use Remove-WindowsCapability to uninstall normally, but use Add-WindowsCapability to add an error (prompt to deny access).
Using admin and domain admin accounts has the same result, looks like a permissions issue, but don't know where to set it.
I tried to use the command to write the .ps1 file (only add one line: Add-WindowsCapability -Online -Name "SNMP.Client~~~~0.0.1.0") and point to it to run, or use the dism command directly to report the same error, you can Seeing that the command start does start, it's just interrupted.
I tried to copy the .ps1 to the remote machine again, and it was normal to open it in the powershell window of the remote machine, but it started to report the same error when I opened it through invoke-command.
The command I entered:
21 Invoke-Command -Session $s -ScriptBlock {Get-WindowsCapability -Online -Name "SNMP.Client~~~~0.0.1.0"}
22 Invoke-Command -Session $s -ScriptBlock {Add-WindowsCapability -Online -Name "SNMP.Client~~~~0.0.1.0"}
23 Invoke-Command -Session $s -ScriptBlock {DISM /online /add-Capability /CapabilityName:SNMP.Client~~~~0.0.1.0}
24 Invoke-Command -Session $s -FilePath C:\Users\Vincent\Desktop\无标题1.ps1
25 Invoke-Command -Session $s -ScriptBlock {C:\Users\Administrator\Desktop\无标题1.ps1}
26 Invoke-Command -Session $s -ScriptBlock {C:\Users\Administrator\Desktop\无标题1.ps1}
The errors found in the log file of dism are as follows, but the specific meaning and how to solve them are not clear.
2022-03-19 21:26:30, Warning DISM DISM Provider Store: PID=4912 TID=4944 Failed to load the provider: DISM DISM Package Manager: PID=3436 TID=10268 Error in operation: (null) (CBS HRESULT=0x80070005) - CCbsConUIHandler::Error
2022-03-19 21:26:34, Error DISM DISM Package Manager: PID=3436 TID=432 Failed finalizing changes. - CDISMPackageManager::Internal_Finalize(hr:0x80070005)
2022-03-19 21:26:34, Error DISM DISM Package Manager: PID=3436 TID=432 Failed processing package changes with session options - CDISMPackageManager::ProcessChangesWithOptions(hr:0x80070005)
2022-03-19 21:26:34, Error DISM API: PID=4912 TID=4944 Failed to install capability. - CAddCapabilityCommandObject::InternalExecute(hr:0x80070005)
2022-03-19 21:26:34, Error DISM API: PID=4912 TID=4944 InternalExecute failed - CBaseCommandObject::Execute(hr:0x80070005)
2022-03-19 21:26:34, Error DISM API: PID=4912 TID=11148 CAddCapabilityCommandObject internal execution failed - DismAddCapabilityInternal(hr:0x80070005)
Whether invoke-command does not support adding functions, how does Windows remote management add functions to remote computers?