I'm trying to create a new service (AppOneTest) on windows 2016, which should be available in services.msc and whenever the service starts (AppOneTest) it should start the process explorer
$ServiceName = "ApplicationOneTest"
$ServiceDisplayName = "AppOneTest"
$ServiceDescription = "This launches process explorer"
$ExecutablePath = "C:\processexp\procexp64.exe"
$ScriptPath = "C:\Backup\LaunchScript.ps1"
$LaunchScript = @"
# Script to launch processexp
& '$ExecutablePath'
"@
$LaunchScript | Out-File -FilePath $ScriptPath -Encoding utf8
New-Service -Name $ServiceName -DisplayName $ServiceDisplayName -Description $ServiceDescription -BinaryPathName "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File $ScriptPath" -StartupType Automatic
sc.exe config $ServiceName obj= "domain\username" password= "******" type= interact
Start-Service -Name $ServiceName
This script will try to create a service and will try to start that service. However, when I try to start the service which was created, it's stuck and never starts.
Any assistance is much appreciated.