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

Reply To: Issue reading a file into an inventory script

$
0
0

So, perhaps you're actually having a "problem" rather than an "issue," but you don't indicate what that problem is.

Assuming you have a CSV file with a computername column…

ComputerName,Whatever,Something
SERVER1,Blah,Bleh
SERVER2,Foo,Bar

If you define your parameter accept pipeline input by property name…

[Parameter(ValueFromPipelineByPropertyName=$True)][string[]]$ComputerName

Then you can…

Import-CSV myfile.csv | Get-CompInfo | Export-CSV myoutput.csv

However, your function's code needs to be inside a PROCESS block, not a BEGIN block as you have it. Functions that accept pipeline input must process that input in PROCESS; the BEGIN block executed prior to pipeline parameter binding occurring.

You have some other problems. First, Win32_LogicalDisk, and possibly Win32_VideoController, can return multiple objects. You aren't properly dealing with that, so you're open to unexpected output. For example, you can't do math on the Size property when $disk has more than one object in it.


Viewing all articles
Browse latest Browse all 13067

Trending Articles