Voglio invocare sc create
da uno script PowerShell. Ecco il codice.Come faccio a richiamare sc create da uno script PowerShell
function Execute-Command
{
param([string]$Command, [switch]$ShowOutput=$True)
echo $Command
if ($ShowOutput) {
Invoke-Expression $Command
} else {
$out = Invoke-Expression $Command
}
}
$cmd="sc create `"$ServiceName`" binpath= `"$TargetPath`" displayname= `"$DisplayName`" "
Execute-Command -Command:$cmd
che dà il seguente errore:
Set-Content : A positional parameter cannot be found that accepts argument 'binpath='.
At line:1 char:1
Qual è il problema? Quali sono gli argomenti posizionali?
Non ci dovrebbero essere spazi dopo i segni = nel comando – AutomatedOrder
Come l'errore dice, 'sc' è un alias per' Set-Content'. Usa il nome completo del file 'sc.exe' –
Da PS4 in poi, puoi usare il cmdlet' New-Service' https://technet.microsoft.com/en-us/library/hh849830(v=wps.630).aspx – sodawillow