![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Passing credential object - what's the type? I'm writing a script function that will take a credential object and assign the username and password to members of a ProcessStartInfo object. Here's the function: function Impersonate ([System.Management.Automation.PSCredential] $credentials, [string] $command, [string] $arguments, [string] $workingDirectory ) { $StartInfo = new-object Diagnostics.ProcessStartInfo $StartInfo.UserName = $credentials.GetNetworkCredential().UserName $StartInfo.Password = $credentials.GetNetworkCredential().Password $StartInfo.FileName = $command $StartInfo.Arguments = $arguments $StartInfo.WorkingDirectory = $workingDirectory $StartInfo.LoadUserProfile = $true $StartInfo.UseShellExecute = $false [System.Diagnostics.Process]::Start($StartInfo) } to test it I'm doing this: $cred = Get-Credential Impersonate [System.Management.Automation.PSCredential]$cred, "e: \toolshed\reflector.exe", "e:\dev\MyOperations.dll", "e:\dev" I get a runtime error "Cannot convert "System.Object[]" to "System.Management.Automation.PSCredential" on the line where I call Impersonate(). Do I have the wrong type for what get-credential returns? thx, bob |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: Passing credential object - what's the type? On May 8, 6:26*pm, bobuva <robert...@xxxxxx> wrote:
don't use commas to separate the function arguments. - Oisin | ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Guest | Re: Passing credential object - what's the type? On May 8, 5:22 pm, "Oisin (x0n) Grehan [MVP]" <ois...@xxxxxx> wrote:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Re: Unable to cast COM object of type 'ADODB.RecordsetClass' to class type 'System.Object[]' | Michel Posseth [MCP] | .NET General | 2 | 03-27-2008 10:04 AM |
| Alternate Credential passing | Anatoli | PowerShell | 4 | 08-02-2007 02:14 PM |
| Passing a HashTable object as a parameter to a script | Brillig | PowerShell | 8 | 02-07-2007 04:45 PM |
| Passing script function as a callback into .NET object | Ilya | PowerShell | 0 | 01-20-2007 03:34 PM |
| Help with foreach-object and passing parameters | Xanbar | PowerShell | 1 | 11-15-2006 02:55 AM |