PowerShell: Difference between revisions
Comparison with Linux commands Tag: visualeditor |
mNo edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
P> Test-NetConnection -ComputerName island.doodle.com -Port 443 | P> Test-NetConnection -ComputerName island.doodle.com -Port 443 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Search files == | == Search files == | ||
Line 9: | Line 10: | ||
PS C:\Users\MHan> Get-ChildItem -Recurse -Include *.* | Select-String "text to search for" | PS C:\Users\MHan> Get-ChildItem -Recurse -Include *.* | Select-String "text to search for" | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Check version == | == Check version == | ||
<syntaxhighlight lang="powershell"> | <syntaxhighlight lang="powershell"> | ||
PS C:\Users\MHan> $ | PS C:\Users\MHan> $PSVersionTable | ||
Name Value | Name Value | ||
Line 26: | Line 28: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Remove a folder and everything underneath == | |||
<syntaxhighlight lang="powershell"> | |||
P> Remove-Item -Path "C:\Users\micha\testing" -Recurse -Force | |||
</syntaxhighlight> | |||
== Comparison with Linux commands == | == Comparison with Linux commands == | ||
{| class="wikitable" | {| class="wikitable" | ||
|+ | |+ | ||
!Action | !Action | ||
!Linux | |||
!PowerShell | !PowerShell | ||
|- | |- | ||
|Search for a string | |Search for a string 1 | ||
|<nowiki>az keyvault list | | |<code><nowiki>az keyvault list | grep -i 'name";'</nowiki></code> | ||
|<nowiki>az | |<code><nowiki>az keyvault list | findstr -i 'name":'</nowiki></code> | ||
|- | |||
|Search for a string 2 - current folder and subfolders | |||
|<code><nowiki>find . | xargs grep -si "searchtext"</nowiki></code> | |||
|<code><nowiki>Get-ChildItem -Path "." -Recurse -File | Select-String -Pattern "searchtext"</nowiki></code> | |||
|- | |||
|Search for a string 3 - only list names of files | |||
|<code><nowiki>find . | xargs grep -sil "searchtext"</nowiki></code> | |||
|<code><nowiki>Get-ChildItem -Path "." -Recurse -File | Select-String -Pattern "searchtext" -List | Select-Object -Property Path</nowiki></code> | |||
|- | |- | ||
|Alias a command | |Alias a command | ||
| | |<code>alias g grep</code> | ||
|alias | |<code>new-alias grep findstr</code> | ||
|} | |} |
Latest revision as of 17:46, 27 August 2024
Check for an open port
P> Test-NetConnection -ComputerName island.doodle.com -Port 443
Search files
PS C:\Users\MHan> Get-ChildItem -Recurse -Include *.* | Select-String "text to search for"
Check version
PS C:\Users\MHan> $PSVersionTable
Name Value
---- -----
PSVersion 5.0.10586.1417
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.10586.1417
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Remove a folder and everything underneath
P> Remove-Item -Path "C:\Users\micha\testing" -Recurse -Force
Comparison with Linux commands
Action | Linux | PowerShell |
---|---|---|
Search for a string 1 | az keyvault list | grep -i 'name";'
|
az keyvault list | findstr -i 'name":'
|
Search for a string 2 - current folder and subfolders | find . | xargs grep -si "searchtext"
|
Get-ChildItem -Path "." -Recurse -File | Select-String -Pattern "searchtext"
|
Search for a string 3 - only list names of files | find . | xargs grep -sil "searchtext"
|
Get-ChildItem -Path "." -Recurse -File | Select-String -Pattern "searchtext" -List | Select-Object -Property Path
|
Alias a command | alias g grep
|
new-alias grep findstr
|