PoshCode Archive  Artifact Content

Artifact 5004a4d6f75c6f38bd46737f31391fff7cf8b0c17b30d57a81fc29d5819b0dfd:

  • File Start-ProcessAsAdministr.ps1 — part of check-in [ca7f27e66f] at 2018-06-10 12:56:20 on branch trunk — Original author: James Brundage @ Microsoft (user: halr9000 size: 2167)

# encoding: ascii
# api: powershell
# title: Start-ProcessAsAdministr
# description: Original author: James Brundage @ Microsoft
# version: 0.1
# type: function
# author: halr9000
# license: CC0
# function: Start-ProcessAsAdministrator
# x-poshcode-id: 1057
# x-archived: 2016-03-05T14:57:22
# x-published: 2010-04-23T19:09:00
#
#
function Start-ProcessAsAdministrator
{
    <#
    .ForwardHelpTargetName Start-Process
    .ForwardHelpCategory Cmdlet
    #>
    [CmdletBinding(DefaultParameterSetName='Default')]
    param(
    [Parameter(Mandatory=$true, Position=0)]
    [Alias('PSPath')]
    [ValidateNotNullOrEmpty()]
    [System.String]
    $FilePath,

    [Parameter(Position=1)]
    [Alias('Args')]
    [ValidateNotNullOrEmpty()]
    [System.String[]]
    $ArgumentList,

    [Parameter(ParameterSetName='Default')]
    [Alias('RunAs')]
    [ValidateNotNullOrEmpty()]
    [System.Management.Automation.PSCredential]
    $Credential,

    [ValidateNotNullOrEmpty()]
    [System.String]
    $WorkingDirectory,

    [Parameter(ParameterSetName='Default')]
    [Alias('Lup')]
    [Switch]
    $LoadUserProfile,

    [Parameter(ParameterSetName='Default')]
    [Alias('nnw')]
    [Switch]
    $NoNewWindow,

    [Switch]
    $PassThru,

    [Parameter(ParameterSetName='Default')]
    [Alias('RSE')]
    [ValidateNotNullOrEmpty()]
    [System.String]
    $RedirectStandardError,

    [Parameter(ParameterSetName='Default')]
    [Alias('RSI')]
    [ValidateNotNullOrEmpty()]
    [System.String]
    $RedirectStandardInput,

    [Parameter(ParameterSetName='Default')]
    [Alias('RSO')]
    [ValidateNotNullOrEmpty()]
    [System.String]
    $RedirectStandardOutput,

    [Switch]
    $Wait,

    [Parameter(ParameterSetName='UseShellExecute')]
    [ValidateNotNullOrEmpty()]
    [System.Diagnostics.ProcessWindowStyle]
    $WindowStyle,

    [Parameter(ParameterSetName='Default')]
    [Switch]
    $UseNewEnvironment   
    )    
    
    process {
        $psBoundParameters = $psBoundParameters += @{"Verb"="runas"}    
        Start-Process @psBoundParameters
    }
}