-
Notifications
You must be signed in to change notification settings - Fork 8.1k
[Feature]Added Remove-service to Management module #4858
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
fb73312
[Feature]Remove-Service added to Management module
joandrsn 32759f4
[Feature]Capitalization
joandrsn 072582f
[Feature]Added test cases for Remove-Service, Removed return value
joandrsn 1349f60
[Feature]Documentation from copy-paste code corrected to reflect the …
joandrsn b1c7e4d
[Feature]Erroraction to be sure that an error is thrown in testcase
joandrsn 17c4d4a
[Feature]Removed direct reference to module in Pester test
joandrsn 2585dbe
[Feature]Removed extra line in test
joandrsn b56dba9
[Feature]Use FullyQualifiedErrorId in Remove-Service test without a v…
joandrsn c519a9a
[Feature]Exposed Remove-Service
joandrsn cb2ee47
[Feature]Consistent casing, Named Arguments & Remove incorrect except…
joandrsn 2d7e000
[Feature]Remove-Service test should fail if the service was not removed
joandrsn 4ffd2c0
[Feature]Cleanup comments & add Remove-Service for CI
joandrsn 2fcf55e
[Feature]Remove-Service in CI set in alphabetic order
joandrsn da41f7d
[Feature]Use ParameterSetName instead of _ParameterSetName and rewrit…
joandrsn 6753840
Revert "[Feature]Use ParameterSetName instead of _ParameterSetName an…
joandrsn 427bc7d
[Feature]Remove _ParameterSetName check & added test for pipeline inp…
joandrsn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| Describe "Set/New-Service cmdlet tests" -Tags "Feature", "RequireAdminOnWindows" { | ||
| Describe "Set/New/Remove-Service cmdlet tests" -Tags "Feature", "RequireAdminOnWindows" { | ||
| BeforeAll { | ||
| $originalDefaultParameterValues = $PSDefaultParameterValues.Clone() | ||
| if ( -not $IsWindows ) { | ||
|
|
@@ -195,6 +195,65 @@ Describe "Set/New-Service cmdlet tests" -Tags "Feature", "RequireAdminOnWindows" | |
| } | ||
| } | ||
|
|
||
| It "Remove-Service can remove a service" { | ||
| try { | ||
| $servicename = "testremoveservice" | ||
| $parameters = @{ | ||
| Name = $servicename; | ||
| BinaryPathName = "$PSHOME\powershell.exe" | ||
| } | ||
| $service = New-Service @parameters | ||
| $service | Should Not BeNullOrEmpty | ||
| Remove-Service -Name $servicename | ||
| $service = Get-Service -Name $servicename -ErrorAction SilentlyContinue | ||
| $service | Should BeNullOrEmpty | ||
| } | ||
| finally { | ||
| Get-CimInstance Win32_Service -Filter "name='$servicename'" | Remove-CimInstance -ErrorAction SilentlyContinue | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also add tests which validates the error cases?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also add tests for pipeline input. |
||
|
|
||
| It "Remove-Service can accept pipeline input of a ServiceController" { | ||
| try { | ||
| $servicename = "testremoveservice" | ||
| $parameters = @{ | ||
| Name = $servicename; | ||
| BinaryPathName = "$PSHOME\powershell.exe" | ||
| } | ||
| $service = New-Service @parameters | ||
| $service | Should Not BeNullOrEmpty | ||
| Get-Service -Name $servicename | Remove-Service | ||
| $service = Get-Service -Name $servicename -ErrorAction SilentlyContinue | ||
| $service | Should BeNullOrEmpty | ||
| } | ||
| finally { | ||
| Get-CimInstance Win32_Service -Filter "name='$servicename'" | Remove-CimInstance -ErrorAction SilentlyContinue | ||
| } | ||
| } | ||
|
|
||
| It "Remove-Service cannot accept a service that does not exist" { | ||
| { Remove-Service -Name "testremoveservice" -ErrorAction 'Stop' } | ShouldBeErrorId "InvalidOperationException,Microsoft.PowerShell.Commands.RemoveServiceCommand" | ||
| } | ||
|
|
||
| It "Set-Service can accept pipeline input of a ServiceController" { | ||
| try { | ||
| $servicename = "testsetservice" | ||
| $newdisplayname = "newdisplayname" | ||
| $parameters = @{ | ||
| Name = $servicename; | ||
| BinaryPathName = "$PSHOME\powershell.exe" | ||
| } | ||
| $service = New-Service @parameters | ||
| $service | Should Not BeNullOrEmpty | ||
| Get-Service -Name $servicename | Set-Service -DisplayName $newdisplayname | ||
| $service = Get-Service -Name $servicename | ||
| $service.DisplayName | Should BeExactly $newdisplayname | ||
| } | ||
| finally { | ||
| Get-CimInstance Win32_Service -Filter "name='$servicename'" | Remove-CimInstance -ErrorAction SilentlyContinue | ||
| } | ||
| } | ||
|
|
||
| It "Using bad parameters will fail for '<name>' where '<parameter>' = '<value>'" -TestCases @( | ||
| @{cmdlet="New-Service"; name = 'credtest' ; parameter = "Credential" ; value = ( | ||
| [System.Management.Automation.PSCredential]::new("username", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
same as above, perhaps just an assert?