Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ public class SetServiceCommand : ServiceOperationBaseCommand
/// service name
/// </summary>
/// <value></value>
[Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ParameterSetName = "Name")]
[Parameter(Mandatory = true, ParameterSetName = "Name", Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
[Alias("ServiceName", "SN")]
public new String Name
{
Expand All @@ -1448,6 +1448,14 @@ public class SetServiceCommand : ServiceOperationBaseCommand
}
internal String serviceName = null;

/// <summary>
/// The following is the definition of the input parameter "InputObject".
/// Specifies a ServiceController object that represents the service to change.
/// Enter a variable that contains the objects or type a command or expression
/// that gets the objects.
/// </summary>
[Parameter(Mandatory = true, ParameterSetName = "InputObject", Position = 0, ValueFromPipeline = true)]
public new ServiceController InputObject { get; set; }

/// <summary>
/// The following is the definition of the input parameter "DisplayName".
Expand Down Expand Up @@ -1539,16 +1547,6 @@ public string Status
}
internal string serviceStatus = null;

/// <summary>
/// The following is the definition of the input parameter "InputObject".
/// Specifies ServiceController object representing the services to be stopped.
/// Enter a variable that contains the objects or type a command or expression
/// that gets the objects.
/// </summary>
[Parameter(ValueFromPipeline = true,
ParameterSetName = "InputObject")]
public new ServiceController InputObject { get; set; }

/// <summary>
/// This is not a parameter for this cmdlet.
/// </summary>
Expand Down Expand Up @@ -1688,7 +1686,7 @@ protected override void ProcessRecord()

// Modify startup type or display name or credential
if (!String.IsNullOrEmpty(DisplayName)
|| (ServiceStartMode)(-1) != StartupType || null != Credential)
|| (ServiceStartMode)(-1) != StartupType || null != Credential)
{
DWORD dwStartType = NativeMethods.SERVICE_NO_CHANGE;
if (!NativeMethods.TryGetNativeStartupType(StartupType, out dwStartType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Describe "Set/New/Remove-Service cmdlet tests" -Tags "Feature", "RequireAdminOnW
@{parameter = "StartupType" ; value = "Manual"},
@{parameter = "StartupType" ; value = "System"},
@{parameter = "Credential" ; value = (
[System.Management.Automation.PSCredential]::new("username",
[System.Management.Automation.PSCredential]::new("username",
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Demo/doc/test secret.")]
(ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force)))
}
Expand Down Expand Up @@ -214,7 +214,7 @@ Describe "Set/New/Remove-Service cmdlet tests" -Tags "Feature", "RequireAdminOnW
}
}

It "Remove-Service can accept pipeline input of a ServiceController" {
It "Remove-Service can accept a ServiceController as pipeline input" {
try {
$servicename = "testremoveservice"
$parameters = @{
Expand All @@ -236,7 +236,7 @@ Describe "Set/New/Remove-Service cmdlet tests" -Tags "Feature", "RequireAdminOnW
{ Remove-Service -Name "testremoveservice" -ErrorAction 'Stop' } | ShouldBeErrorId "InvalidOperationException,Microsoft.PowerShell.Commands.RemoveServiceCommand"
}

It "Set-Service can accept pipeline input of a ServiceController" {
It "Set-Service can accept a ServiceController as pipeline input" {
try {
$servicename = "testsetservice"
$newdisplayname = "newdisplayname"
Expand All @@ -255,9 +255,29 @@ Describe "Set/New/Remove-Service cmdlet tests" -Tags "Feature", "RequireAdminOnW
}
}

It "Set-Service can accept a ServiceController as positional input" {
try {
$servicename = "testsetservice"
$newdisplayname = "newdisplayname"
$parameters = @{
Name = $servicename;
BinaryPathName = "$PSHOME\powershell.exe"
}
$service = New-Service @parameters
$service | Should Not BeNullOrEmpty
$script = { Set-Service $service -DisplayName $newdisplayname }
{ & $script } | Should Not Throw
$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",
[System.Management.Automation.PSCredential]::new("username",
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Demo/doc/test secret.")]
(ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force)));
errorid = "CouldNotNewService,Microsoft.PowerShell.Commands.NewServiceCommand"},
Expand All @@ -271,7 +291,7 @@ Describe "Set/New/Remove-Service cmdlet tests" -Tags "Feature", "RequireAdminOnW
param($cmdlet, $name, $parameter, $value, $errorid)
$parameters = @{$parameter = $value; Name = $name; ErrorAction = "Stop"}
if ($cmdlet -eq "New-Service") {
$parameters += @{Binary = "$PSHOME\powershell.exe"};
$parameters += @{Binary = "$PSHOME\powershell.exe"};
}
{ & $cmdlet @parameters } | ShouldBeErrorId $errorid
}
Expand Down