I am trying to build a tool to stop and restart services on remote computers, but I want to choose a specific service. I can't get the $Service parameter to pass to the command.
Any Ideas?
function Restart-rService {
[CmdletBinding()]
Param(
[Parameter()]
[string[]]$computername = "loclhost",
$Credential = (Get-Credential -UserName 'dom\User01'-Message "Any Service Remote"),
[string]$Service = ''
)
$command = { Restart-Service -name }
Invoke-Command -ComputerName $computername -Credential $Credential -ScriptBlock $command -ArgumentList $Service
}
Restart-rService -computername tserver -service 'DHCP'
Missing an argument for parameter 'Name'. Specify a parameter of type 'System.String[]' and try again.
+ CategoryInfo : InvalidArgument: (:) [Restart-Service], ParameterBindingException
+ FullyQualifiedErrorId : MissingArgument,Microsoft.PowerShell.Commands.RestartServiceCommand
+ PSComputerName : tserver