Test-Connection : Provider load failure Error

Hello Everyone,

I got some help here before so I thought I’d try it out again 🙂

I’m trying to create a script that will:

Check if the PC is online -if online, check if winmgmt is running. -If running, stop the winmgmt service and delete some folders.

********This is as far as I’ve gotten**********

Then restart winmgmt service and reboot.

This is what I’ve written so far. I did it in steps. 1st making sure I could input a computer name. Then, testing the connection. Then checking if winmgmt is running. After that if it’s running it will stop the service.

$Server = Read-Host -Prompt "Input your server name" if (Test-Connection -ComputerName $Server -Quiet -Count 1) { } elseif ((Get-Service -Name "winmgmt" -ComputerName $Server).status -eq "running") {(Get-Service -Name "winmgmt" -ComputerName $Server).stop() Get-ChildItem \$ServerC$WindowsSystem32wbem* -Filter *Repository* | Remove-Item -Force -Recurse } 

It wasn’t until I added the: Get-ChildItem $ServerC$WindowsSystem32wbem* -Filter Repository | Remove-Item -Force -Recurse that I got the error.

Other than this error, the script appears to be working as planned. The winmgmt service is stopped and the correct folders deleted.

“Test-Connection : Provider load failure At C:UsersUSERDesktop_Colorado Powershell IdeaUntitled4.ps1:8 char:5 + if (Test-Connection -ComputerName $Server -Quiet -Count 1) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Test-Connection], ManagementException + FullyQualifiedErrorId : TestConnectionException,Microsoft.PowerShell.Commands.TestCo nnectionCommand”

Any ideas as to why I’m getting this? I’m still googling for answers but nothing I’ve found so far appears to be the correct solution.

submitted by /u/nUmbdA
[link] [comments]

Leave a Reply