我能够使用其作为管理员帐户的凭据登录VM,但是在PowerShell脚本中尝试相同的凭据时出现错误
首先在Admin模式下的PowerShell中执行以下功能,然后尝试使用以下命令创建API应用程序的服务
create-service -Name TransientStoreAPI -DisplayName TransientStoreAPI -Description API -Exe C:\xxx\xxx.xxx.xxx.WebAPIServices.exe -User TransientStoreApi11
function create-service
{
param(
[Parameter(mandatory=$true)]
[string]
$Name,
[Parameter(mandatory=$true)]
[string]
$DisplayName,
[Parameter(mandatory=$true)]
[string]
$Description,
[Parameter(mandatory=$true)]
[System.IO.FileInfo]
$Exe,
[Parameter(mandatory=$true)]
[string]
$User
)
$acl = Get-Acl $($Exe.DirectoryName)
$aclRuleArgs = $User, "Read,Write,ReadAndExecute", "ContainerInherit,ObjectInherit", "None", "Allow"
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($aclRuleArgs)
$acl.SetAccessRule($accessRule)
$acl | Set-Acl $($Exe.DirectoryName)
New-Service -Name $Name -BinaryPathName $($Exe.FullName) -Credential $User -Description $Description -DisplayName $DisplayName -StartupType Automatic
}
预期-用户应该能够为API应用创建服务
虚拟机获取错误的实际结果为
New-Service : Service 'TransientStoreAPI (TransientStoreAPI)' cannot be created due to the following error: The account name is
invalid or does not exist, or the password is invalid for the account name specified
At line:6 char:1
+ New-Service -Name $Name -BinaryPathName $Exe -Credential $User -Descr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (TransientStoreAPI:String) [New-Service], ServiceCommandException
+ FullyQualifiedErrorId : CouldNotNewService,Microsoft.PowerShell.Commands.NewServiceCommand