powershell install multiple software packages, disable UAC - windows

wondering if there is a way to make powershell not open UAC prompt and just run through an install script, for example
Get-Url http://dl.google.com/chrome/install/375.126/chrome_installer.exe c:\temp\chrome_installer.exe
Start-Process -FilePath 'c:\temp\chrome_installer.exe' -ArgumentList '/silent', '/install' -Wait
Start-Process -FilePath 'C:\temp\DifferentProgram.exe' -ArgumentList '/argument' -Wait

Related

How to run a exe file with /regServer to create aplicationID in Dcom config in component services using powershell?

I have one WFO.exe file which I want to register .
I am able to run below command on remote desktop using powershell and a specific APPID is generated in Dcom config under component services:
c:\WFO.exe /RegServer
c:\WFO.exe /Service
But when I try to run this command through Packer powershell APPId is not getting created.
I tried multiple commands, but nothing is working
Start-Process -Wait -FilePath c:\WFO.exe -ArgumentList "/RegServer" -passthru
Start-Process -Wait -FilePath c:\WFO.exe -ArgumentList "/Service" -passthru
Invoke-Command -ScriptBlock {
Start-Process -Wait -FilePath "c:\WFO.exe" -ArgumentList "/s /RegServer" -PassThru
}
Invoke-Command -ScriptBlock {
Start-Process -Wait -FilePath "c:\WFO.exe" -ArgumentList "/s /Service" -PassThru
}
Do I need to import anything to work it through Packer Powershell?

Elevate rights in current directory with PowerShell

For example I'm in C:\Users\User\Desktop\Tools and I'm trying to stay here as admin.
I tried this way, gluing together different commands:
"C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -noexit" & -windowstyle hidden -Command Start-Process powershell -ArgumentList '-NoExit', '-Command cd %V' -Verb runAs""
The PATH changes to C:\WINDOWS\system32 why? How to elevate rights in current directory via simple command?
Use $PWD from the calling process to change the location on startup:
Start-Process powershell -ArgumentList '-NoExit', "-Command cd '$pwd'; & .\actual\script\you\want\to\run.ps1" -Verb runAs

Powershell remove-item with a timer?

I have a script where my users get to install programs in on their computers.
the logic is -> copy from network path the installation file to the local hard drive of the computer,
run the installation file with different creds
I want to then delete the file but this code isnt good
copy-item "$path1" -Destination C:\ProgramData\ #copy from network path to local
$progyname = [System.IO.Path]::GetFileName($path1) #holding the programname.exe
Start-Process powershell -Credential $creds -workingdirectory c:\programdata\ -ArgumentList "-Command &{Start-Process $progyname -Verb RunAs}"
Remove-Item -path c:\programdata\$progyname -Force
Problem is the script will delete the item too soon, i actually want to wait for the installation to be completed and then delete the file.
what could work here?
Use the passthru parameter for start-process, save the returned ID to a variable and wait until the process is closed and youre good to delete
You can try this:
copy-item "$path1" -Destination C:\ProgramData\ #copy from network path to local
$progyname = [System.IO.Path]::GetFileName($path1) #holding the programname.exe
Start-Process powershell -Credential $creds -workingdirectory c:\programdata\ -ArgumentList "-Command &{Start-Process $progyname -Verb RunAs}"
$pro = $progynane.basename
If (!(Get-Process $pro -ErrorAction SilentlyContinue)){Remove-Item -path c:\programdata\$progyname -Force}
Or if you like you can -Wait parameter at end of Start-Process as #Lee_Dailey pointed.

powershell error while trying to start process

Running PS as admin, trying to run an exe from server (or even if i copy this file to my computer and trying to run it locally)
$apps = "\srv\blabla"
Start-Process $apps\mbsetup.exe -Credential $Credentials
Error:
without -credential this would work, i would assume something bad with the user definition but the creds are that of the domain admin.
any idea?
It looks like your app requieres administrative privileges. Add -Verb RunAs to your Start-Process cmdlet to elevate the execution.
But -Verb RunAs will not work in combination with -Credential. This is a workaround:
Start-Process powershell -Credential $Credentials -ArgumentList "-Command &{Start-Process yourApp.exe -Verb RunAs}"

How to pass quoted arguments to elevated batch script via powershell Start-Process

I have a really hard time passing quotes to .bat files when elevating, binaries seem to work thou... steps to reproduce:
create a small test batch script %TEMP%\test.bat containing
echo.%* && pause
Fire up powershell and try those:
# both behave like expected, echoing hello and pausing
saps -filepath cmd -argumentlist '/c echo.hello && pause'
saps -filepath "$env:TEMP\test.bat" -argumentlist 'hello'
# both behave like expected, echoing "hello" and pausing
saps -filepath cmd -argumentlist '/c echo."hello" && pause'
saps -filepath "$env:TEMP\test.bat" -argumentlist '"hello"'
# both behave like expected, echoing an elevated hello and pausing
saps -verb runas -filepath cmd -argumentlist '/c echo.hello && pause'
saps -verb runas -filepath "$env:TEMP\test.bat" -argumentlist 'hello'
# cmd still echoes correctly "hell"no and pauses
saps -verb runas -filepath cmd -argumentlist '/c echo."hell"no && pause'
# tl;dr
# now this is where hell breaks loose
saps -verb runas -filepath "$env:TEMP\test.bat" -argumentlist '"hell"no'
# doesnt echo anything, window pops up and vanishes in an instant
# doesnt pause
The "runas" verb doesn't work if you invoke it directly on a batch file. You need to invoke it on the actual executable (i.e. cmd.exe) and pass the batch file as an argument.
$params = '/c', "$env:TEMP\test.bat", '"hell"no'
Start-Process -Verb Runas -FilePath $env:ComSpec -ArgumentList $params

Resources