Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Understanding $_

$
0
0

I have this code I got off of this very site that works.  It will add double quotes around each item it reads.

 

Get-Content c:\reports\Quotes\machines.txt | foreach { "'$_'" } | Out-File c:\reports\DMS.txt

 

Ok, we have 

Get-Content c:\reports\Quotes\machines.txt        so we read in each line.

 

Then we have this:

 foreach { "'$_'" }       I understand that it says "for each current object" but how/why does it add double quotes around each object?    I see nothing that says for each object wrap it in quotes.   All I see is double quotes on either side of the $_ current object.  So that adds themby why?   It is not intuitive to me at all

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles