error running script remote

May 4, 2011 at 10:26 AM
Edited May 4, 2011 at 10:28 AM

Hi all,

The variable $ID has an value when i try to run the script(printed this). I am trying to run the script from a client and the script is running on the server. Any ideas about what i'm doing wrong?

ForEach-Object : Cannot bind parameter 'Process'. Cannot convert the "-ComputerName" value of type "System.String" to type "System.Management.Automation.Scrip
No incident exists with given id

At \\computername\c$\Script\emailenduser.ps1:9 char:40
+ $incident = Get-SCSMIncident -ID $ID |% <<<< {$_.Object} -ComputerName "computernamehere" (i assume this has to be between " and with \\ in front of it?)
    + CategoryInfo          : InvalidArgument: (:) [ForEach-Object], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ForEachObjectCommand

Thanks in advance!

May 4, 2011 at 4:12 PM
Edited May 4, 2011 at 4:14 PM

It'd help if you post that part of the script.

For computer, all you need is the computer name, but you may not be putting it in the right place:

Get-SCSNIncident -ID $ID -ComputerName myscsmserver | ...
May 4, 2011 at 6:10 PM

it looks like this is the pipeline you're trying to run:
$incident = Get-SCSMIncident -ID $ID | %{ $_.Object} -Computername -computername

which is the same as:
$incident = Get-SCSMIncident -ID $ID | foreach-object { $_.Object} -Computername -computername

this means that you are attempting to assign -ComputerName parameter to the foreach-object cmdlet which won't work. If you need to use Get-SCSMIncident with a remote system, be sure that you provide the computername parameter.

Get-SCSMIncident -ComputerName <name> . . .

May 5, 2011 at 7:01 AM

Hi guys,

Thanks for your replys! i managed to fix it with jtruher his reply.

$incident = Get-SCSMIncident -ID $ID | foreach-object { $_.Object} -Computername -computername

had to be

$incident = Get-SCSMIncident -Computername -computername -ID $ID | foreach-object { $_.Object}

It was in the wrong order :(