Trying to launch grunt serve with Start-Process - powershell

I'm trying to launch grunt serve with custom switch parameters from script, but keep getting positional parameter related error
Here's what I've tried so far:
start-process grunt serve -ArgumentList {-switch1;-switch2} -WorkingDirectory $mydir
start-process grunt -ArgumentList {serve;-switch1;-switch2} -WorkingDirectory $mydir
start-process {grunt serve} -ArgumentList {-switch1;-switch2} -WorkingDirectory $mydir
start-process (grunt serve) -ArgumentList {-switch1;-switch2} -WorkingDirectory $mydir
start-process "grunt serve" -ArgumentList {-switch1;-switch2} -WorkingDirectory $mydir
I'm not entirely sure the syntax for -ArgumentList is correct, but just grunt launches alright.
I know, I can do start powershell -command {grunt serve -switch1 switch2} and it will work, but I want to avoid creating another PowerShell session.

Related

Specifying complete installation option when running msi from powershell

I am trying to automate the installation of gstreamer on windows using powershell
I have the msi file downloaded, and am installing it as shown below
PS C:\Users\Administrator> $path = "C:\Users\Administrator\Downloads\gstreamer-1.0-devel-mingw-x86_64-1.18.0.msi";
PS C:\Users\Administrator> Start-Process -Wait -FilePath $path -Argument "/qn"
However, this does not get me the complete installation, because it is only selecting the default arguments from the installer.
I need to specify for it to perform the complete installation, how can I modify my arguments? So that it selects "complete" installation and not "typical" like it does by default
These should work:
Start-Process -Wait -FilePath $path -Argument "/qn","Complete=1"
Start-Process -Wait -FilePath $path -Argument "/qn Complete=1"
I had the same problem, so I ran the Installer from power shell with and without the /qn argument and logged the process into two different files. Finally, I compared the result and I was able to find that for installing process using the UI it adds a property called INSTALLLEVEL, which is set to 1000 (don't know why this value yet). So, by adding the argument INSTALLLEVEL=1000 it installs the complete version.
Start-Process -Wait -FilePath gstreamer-1.0-mingw-x86_64-1.20.2.msi -Argument "/qn INSTALLLEVEL=1000"
I had tried below but it did not work
Start-Process -Wait -FilePath $path -Argument "/qn","Complete=1"
Start-Process -Wait -FilePath $path -Argument "/qn Complete=1"
While this is working fine for me.
Start-Process -Wait -FilePath gstreamer-1.0-mingw-x86_64-1.20.2.msi -Argument "/qn INSTALLLEVEL=1000"

How to pass args to aspnet_regiis via powershell

I have 2 scripts:
Launch.ps1
Deploy.ps1
Launch simply runs deploy as administrator:
clear
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$scriptPathToRun = "$scriptPath\Deploy.ps1"
Start-Process -Verb runAs PowerShell -ArgumentList '-noexit','-File', $scriptPathToRun
I am trying to pass arguments to aspnet_regiis, I have tried the following:
Start-Process -NoNewWindow "$env:windir\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis" -ArgumentList '–ga', 'domian\serviceAccount'
Start-Process -NoNewWindow "$env:windir\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis" -ArgumentList '–ga domian\serviceAccount'
Start-Process -NoNewWindow "$env:windir\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis" -ArgumentList #('–ga', 'domian\serviceAccount')
& "$env:windir\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis" '–ga domian\serviceAccount'
& "$env:windir\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis" '–ga', 'domian\serviceAccount'
& "$env:windir\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis" #('–ga', 'domian\serviceAccount')
In all these attempts, aspnet_regiis is run but it appears no args are passed to it because the output is just a listing of available aspnet_regiis parameters.
Can someone point out what I'm missing? Thanks.
The simplest answer is probably to just run the command using the call/invocation (&) operator:
& "$env:SystemRoot\Microsoft.Net\Framework64\v4.0.30319\aspnet_regiis" -ga domain\serviceAccount
If you really wanted to use Start-Process, you should be able to write it this way:
Start-Process "$env:SystemRoot\Microsoft.Net\Framework64\v4.0.30319\aspnet_regiis" "-ga","domain\serviceAccount" -NoNewWindow
The first token on that command line is the executable to run (i.e., -FilePath). The -ArgumentList parameter is an array (i.e., "-ga","domain\serviceAccount").

How to pass argument to Start-Process

I'd like to run this command
net start "PTV LOXANE xDataServer 1.4.1.067" using Start-Process in powershell with admin rights.
My problem is how to give the quote to ArgumentList.
I've tried this but it doesn't work
Start-Process net -ArgumentList "stop \"PTV LOXANE xDataServer 1.4.1.067\"" -Verb runas -wait -NoNewWindow -PassThru
I've found how to do it. You must double the quotes:
Start-Process net -ArgumentList "start ""PTV LOXANE xDataServer 1.4.1.067""" -wait -PassThru -Verb runas
Now I've got a second question. How can I run this command when calling powershell ?
This doesn't work:
powershell -Command 'Start-Process net -ArgumentList "start ""PTV LOXANE xDataServer 1.4.1.067""" -wait -PassThru -Verb runas'

Opening multiple powershell scripts same time for user

I am developing a SQL health check using powershell. So it checks the statuses of databases and outputs text to console whether anything needs attention. i have the first ps1 to load the various checks but i need them to start loading the below ps1's in parralel. I need to work this on powershell v2. Do i need to use start-job for each line
Here is my code
$Output = #()
$BackupHistory = #()
$script = $myInvocation.MyCommand.Definition
$scriptPath = Split-Path -parent $script
Start-Process -FilePath powershell.exe -ArgumentList "-noexit","$scriptpath\SQLHealthVLF.ps1 $Env" -Wait -WindowStyle Maximized
Start-Process -FilePath powershell.exe -ArgumentList "-noexit","$scriptpath\SQLHealthBackup.ps1 $Env" -Wait -WindowStyle Maximized
Start-Process -FilePath powershell.exe -ArgumentList "-noexit","$scriptpath\SQLHealthIOAlerts.ps1 $Env" -Wait -WindowStyle Maximized
Start-Process -FilePath powershell.exe -ArgumentList "-noexit","$scriptpath\SQLDisksUsage.ps1 $Env" -Wait -WindowStyle Maximized
What currently happens is one loads, then i need to close it and then the next one loads. This doesn't give the script consistency.

Can't start PowerShell script file with credentials of other user

I have a GUI that has been created with PowerShell Studio and exported as a PS1-file. I'm now trying to launch this GUI by calling it with another user's credentials.
When I run the code it doesn't even give an error message. PowerShell pops-up and closes again in seconds and nothing is launched. Follwoing this thread, I think I followed the correct syntax.
$Script = 'S:\Prod\Script center\GUI Script.ps1'
$Credentials = Get-Credential
$powershellArguments = "-file '$Script'", "-noexit", "-verb runas"
Start-Process powershell -Credential $Credentials -ArgumentList $powershellArguments
These ones doesn't work either:
Start-Process powershell -Credential $Credentials -ArgumentList "-noprofile -command &{Start-Process powershell -verb runas -File 'S:\Prod\Script center\GUI Script.ps1'}"
Start-Process powershell -Credential $Credentials -ArgumentList "-noprofile -command &{Start-Process $script -verb runas}"
And this one is asking me the credentials, although they are already saved in the variable $Credentials. However, the powershell console launched is not launched as the user in the Credentials :(
$cmd = 'powershell.exe'
$arguments = "-NoExit", "-NoProfile", "-WindowStyle Maximized", '-NoLogo', "Credential $Credentials", "File '$script'"
Start-Process $cmd -ArgumentList $arguments -Verb runAs
I'm sure it's not related to the GUI script, because this works perfectly fine:
& 'S:\Prod\Script center\GUI Script.ps1'
Any help is greatly appreciated.
Maybe your error is only on argument single quotes $powershellArguments = "-file '$Script'"; double quotes should be used.
Start-Process -FilePath "powershell" -Credential $cred -ArgumentList #("-file 'cred.ps1'") # doesn't work
Start-Process -FilePath "powershell" -Credential $cred -ArgumentList #("-file ""cred.ps1""") # works