Не удалось запустить службу с помощью Powershell на виртуальной машине - PullRequest
0 голосов
/ 23 мая 2019

Я могу войти в виртуальную машину, используя ее учетные данные, которые являются учетной записью администратора, но получаю сообщение об ошибке, когда я попробовал те же учетные данные в сценарии PowerShell

Сначала выполнил приведенную ниже функцию в 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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...