Using Enter-PSSession to start a whole new session will support elevation if you specify CredSSP, which enables the delegation of user credentials: This is because any prompt for elevation will happen on the remote machine in a non-interactive session and so will fail. If you use Invoke-Command to run a script or command on a remote computer, then it will not run elevated even if the local session is. PS> Start-Process powershell.exe -Verb runAs To run an entire PowerShell session 'As Admin' from an existing PowerShell (non-elevated) session: To run (and optionally elevate) a PowerShell script from a CMD shell, see the PowerShell.exe page.Ī set of commands can also be saved in a scriptblock variable, and then passed to a new (elevated) PowerShell session: Start-Process -FilePath powershell.exe -ArgumentList $code -verb RunAs -WorkingDirectory C: PS C:\> Start-Process powershell -ArgumentList '-noprofile -file MyScript.ps1' -verb RunAs To elevate a script from a (non-elevated) PowerShell command line: Shortcuts can be edited to always run as Admin - Properties | Shortcut | Advanced then tick "Run as administrator". It is possible to right click Powershell.exe (or it's Start menu shortcut) and run it 'As Admin'. Some PowerShell cmdlets and Windows commands such as REG ADD and SUBINACL have to be run from an elevated prompt, there are several ways of doing this.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
June 2023
Categories |