Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/Microsoft.WSMan.Management/ConfigProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public sealed partial class WSManConfigProvider : NavigationCmdletProvider, ICmd
//Plugin Name Storage
private PSObject objPluginNames = null;

private ServiceController winrmServiceController;

/// <summary>
/// Determines if Set-Item user input type validation is required or not.
/// It is True by default, Clear-Item will set it to false so that it can
Expand Down Expand Up @@ -4436,15 +4438,16 @@ private void AssertError(string ErrorMessage, bool IsWSManError)
/// <returns></returns>
private bool IsWSManServiceRunning()
{
ServiceController svc = new ServiceController("WinRM");
if (svc != null)
if (winrmServiceController == null)
{
if (svc.Status.Equals(ServiceControllerStatus.Running))
{
return true;
}
winrmServiceController = new ServiceController("WinRM");
}
return false;
else
{
winrmServiceController.Refresh();
}

return (winrmServiceController.Status.Equals(ServiceControllerStatus.Running));
}

/// <summary>
Expand Down