-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Remove '-ComputerName' from 'Get/Set/Remove-Service' #5094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
It's easier to review the changes after ignoring whitespaces: https://github.com/PowerShell/PowerShell/pull/5094/files?w=1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| NativeMethods.SERVICE_CONFIG_DESCRIPTION, | ||
| buffer); | ||
| // If '-Status' parameter is specified, do the necessary action to bring about the desired result | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not like this comment. It says if -Status, do something to get what you want. Can we be more specific or remove this comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will change it to // Handle '-Status' parameter.
| //stop service,give the force parameter always true as we have already checked for the dependent services | ||
| //Specify NoWait parameter as always false since we are not adding this switch to this cmdlet | ||
| DoStopService(service, true, true); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are touching the code here, can we use named parameters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
| WriteObject(displayservice); | ||
| if (!service.Status.Equals(ServiceControllerStatus.Paused)) | ||
| //pause service | ||
| DoPauseService(service); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't change this one. I will remove it.
| bool objServiceShouldBeDisposed = false; | ||
| try | ||
| if (InputObject != null) | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code looks very similar to line 1485. Can we refactor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are from two different cmdlets: Set-Service (line 1485) and Remove-Service (2083)
|
@adityapatwardhan Your comments are addressed. Can you please take another look? |
| ServiceCommandException exception = | ||
| new ServiceCommandException(message, innerException); | ||
| exception.ServiceName = serviceName; | ||
| (null == innerException) ? "" : innerException.Message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use String.Empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please clarify for me: I found many "*" strings in cs files - should we create a constant for it?
| foreach (ServiceController service in OneService(pattern)) | ||
| ServiceController service = GetOneService(pattern); | ||
| if (service != null) | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems GetOneService() never return null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the service doesn't exist, accessing sc.Status; will throw InvalidOperationException. In that case the method will catch the exception and return null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Closed.
Fix #5090
Remove '-ComputerName' from 'Get/Set/Remove-Service'