Hostname Learning

Why when I query something like a csv or use get-content on a text file with a list of hostnames does the subsequent command choke on headers and such?

Example:
I wanted to run something like #invoke-command -computername (Get-content C:\somefile.txt) -scriptblock {get-process}

Instead I had to take the variable that I had make “somefile.txt” with and do the following top it

foreach($i in $pclist) {$tryme = $tryme + $i.Hostname}

Now #invoke-command -computername $tryme -scriptblock {get-process} is working fine

What’s up with that?

I’d say it depends pretty much on what’s in your C:\somefile.txt. When I try

invoke-command -computername (Get-content C:\somefile.txt) -scriptblock {get-process}
it works just as expected.

Any chance you could share how the data in your textfile is formatted?
Like Olaf says it may have more to do with the data than the invoke command.

If you’re using Import-CSV to read a CSV, it’ll handle the headers for you.

If not, it’s easier to use something like…

Get-Content data.txt | Select -Skip 1

To skip the first line.

I have found that if I run something like

I typically work in an environments between 30-100 workstations per domain.

Get-ADComputer -filter * | Out-file C:\something.txt

I then need to strip out (or skip, forgot about that - thanks Don!) the top two lines or export it as a csv.

This certainly isn’t show stopped just an oddity I have noticed.

I’ll try to make a sample file and post it later!

Thank-you for taking the time to look at this, everybody!