Hi people mi need help
I am try create a script of stop services with variable values, as down my script:
Clear-Host
$serviceList=gc servicos.txt
foreach ($service in $serviceList)
{
$service=$service-split(',')
$first=$service[0]
$second=$service[1]
$third=$service[2]
echo $first
Get-Service -InputObject $first | Start-Service
echo $second
Get-Service -InputObject $second | Start-Service
echo $third
Get-Service -InputObject $third | Start-Service
}
I get an error over the service ends successfully
et-Service : Cannot bind parameter 'InputObject'. Cannot convert value "" to type "System.ServiceProcess.ServiceController".
Error: "Invalid value for parameter name."
At line:10 char:26
+ Get-Service -InputObject $first | Start-Service
+ ~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-Service], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetServiceCommand
Get-Service : Cannot validate argument on parameter 'InputObject'. The argument is null or empty. Provide an argument that is
not null or empty, and then try the command again.
At line:12 char:26
+ Get-Service -InputObject $second | Start-Service
+ ~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-Service], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetServiceCommand
Get-Service : Cannot validate argument on parameter 'InputObject'. The argument is null or empty. Provide an argument that is
not null or empty, and then try the command again.
At line:14 char:26
+ Get-Service -InputObject $third | Start-Service
+ ~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-Service], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetServiceCommand