Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Pass Array as Argument

$
0
0

I have a script called SetConnectionTypeToManual.psm1 and a list of systems in NodeList.txt.

I want to store the contents of NodeList.txt in an array and pass the array as parameter to a function in SetConnectionTypeToManual.psm1. (i.e., run SetConnectionTypeToManual.psm1 -NodeList)

 

SetConnectionTypeToManual.psm1 contains:

 

param

(

[array]$NodeList = Get-Content NodeList.txt

)



function SetConnectionTypeToManual


{


foreach ($node in $NodeList)


{

#CodeThatWillSetConnectionTypeToManual

#Using Write-Host for testing

Write-Host $Node

}


}


SetConnectionTypeToManual -NodeList



But running SetConnectionTypeToManual.psm1 -NodeList errors with:

 

Documents\Tools\Scripts\Powershell\ScriptRock\SetConnectionTypeToManual.ps1:4

char:20

+     [array]$NodeList = Get-Content NodeList.txt

+    Missing expression after         ~


Any ideas how to pass the contents of NodeList.txt to this function as an array? 


Viewing all articles
Browse latest Browse all 6937

Trending Articles