Skip to content

Commit f687702

Browse files
kvprasoonadityapatwardhan
authored andcommitted
Fix wrong output for New-Service in variable assignment and -OutVariable (PowerShell#10444)
1 parent 42b599d commit f687702

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Microsoft.PowerShell.Commands.Management/commands/management/Service.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,11 +2274,8 @@ protected override void BeginProcessing()
22742274
}
22752275

22762276
// write the ServiceController for the new service
2277-
using (ServiceController service =
2278-
new ServiceController(Name)) // ensure dispose
2279-
{
2280-
WriteObject(service);
2281-
}
2277+
ServiceController service = new ServiceController(Name);
2278+
WriteObject(service);
22822279
}
22832280
finally
22842281
{

test/powershell/Modules/Microsoft.PowerShell.Management/Set-Service.Tests.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ Describe "Set/New/Remove-Service cmdlet tests" -Tags "Feature", "RequireAdminOnW
214214
}
215215
$service = New-Service @parameters
216216
$service | Should -Not -BeNullOrEmpty
217+
$service.displayname | Should -Be $(if($displayname){$displayname}else{$name})
218+
$service.startType | Should -Be $startupType
219+
217220
$service = Get-CimInstance Win32_Service -Filter "name='$name'"
218221
$service | Should -Not -BeNullOrEmpty
219222
$service.Name | Should -Be $name

0 commit comments

Comments
 (0)