Reputation: 423
A simplified version of what I have, is three powershell scripts. One calls other powershell scripts using credentials. The second calls a function which is stored in the third script. So basically the main function of my first script looks something like this:
Invoke-Command -ScriptBlock { param($script,$param) &$script $param} -ArgumentList $scriptToRun,$param) -ComputerName $computerName -Credential $cred
This function succesfully calls the second script, which takes the passed in parameter like this:
param($path) . ./functions.ps1 addToiTunes $path
The third script contains a function called addToiTunes which basic function starts by creating a COM object for iTunes like this:
function addToiTunes($path) {
$iTunes = New-Object -ComObject iTunes.application
Write-Host "Completed"
}
The problem is, it never gets to the Write-Host statement. It just hangs there on the New-Object statement, then eventually stops and states that "script execution complete'.
Any idea why this would be occurring? Is it because it's trying to create a new com object in a background process? Or could it be my credentials call isn't actually working?
Does anyone know of a better way to call the New-Object? Or should I be checking for an existing object of that application? I'm not really sure what the problem is.
Upvotes: 1
Views: 1602
Reputation: 423
It appears to be something to do with the credentials. If i remove the computername and creds from the call, I don't get the CO_E_SERVER_EXEC_FAILURE message, which is all well and good when the credentials are not required...
UPDATE I've created a new Question which is more directly related to the issue here: Using credentials on ScriptBlock causing COM errors connecting to application
Upvotes: 1
Reputation: 6671
Is this not the famous old second hop issue with Powershell? you need to set up client credential delegation with Enable-WSManCredSSP, see the Scripting guy here:http://blogs.technet.com/b/heyscriptingguy/archive/2012/11/14/enable-powershell-quot-second-hop-quot-functionality-with-credssp.aspx
Otherwise the second 'n third powershell script does not inherit your credentials and runs as local system.
Upvotes: 0