none
Powershell Script to Launch Application RRS feed

  • Question

  • I use Remote Desktop Connection Manager to organize my hundreds of RDP clients. The account that I currently log into my machine as does not have rights to launch this application. I would like to create a powershell script that launches the app as a different user. If I manually open a Powershell window as the elevated user and enter the following command it works.

    Invoke-Item "C:\Program Files (x86)\Remote Desktop Connection Manager\NewRDCManGroups.rdg"

    What I would like the script to do is first open Powershell as the elevated user then launch this program as the elevated user. I can get Powershell to open and prompt for credentials (which is what I want) but then it doesn't launch the app. Here is what I have so far:

    Start-Process powershell.exe -Credential "domain\accountname" "C:\Program Files (x86)\Remote Desktop Connection Manager\RDCMan.exe" Invoke-Item "C:\Program Files (x86)\Remote Desktop Connection Manager\NewRDCManGroups.rdg"

    Any help is much appreciated.
    Thursday, June 27, 2013 7:14 PM

All replies

  • I think I can give you solution to your request - if it is still up to date.
    About 1 year ago I wrote command to store credentials in file and reuse credentials later.
    But it is really not recommended of doing this, because everyone using this script can use you crendentials, too.

    The stored credentials can only be reused if you run the "GetCredFrom" command with same user on same machine as you run the "SaveCred" command.

    Function SaveCred
    	{
    	[CmdletBinding()]
        
        PARAM
            (
            [Parameter(Mandatory=$false,HelpMessage="Credentials to Save - if not given you are asked for")][System.Management.Automation.PsCredential]$Credential=$null, 
    		[Parameter(Mandatory=$true,HelpMessage="File to save the Credentials to")][string]$File
            )
            
        PROCESS
            {
    		$Error.Clear()
    		
    		Write-Debug "Saving Credentials to file $file ..."
    		
    		if( $Credential -eq $null)
    			{
    			Write-Debug "Getting Credentials from User.."
    			$Private:Credential = Get-Credential
    			}
    			
    		$Private:Password = $Credential.Password | ConvertFrom-SecureString
    		
    		$Private:Userobject = New-Object PSCustomObject
    		$Userobject | Add-Member -MemberType NoteProperty –Name Username -Value $Credential.UserName
    		$Userobject | Add-Member -MemberType NoteProperty –Name Password -Value $Password
    		
    		Export-Clixml -InputObject $Userobject -Path $File -Force
    		
    		GetError
            }
    	}

    Function GetCredFrom
    	{
    	[CmdletBinding()]
        
        PARAM
            (
    		[Parameter(Mandatory=$true,HelpMessage="File to get the Credentials from")][string]$Path
            )
            
        PROCESS
            {
    		$Error.Clear()
    		Write-Debug "Getting credentials from file $Path ..."
    		
    		$private:Userobject = Import-Clixml -Path $Path
    		
    		$private:Userobject.Password = $private:Userobject.Password | ConvertTo-SecureString
    		#$Private:Userobject = [System.Management.Automation.PSCredential]$Private:Userobject
    		
    		#$Credential = New-Object System.Management.Automation.PsCredential
    		#$Credential.UserName = $Userobject.Username
    		#$Credential.Password = $Userobject.Password
    		
    		GetError
    		
    		Return $Userobject
    		}
    	}

    • Proposed as answer by MK-Maddin Monday, December 23, 2013 9:36 AM
    Wednesday, October 2, 2013 11:24 AM