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

Clarification on computer name parameter

$
0
0

I just want to make sure that I understand this correctly and am not missing anything.

<span style=”font-size: 13px;”>

</span>

param(

[string]$computername = ‘localhost’

)

$a = get-WmiObject -Class win32_operatingsystem -ComputerName $computername

$b = Get-WmiObject -Class win32_computersystem -ComputerName $computername

Obviously the above code is not complete.  Once complete I could run the script and pass in the computername parameter and have it run against remote computers.  Is it correct that I can only pass the computername parameter into this script because the commands the script utilizes depend on the -computername parameter?

For example, this would not work:


param(

[string]$computername = ‘localhost’

)

$a = set-itemproperty -path c:\GroupFiles\final.doc -name IsReadOnly -value $true  -ComputerName $computername

$b = New-Item c:\hello -ComputerName $computername

If I ran the above ./script1.ps1 -computername win8 , it would not work because the commands in the script do not accept the -computername parameter.  Is that right?


Viewing all articles
Browse latest Browse all 13067

Trending Articles