Using Get-Content


hi all, i'm trying write ps script read file , give me result lines of filtering whole file.

i'm trying this code:

$testo = get-content c:\myfile.txt | {$_ -like "*word*"}
foreach-object {$line in $testo -replace(";" , ","}

i receive thi error:
+ foreach-object {$line in <<<<  $testo -replace (";" , ","}
    + categoryinfo          : parsererror: (in:string) [], parentcontainserrorrecordexception
    + fullyqualifiederrorid : unexpectedtoken

how can corret instruction ?
sorry i'm newbie using powershell :-(

 

you can/should able use 'where' filter foreach, long it's piped, mjolinor kind of hinted to. 
(ex.: get-content users.txt | where{$_ -like *@domain.com} | foreach-object{set-user -windowsemailaddress $null})

it should highly important note, though, trailing or leading blank/white spaces cause powershell throw error, because ' ' character still character , powershell treat literal, in object. (ex: 'somestuff' -ne 'somestuff ')

 

  get-content "c:\myfile.txt" | where{$_ -like "word"} | foreach-object{($line in $testo) -replace(";",",")}  



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Error: 0x80073701 when trying to add Print Services Role in Windows 2012 Standard

Disconnecting from a Windows Server 2012 R2 file sharing session on a Windows 7,8,10 machine

Event ID 64,77,1008 Certificates Events Windows Server 2008, 2008R2