我有一个脚本,我正在批处理文件中运行脚本来启动服务,要求用户启动服务传递服务所需的用户名和密码。出现一个输入框,我可以输入凭据。
$srvName = Get-Service | Where-Object { $_.ServiceName -like ‘myService’ }
Start-Service net -arg $srvName -Credential (Get-Credential)Out-File C:\a.txt
但是,服务无法启动,在我的outfile中,我收到以下错误。
CategoryInfo : InvalidArgument: (:) [Start-Service], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.StartServiceCommand
当我看,我发现很多使用Powershell设置服务凭据的例子,但只有一个用于做我想做的事情,但显然不起作用。
您需要将其传输到out-file
$srvName = Get-Service | Where-Object { $_.ServiceName -like ‘myService’ }
Start-Service $srvName -Credential (Get-Credential) | Out-File C:\a.txt
错误发布状态InvalidArgument: (:)
因为它将Out-File C:\a.txt
解释为Start-Service
的参数因此InvalidArgument
。
此外,启动服务没有-arg
参数,我不知道net
是什么。