Microsoft Virtualization Discussions

Get-Content Add-Content

JSHACHER11

Hi guys,

 

I am trying to pull data from one file to another

 

This works fine:

 

gc "c:\file1.txt" | ? {$_ -match "lun:/vol/"} | Add-Content "c:\file2.txt"

 

but this fails:

 

$source = Read-Host "enter full path to source file"
$dest = Read-Host "enter full path to destination file"

 

gc $source | ? {$_ -match "lun:/vol/"} | Add-Content $dest

 

 

 

Get-Process : A positional parameter cannot be found that accepts argument 'gc'.
At C:\perf_file.ps1:11 char:3
+ PS <<<< C:\> gc $source | ? {$_ -match "lun:/vol/"} | Add-Content $dest
+ CategoryInfo : InvalidArgument: (:) [Get-Process], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetProcessCommand

 

 

what am I doing wrong?

 

Thank you

 

Joel

4 REPLIES 4

JGPSHNTAP

I need a little more informatoin .. whats in the file.. Second what is your ultimate goal?

JSHACHER11

it's just a text file with performance information

 

for example, the file contains a lot of lines about 'volume' stats and I want to take only the lines that say 'read_align_histo' and put it in a different file

 

like I said, it works fine, it's just when I use the 'Read-Host' that it fails

 

Cheers

vinith

Hello Joel,

 

Can you use the Get-Content cmdlet name itself in place of "gc", also please check if the alias is pointing to get-process.

 

This is how the the output for the alias gc should show up

 

PS C:\> Get-Alias -Name gc

CommandType Name ModuleName
----------- ---- ----------
Alias gc -> Get-Content

 

I tried it in my lab and it worked fine, i guess there is some issue with the alias redirecting itself to "Get-Process"

 

Thanks,

Vinith

JSHACHER11

 

 

apologies!

 

my fault. my script was like this:

 

PS C:> gc ...

 

instaed of:

 

gc ..

 

 

POSH didn't know how to read the 'PS' (obviously)

 

Smiley Embarassed

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public