Windows PowerShell Cookbook: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
[[Category:Powershell]] [[Category:Windows]] | [[Category:Powershell]] [[Category:Windows]] | ||
== Download content from the web == | == Fetching remote content == | ||
=== Download content from the web === | |||
This will print out the markup from the index page (which could then be piped through additional commands): | This will print out the markup from the index page (which could then be piped through additional commands): | ||
| Line 57: | Line 59: | ||
> gci -rec | > gci -rec | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Environment variables == | |||
Displaying, creating, and modifying environment variables using Powershell CLI.<ref>[https://technet.microsoft.com/en-us/library/ff730964.aspx Creating and Modifying Environment Variables] - Microsoft TechNet</ref> | |||
=== List all environment variables === | |||
<syntaxhighlight lang="powershell"> | |||
> Get-ChildItem Env: | |||
> # (or using gci alias...) | |||
> gci env: | |||
</syntaxhighlight> | |||
== Notes == | |||
<references /> | |||
Revision as of 18:53, 30 November 2015
Fetching remote content
Download content from the web
This will print out the markup from the index page (which could then be piped through additional commands):
> (new-object Net.WebClient).DownloadString("http://damienjay.com/")
Grep/Searching the content of files
Files in a single directory
> select-string .\*.* -pattern "\my_regexp\"
Recursive search
> gci path\to\search\root\ -rec | select-string -pattern "\my_regexp\"
Recursive search filtered by file type
> Get-ChildItem path\to\search\root\ -include *.txt -rec | select-string -pattern "\my_regexp\" > # or, using aliases for the commands and not using "-include" ... > gci path\to\search\root\ *.txt -r | sls -pattern "\my_regexp\"
List directory contents
Fun Things You Can Do With the Get-ChildItem Cmdlet (Microsoft TechNet)
> Get-ChildItem .\ > # or... > gci .\ > # or... > gci # for the current directory
Limit listing to file names
> gci path\to\directory | Select-Object Name > # or... > Get-ChildItem path\to\directory -name
Recursive listing
> gci -recursive > # or... > gci -rec
Environment variables
Displaying, creating, and modifying environment variables using Powershell CLI.[1]
List all environment variables
> Get-ChildItem Env: > # (or using gci alias...) > gci env:
Notes
- ↑ Creating and Modifying Environment Variables - Microsoft TechNet