start-process

How to start and stop processes in PowerShell?

混江龙づ霸主 提交于 2020-02-06 01:45:51
问题 This should work fine in PowerShell older than 3. I need to run two processes: wuapp.exe and desk.cpl with ScreenSaver's tab. The problem I have is that once I start wuapp.exe the process name shows up in Task Manager as explorer.exe - the current code works for wuapp.exe but not on every machine. The other thing is when I kill rundll32 other apps will close also. What do you suggest? $wshell = New-Object -ComObject Wscript.Shell Start-Process wuapp.exe (New-Object -comObject Shell

PowerShell Executing a function within a Script Block using Start-Process does weird things with double quotes

让人想犯罪 __ 提交于 2020-02-01 04:07:26
问题 I have a PowerShell script that edits the registry, so it needs to run as admin. To do this, I start up a new PowerShell process from my running PowerShell script, and pass in part of the registry key path using a Script Block with a function in it. When I use double quotes within that function, PowerShell tries to interpret them as commands, rather than a string. If I use single quotes though, then everything works fine. I've created a little stripped down sample powershell script that

Start-process raises an error when providing Credentials - possible bug

放肆的年华 提交于 2020-01-20 05:37:28
问题 Would you possibly know why this error is being raised in response to the code below. User-name and password have been verified as correct. $secPassword = ConvertTo-SecureString "Password" -AsPlaintext -Force $farmCredential = New-Object System.Management.Automation.PsCredential "SharePoint\SP_Farm",$secPassword Start-Process $PSHOME\powershell.exe -Credential $FarmCredential -ArgumentList "-NoExit","-Command `"&{`$outvar1 = 4+4; `"write-output `"Hello:`"`$outvar1`"}`"" -Wait the error; Start

PowerShell Start-Process loses precision on number passed as a string to a function

喜你入骨 提交于 2020-01-17 10:23:25
问题 I have some code that edits the registry, so it needs to run as admin. To do this, I start up a new PowerShell process from my running PowerShell script, and pass in part of the registry key path, which happens to be a version number, e.g. "12.0". The function in the new PowerShell process receives the string as "12" though, not "12.0", and so I'm getting errors that it can't find the registry key. I've created a little sample powershell script that reproduces the problem. Here's the snippet:

Tell if Stop-Process was successful or not in PowerShell

烈酒焚心 提交于 2020-01-02 20:48:49
问题 Currently I start processes in PowerShell like this: $proc = Start-Process notepad -Passthru $proc | Export-Clixml -Path (Join-Path $ENV:temp 'processhandle.xml') to later on kill it like this: $proc = Import-Clixml -Path (Join-Path $ENV:temp 'processhandle.xml') $proc | Stop-Process The problem is that if the process died before I got to call $proc | Stop-Process , I will get error in the PowerShell output. I need to disable this error and just get the Boolean value indicating if Stop

Is there a way to pass serializable objects to a PowerShell script with start-process?

蓝咒 提交于 2019-12-31 02:14:11
问题 I know about PowerShell jobs, but I want to use start-process and pass a serializable object to the new powershell process. Is there any way to do this? It seems that using start-process you have to provide a string argument list which won't cut it for me. I'm trying to get a PSCredential from one process to another (or a SecureString, I'll take either one). Maybe this circumvents security. UPDATE - adding the solution I used after seeing help from others (using solution from @PetSerAl) I

Powershell Start-Process to start Powershell session and pass local variables

跟風遠走 提交于 2019-12-30 21:09:13
问题 Is there a way to use the Powershell Start-Process cmdlet to start a new Powershell session and pass a scriptblock with local variables (once of which will be an array)? Example: $Array = @(1,2,3,4) $String = "This is string number" $Scriptblock = {$Array | ForEach-Object {Write-Host $String $_}} Start-Process Powershell -ArgumentList "$Scriptblock" Thanks. 回答1: I'm pretty sure there's no direct way to pass variables from one PowerShell session to another. The best you can do is some

PowerShell - script 1 calls script 2 - how to return value from script 2 to script 1

与世无争的帅哥 提交于 2019-12-29 09:13:12
问题 I have two PowerShell scripts. One script invokes another PowerShell script using elevated credentials, using Start-Process. But I am struggling with how to make the second script return the output value to the first script. Here is script # 1, which is invoked with script1.psl "sender-ip=10.10.10.10" function getUser($abc) { <#Previously created password file in C:\Script\cred.txt, read-host -assecurestring | convertfrom-securestring | out-file C:\Script\cred.txt#> $password = get-content C:

Powershell Remote Invoke-Command Start-Process App Immediately Closes After Launch

ぐ巨炮叔叔 提交于 2019-12-24 08:31:46
问题 I am working on a script to remotely kill two processes, delete some folders, and launch a service as an application. Eventually this will be deployed to run against multiple servers, but I'm currently testing it against a single server. Everything works great except for the final step which is to launch the remote service (which is being run as an application using the -cl argument due to some compatibility issues with it running as a service). The application launches via the script but

Passing variable arguments using PowerShell's Start-Process cmdlet

自古美人都是妖i 提交于 2019-12-24 01:44:46
问题 Good evening everyone, I'm using a command line that passes arguments to as variables in the following scripts to be run in another ps1 that I'm calling from within this script. Whenever I try to pass the arguments from the command line I get the following error though Start-Process : A positional parameter cannot be found that accepts argument Would anyone be able to assist? Thank you for your time and much appreciate any help. param ( [string]$targetserver = $args[0], #target server [string