I would like to know why I cant run this PowerShell command by a batch script command like this one:
start powershell -Verb runAs -ExecutionPolicy Unrestricted -Command xxxxxx
PS1 command:
$TargetFile = "%UserProfile%\Downloads\Police.exe"
$ShortcutFile = "$env:Public\Desktop\Police.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile
$Shortcut.Save()
Batch script command that invoke PowerShell command:
@echo off
Echo Preparing the copy process and making a shortcut for Polixe.exe...
If exist "%UserProfile%\Downloads\Police.exe" (
esentutl /y "%UserProfile%\Downloads\Police.exe" /d "%UserProfile%\Documents\Police.exe" /o
start powershell -Verb runAs -ExecutionPolicy Unrestricted -Command $TargetFile = "%UserProfile%\Downloads\Police.exe" ^
$ShortcutFile = "$env:Public\Desktop\Police.lnk" ^
$WScriptShell = New-Object -ComObject WScript.Shell ^
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile) ^
$Shortcut.TargetPath = $TargetFile ^
$Shortcut.Save() ^
) ELSE (
If not exist "%UserProfile%\Downloads\Police.exe" echo We did no find the file Police.exe, the copy/shortcut transfer did not succeed!
)
exit
I have this errors:
'$TargetFile is not recognized as an internal or external command, operable program or batch file. '$ShortcutFile' is not recognized as an internal or external command, operable program or batch file. '$WScriptShell' is not recognized as an internal or external command, operable program or batch file. '$Shortcut' is not recognized as an internal or external command, operable program or batch file. '$Shortcut.TargetPath' is not recognized as an internal or external command, operable program or batch file. '$Shortcut.Save' is not recognized as an internal or external command, operable program or batch file.