Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Clarification on computer name parameter

$
0
0

You gotta avoid pasting out of “rich” apps, which includes the ISE I think. :) They end up pasting HTML. That’s where your extra SPAN tag came from in your post. LMK what you pasted from – I’d like to post a clearer warning about that for other folks. You can also paste into the TEXT tab of the editor, which makes it a lot clearer what’s happening, instead of the VISUAL editor tab.

Yes it was the ISE.  Good to know for future.

So, you may have things a bit mixed up. I’m not sure, so I’ll just cover all the bits. First, YOUR parameter could be $fred. It doesn’t NEED to be $ComputerName. You only use $ComputerName because that’s consistent with the way the shell works. I just want to make sure you’re clear on that. This is also legal:
<pre class=”d4pbbc-pre”>param([string]$purple)

get-wmiobject -class win32_bios -computername $purple
There doesn’t need to be a “match.” Also, your code isn’t quite set up well to work against multiple computers – it will, but it’ll be harder to capture errors.
<pre class="d4pbbc-pre">param([string[]]$computername)

foreach ($bozo in $computername)

$a = Get-WmiObject Win32_OperatingSystem -ComputerName $bozo

}
Would be a better pattern. You cannot just tack on a -ComputerName parameter to a command – like Set-ItemProperty – which does not natively support that parameter. You’re correct on that. Just because YOUR script has a -ComputerName parameter doesn’t confer the ability to any command contained within the script.

Got it thanks Don.  This clarifies things for me nicely.


Viewing all articles
Browse latest Browse all 13067

Trending Articles