如何使用Powershell创建服务名

时间:2019-04-23 14:09:54

标签: powershell

我试图创建一个服务名,当我转到“ service.msc”时,powershell脚本无法创建。

我尝试了以下代码,但无法创建服务。我正在以“管理员”身份运行

$serviceName="RSCDsvc"
$serviceDisplayName="BMC BladeLogic Server Automation RSCD Agent"
$serviceDescription="BMC BladeLogic Server Automation Remote System Call Daemon"
$serviceExecutable="RSCDsvc.exe"

LogWrite $bsaLog "Installing service.."


$binaryPath="C:\Program Files\BMC Software\BladeLogic\RSCD\RSCDsvc.exe"

New-Service -name $serviceName -DisplayName $serviceDisplayName -binaryPathName $binaryPath -StartupType Automatic -Description $serviceDescription 

Start-Service -Name $serviceName
Get-Service $serviceName

LogWrite $bsaLog "Service Installed.."

当我键入“ services.msc”时,我想查看服务名称。我应该能够看到显示为“ BMC Bladelogic Server Automation RSCD代理”的“ RSCDsvc”

当我分别在Powershell提示符中运行这些命令时,出现以下错误,当我进入taskmanager并转到“详细信息”选项卡时,可以看到该服务正在运行,但是当我进入“ services.msc“

New-Service : Service 'BMC BladeLogic Server Automation RSCD Agent (RSCDsvc)' cannot be created due to the following error: The 
specified service already exists
At line:1 char:1
+ New-Service -name $serviceName -DisplayName $serviceDisplayName -bina ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (RSCDsvc:String) [New-Service], ServiceCommandException
    + FullyQualifiedErrorId : CouldNotNewService,Microsoft.PowerShell.Commands.NewServiceCommand

0 个答案:

没有答案