Microsoft Virtualization Discussions

Get-Content Add-Content

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




Re: Get-Content Add-Content

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

Re: Get-Content Add-Content

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



Re: Get-Content Add-Content

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"




Re: Get-Content Add-Content





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

Cloud Volumes ONTAP
Review Banner
All Community Forums