Function @ Invoke-Command

Team,

I wrote a local function, and calling it inside invoke-command for executing it @ remote system. Also that function need a parameter called computername and I am supplying that through agr parameter. Everything works fine. But I need someyhing more. I m feeding a csv to my script, from there I m getting computer names and using foreach, I am invoking that function. That CSV file contains few static data which is also required by that function. Right now my function works fine by not showing those static data. I know that my local variable is not available @ remote pc, but I m unable to feed it properly. Following is the few portion of my script.

[pre]

$result = icm ${function:create-report} - argu $dc.Hostname -cn dc012 -credential $cred

[/pre]

As you can see $dc is the dynamic variable from foreach. Now how can I send this variable to that remote server.

The function was written like it will read few cells from the $dc.

The function is creating a hashtable. Following is a sample.

[pre]

$tbl= @{

‘Hostname’ = $dc.fqdn

‘ipv4’ = $ip

‘Role’ = $dc.role

‘Site’ = (get-addomaincontroller -server $computername).site

}

[/pre]

As per the sample, that function is able to create the hashtable with ip and site value, but other two are left blank.

Could you plz help me by guiding how I can solve that.

Regards

Roy.

We need to see you function. The function should have a parameter to accept $DC object. Whatever passed to -ArgumentList parameter of Invoke-Command will be bound to Parameter of the ScriptBlock, here its the function definition.

[quote quote=146375]We need to see you function. The function should have a parameter to accept $DC object. Whatever passed to -ArgumentList parameter of Invoke-Command will be bound to Parameter of the ScriptBlock, here its the function definition.

[/quote]
Thanks a lot Prasoon. Your few words clear my doubt/concept. I solved it. As mentioned I did some tweaks on my function by specyfing dc variable and the default value.

Now its working perfectly as expected…

Again thanks a lot…