windows 2012 can't run cmd as admin from powershell - windows

Does anyone know if it's possible to modify the following:
Start-Process "cmd.exe" "/c update.bat -config configfile.txt"
To run in an elevated cmd windows in server 2012. The batch script keeps failing because the cmd session isn't running in admin mode. It works fine on server 2008 as long as the user running the powershell script has admin access.
Have MS changed something in 2012?

Start-Process "cmd.exe" "/c update.bat -config configfile.txt" -Verb RunAs

Related

RunAs as a different user

If I from an elevated cmd run the following line, I get the error: "740: The requested operation requires elevation." But the CMD I run it in, is elevated som how can I tell runas to elevate it or that it is elevated?
"C:\Windows\System32\runas.exe /savecred /noprofile /user:aloc-ad\teksupadmin "%windir%\System32\mmc.exe %windir%\System32\virtmgmt.msc""
I have also tried PowerShell:
Start-Process -FilePath c:\Windows\System32\mmc.exe -ArgumentList c:\Windows\System32\virtmgmt.msc -Credential aloc-ad\teksupadmin
But with same result.
Runas will check if the user you hand over to it has elevated rights.
If the user (here teksupadmin) doesn't have elevated rights (or permissions in general) , the program wont run even when you started the cmd with elevated rights.

Executing file from Admin CMD via CLI

I am trying to execute a file via the CMD with Administrative privileges.
How can I open a cmd via command line with Administrative privileges.
I have to execute a script within a script.
powershell -ExecutionPolicy ByPass -noprofile -command "&{ start-process powershell -ArgumentList '-noprofile -File C:\scripts\install_ims.ps1' -verb RunAs}"
I have tried this in a bat file, but it doesn't work when executed within the script.
This should work fine for your purposes.
powershell -Command "Start-Process <filename> -Verb RunAs"
This is copy-pasted from some Batch files that I finally added to GitHub in the last few days if you have questions, that's probably the best place to go. https://github.com/Benny121221/Batch-BS

I'm having a trouble installing a .msi or .exe file in PowerShell set in my script

I'm doing a script in PowerShell and I have to install the administration console. I have two installers, .msi and .exe for this one.
My script has to install it and it can't do it because the script stops when the installation GUI appears.
I was reviewing some webpages and I noticed something about silent mode so I try with this script
$pathvargs = {C:\_projects\xxxx\Current\Deployment\SupplementalInstalls\Administration\setup.exe /S /v/qn }
Invoke-Command -ScriptBlock $pathvargs
but a Windows Installer popup thrown explaining me how are the commands for a windows installation, so I try with these scripts too:
$product = [WMICLASS]"\\MyMachine\ROOT\CIMV2:win32_Product"
$product.Install("C:\_projects\xxxx\Current\Deployment\SupplementalInstalls\Administration\AdminConsole.msi")
Start-Process -FilePath "C:\_projects\xxxx\Current\Deployment\SupplementalInstalls\Administration\setup.exe" -ArgumentList "/S /v/qn"
Same windows installation poop up appears.
I can't install the administration console using my script, can anyone help me?
If you have the MSI, do it through MSIExec.exe in Powershell, i.e.:
Invoke-Expression "msiexec.exe /i 'C:\_projects\xxxx\Current\Deployment\SupplementalInstalls\Administration\AdminConsole.msi' /quiet /norestart /L 'install.log'" -ErrorAction Stop

The directory name is invalid - Powershell Script

I am an administrator and learning about scripts but was trying to create a script to open multiple programs as another user (my admin password)
The following script runs well when run from powershell ise but won't run properly when right clicking and selecting "run with powershell"
Start-Process -FilePath "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -Credential "domain\userid"
When run it prompts for password but doesn't bring up google chrome. It works OK when run from Powershell ISE and I get error "The directory name is invalid" when running the script from Powershell.exe (not the ISE environment).
Add the working directory:
Start-Process `
-FilePath "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" `
-Credential "domain\userid" `
-WorkingDirectory "C:\Program Files (x86)\Google\Chrome\Application\"

Unable to execute multi-command in power shell

I'm working on power shell script using windows 2012 server, that do simple two functions
open powershell as an administrator
change the directory to c:\user\scrpt.bat
the code is:
powershell -Command "& {powershell Start-Process PowerShell -Verb RunAs; Set-Location C:\}
the problem is not when execute the first part, it's in the other part which is:
Set-Location C:\}
My question is there any way after running powershell as administrator execute the next command ?
I already tried to use semicolon ";" but no luck
If you want to change directory for the process you're spawning - use -WorkingDirectory option:
powershell -Command "& { Start-Process PowerShell -Verb RunAs -WorkingDirectory 'D:' }"

Resources