start-process

“Start-Process -NoNewWindow” within a Start-Job?

随声附和 提交于 2019-12-23 08:29:38
问题 I'm having issues using Start-Process within a Start-Job, specifically when using -NoNewWindow . For example, this test code: Start-Job -scriptblock { Start-Process cmd -NoNewWindow -Wait -ArgumentList '/c', 'echo' | out-null Start-Process cmd # We'll never get here } get-job | wait-job | receive-job get-job | remove-job Returns the following error, that apparently google hasnt heard of: Receive-Job : There is an error processing data from the background process. Error reported: Cannot

Powershell start-process script calls a second script - how to make one script only

时光总嘲笑我的痴心妄想 提交于 2019-12-22 10:16:26
问题 I have a powershell script that accepts parameters in the form of "sender-ip=10.10.10.10" and that runs perfectly with elevated credentials #script.ps1 $userID=$NULL $line_array = @() $multi_array = @() [hashtable]$my_hash = @{} foreach ($i in $args){ $line_array+= $i.split(" ") } foreach ($j in $line_array){ $multi_array += ,@($j.split("=")) } foreach ($k in $multi_array){ $my_hash.add($k[0],$k[1]) } $Sender_IP = $my_hash.Get_Item("sender-ip") <#Gather information on the computer

Issues with running a PsExec process from code

戏子无情 提交于 2019-12-19 09:02:42
问题 I am experiencing a weird issue when attempting to run a .NET command line tool remotely using PsExec. When running PsExec from command line, it runs and completes fine. When running it from a console application (creating a process, running PsExec.exe with the necessary arguments to it) -- it is running OK. When running it from our in house custom tool that is used to run different tasks, it either times out or does not complete successfully. Here is the code i am using: Process p = new

Start-Process -wait doesn't work when script is launched from command prompt opened with runas or as a scheduled task

北战南征 提交于 2019-12-19 05:47:25
问题 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

Powershell Using Start-Process in PSSession to Open Notepad

夙愿已清 提交于 2019-12-17 19:53:40
问题 I've created a pssession on a remote computer and entered that possession. From within that session I use start-process to start notepad. I can confirm that notepad is running with the get-process command, and also with taskmgr in the remote computer. However, the GUI side of the process isn't showing. This is the sequence I've been using: $server = New-PSSession -ComputerName myserver -Credential mycreds Enter-PSSession $server [$server]: PS C:\>Start-Process notepad -Wait -WindowStyle

Powershell Start Process, Wait with Timeout, Kill and Get Exit Code

偶尔善良 提交于 2019-12-17 16:17:57
问题 I want to repeatedly execute a program in a loop. Sometimes, the program crashes, so I want to kill it so the next iteration can correctly start. I determine this via timeout. I have the timeout working but cannot get the Exit Code of the program, which I also need to determine its result. Before, I did not wait with timeout, but just used -wait in Start-Process, but this made the script hang if the started program crashed. With this setup I could correctly get the exit code though. I am

Powershell Silent Install in Nano Server with Docker

感情迁移 提交于 2019-12-12 01:00:03
问题 My docker file gets a Nano Server container and it adds Java automatically. # Get nano server FROM microsoft/nanoserver # Download file and set in docker container ADD http://javadl.oracle.com/webapps/download/AutoDL?BundleId=225355_090f390dda5b47b9b721c7dfaa008135 \ 'C:\\java\jre-8u151-windows-x64.exe' # Silent install and delete install file RUN powershell Start-Process -filepath C:\java\jre-8u151-windows-x64.exe -ArgumentList '/s,INSTALLDIR=c:\Java\jre1.8.0_151' -Passthru -Wait; \ Remove

Start-Process passing a hashtable in the ArgumentList

醉酒当歌 提交于 2019-12-11 07:09:23
问题 Consider the following situation: Content MyScript.ps1 : Param ( [String]$CountryCode, [String]$FilesPath, [String]$KeepassDatabase, [String]$KeepassKeyFile, [String]$EventLog = 'HCScripts', [String]$EventSource, [HashTable]$CitrixFarm = @{'Server1' = '6.5'} ) $CountryCode $FilesPath $KeepassDatabase $KeepassKeyFile $EventLog $EventSource $CitrixFarm Content of the Caller.ps1 : Param ( $FilesPath = ".\MyScript.ps1", $EvenntLog = 'Test', $CountryCode = 'BNL', $KeepasDatabase, $KeepasKeyFile )

PowerShell Start-Service Timeout

做~自己de王妃 提交于 2019-12-11 07:07:55
问题 Problem I have been working on a timeout feature for the Start-Services feature of my application and have stumbled upon some setbacks in which the timeout doesn't work properly or fails to display properly. My two constants are set as such: $timeout = New-TimeSpan -Seconds $SecondsToWait $elapsedTime = [System.Diagnostics.Stopwatch]::StartNew() The rest of my code has changed multiple time to try and achieve my goal. I have tried all of the following with little or no success. Each attempt

Run PowerShell script in PowerShell 6 from C#

一曲冷凌霜 提交于 2019-12-11 03:56:44
问题 I have a PowerShell script which communicates with a REST server. This script only works in PowerShell 6. I want to call it from C#, because the C# program needs the info from the REST server, and I don't want to rewrite the REST code in C#. So basically, I want to run a PowerShell script from C#. However , in C#, PowerShell.Create(); creates a PowerShell instance that uses PowerShell 5. I already replaced pwsh.exe in the default folder, deleted PowerShell 5 everywhere etc. and when I shift