I would like to Invoke a command on a Remote VM using PowerShell with PowerCLI.
Invoke-VMScript -ScriptText "cmd /c calc" -ScriptType Bat -VM $VMName -GuestCredential $Credential -Confirm:$false -ea SilentlyContinue
Sadly everytime when my command get's invoked an Popup appears telling me "A Program running on this computer is trying to display a message" If click manually on that Popup my Script runs fine, but how can I automate this, so that I can use PowerCLI for this.
The goal is to execute a Binary in Interactive Mode, that processes Automated Tasks, when the Script get's invoked by "Invoke-VMScript"
This is an issue with Interactive Services Detection. Your script is trying to run as interactive in Session 0.
The standard workarounds are creating a schedule task and then triggering it. Or invoking psexec.exe to the user session with -i.
Related
I have a task to remotely run Acrobat Distller (AD) remotely.
I was able to locally run AD in the command prompt:
"C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\acrodist.exe" /O $OutputFolder $InputFolder\test.ps
I tried invoking the same command using powershell:
powershell.exe -NoExit -Command Invoke-Command -ComputerName $server -ScriptBlock {'"C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\acrodist.exe" /O $OutputFolder $InputFolder\test.ps'}
When ran, the powershell command did prompt any error BUT it did not generate the expected PDF output as well.
Can I get some assistance on what I am doing wrong here?
Thanks
You probably need to use $using:OutputFolder and $using:InputFolder.
Normally, powershell variables are only set for your session and don't carry over to remote servers. The $Using: format allows you to do this with Invoke-Command.
I need to run a PowerShell script from another PowerShell script as different user and hidden window.
What do I have so far:
Start-Process powershell '& C:\test.ps1' -WindowStyle Hidden -Credential $cred
where $cred is a PSCredential object. The test.ps1 script is for testing purposes one line with Remove-Item. As I can still see the file not being removed I can tell that the script is not being run.
EDIT
My original intention is to run regedit script but when I was implementing Start-Job answer (below) I've got this error:
Start-Job : The value of the FilePath parameter must be a Windows PowerShell script file. Enter th
e path to a file with a .ps1 file name extension and try the command again.
You could use jobs for this. As the Powershell documentation says
A Windows PowerShell background job runs a command without interacting
with the current session.
PS> $myJob = Start-Job -FilePath C:\test.ps1 -Credential $cred
To get the result/output of the job, use Receive-Job
PS> $myJob | Receive-Job -Keep
You can run the PowerShell scripts through task scheduler. I'm not sure if it is your goal, but it will let you execute PowerShell scripts on a user's session using their credentials.
I'll let you Google the how to, to fit your needs.
When I start the powershell with Credential parameter that uses domain credentials from the domain computer, the keyboard stops working:
start powershell -Credential $DomainUser
If I start cmd keyboard works, and when I start powershell from cmd it stops again.
If I use
start powershell -Credential $DomainUser -ArgumentList "1+1; sleep 2"
I can see the commands executed normally and this is the only way I can execute them.
If I run
start powershell -Credential $DomainUser -ArgumentList '-NoExit -Command "pause"'
I can type the letters while pause is in effect, after it finishes no typing again.
If I shift + context menu and run powershell as domain user via Run as different user option it works.
It happens on multiple Windows 8 and 10 OSes and Posh 4+.
Anybody knows what is going on ?
I am creating a PowerShell script that automates the Oracle software install. Right now everything is working correctly until I trying and setup the two listeners for the software.
When manually installing the database software you have to open a new shell and execute these two commands after the software has been installed....
netca -silent -responsefile c:\path\to\netca_listener.rsp
netca -silent -responsefile c:\path\to\netca_callout_listener.rsp
I have been trying to execute these two rsp files like so..
saps -FilePath cmd.exe -ArgumentList "/c", "netca", "-silent", "-responsefile $first_rspfile" -WindowStyle Hidden -Wait
Typically the process will spin briefly, but then will do nothing, and the response files will pop open when the process starts running.
Any clues to what might be going on?
You don't need cmd /c in PowerShell. Try this:
Start-Process -FilePath "netca.exe" `
-ArgumentList #("-silent", "-responsefile $first_rspfile") `
-WindowStyle "Hidden" -Wait
I've got a script that's I want to run as a scheduled task, but it's not doing the thing it's supposed to. I'm trying to call an executable with Start-Process and the -Wait switch before continuing. Line is
Start-Process -FilePath "C:\Pfx Engagement\Admin\Utilities\Backup Restore\BackupRestoreUtil.exe" -ArgumentList "/f "$backup_directory"" -Wait
If I call it from a command prompt, ie:
powershell .\script.ps1
it works. It runs the command and waits for it to finish before moving on. There's more to the script that has to be run after that command is finished. The problem is that when it's a scheduled task, it doesn't wait. Doing some basic troubleshooting, I first tried opening a cmd window with runas using the scheduled task account, named "Scripts." So I run
runas /env /user:Scripts cmd
to open a command prompt window with the task account. From that command prompt, I try again the "powershell .\script.ps1" and this time, it doesn't wait. It runs the command and moves on immediately before the command is finished. So I thought it might be an issue with the "Scripts" account, until I opened a new command prompt with runas Administrator
runas /env /user:Administrator cmd
When I call the script from this Administrator command prompt, the -Wait switch is also ignored, and the script moves along immediately after calling it without waiting for it to finish.
The odd part about this is that when I call it from the command prompt from Administrator account without doing runas, it works. Same account, two different results. Any ideas as to what the hell is going on here, and equally importantly, how to fix it?
OS is Server 2008 R2, running powershell 3.0
Can't tell you why it's doing it, but I think this might work around it:
$proc = Start-Process -FilePath "C:\Pfx Engagement\Admin\Utilities\Backup Restore\BackupRestoreUtil.exe" -ArgumentList "/f "$backup_directory"" -Passthru
do {start-sleep -Milliseconds 500}
until ($proc.HasExited)
The -Passthru switch will make it return a Process object for the process, and you can test that to see when the process has exited.