In Linux and Unix world when we want to grab a line that contains specific output we would just use the following command:
command | grep search
In powershell to do the same thing we use this command:
command | ls *search*
For example we run the following command to list a whole bunch of output for:
Get-AcceptedDomain
We want to to identify all lines that have the word "Name" in it. Run the following command:
Get-AcceptedDomain | fl *name*
Very easy.
Wednesday, September 15, 2010
Subscribe to:
Post Comments (Atom)
'get-windowsfeatures | fl *framework*' results in a lot of blank lines.
ReplyDelete'get-windowsfeatures | ls *framework*' results in a lot of errors.
Same here. Any idea how to get this working?
ReplyDeleteFirstly, that's an EXCHANGE PowerShell, which has different plugins and modules available to it, but the command (Format-List) is in both.
ReplyDeleteSome commands operate on Objects, and some operate on text. The Get-AcceptedDomain command outputs objects, which the Format-List or Get-Item (ls) command work on. Using it to parse text from the output doesn't work, but parsing objects should (or something like that).
Not helpful. Perhaps you could give more detail/explanation. I came here visiting: http://social.msdn.microsoft.com/Forums/en/windowssdk/thread/592ea672-1c3d-40ce-8669-59148d3b6e3f
ReplyDeleteYeah, how do I do this in powershell?
ReplyDeletegrep search_string dir/*/subdir/file.txt
"Anonymous said...
ReplyDelete'get-windowsfeatures | fl *framework*' results in a lot of blank lines.
'get-windowsfeatures | ls *framework*' results in a lot of errors."
try
$r = get-windowsfeature
then
$r | get-member
and look at column Name (where MemberType is Property) idea, right?
and, finally, we get, for example
Get-WindowsFeature | Where-Object {$_.DisplayName -like '*active directory*'}
hope this help,
wbr
> Yeah, how do I do this in powershell?
ReplyDelete> grep search_string dir/*/subdir/file.txt
What has worked for me this morning is:
more dir/*/subdir/file.txt | select-string search_string
I don't understand why it is so much less usable than the unix equivalent though.
Install Cygwin
ReplyDeletecommand | select-string -pattern "texttofind"
ReplyDeleteless usable? its only different.
ReplyDeletehah, check out this powershell problem.
ReplyDeleteecho blah > asdf.txtt
Get-Content .\*.txtt | select-string blah > asdf2.txtt
you'll see asdf.txtt is small, but asdf2.txtt never stops growing until you kill the command, as it feeds back into itself, unlike grep.
and there seems to be several different ways, ls, fl, and now select-string, which may work or not. I don't need to know to use ls, fl, nor select-string when used in combination with this or that command, grep just works.
Deletehow to convert this unix cmd (grep -v "^Enter" 123.imp > 321.imp) to powershell
ReplyDelete