Author Posts

July 25, 2018 at 3:47 am

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?

July 25, 2018 at 7:51 am

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.

July 25, 2018 at 8:17 am

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.

July 25, 2018 at 1:13 pm

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.

July 28, 2018 at 1:15 am

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!