Last active
May 27, 2022 12:03
-
-
Save fvilante/d6381b4d3c883c9277d93514acb9d26e to your computer and use it in GitHub Desktop.
powershell tips and tricks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Get help | |
Get-Help Sort-Object | |
#Old dir | |
dir | |
Get-ChildItem | |
Get-ChildItem *.txt | |
Get-ChildItem -Directory | |
Get-ChildItem -File | |
#dir recursive | |
Get-ChildItem -Recurse | |
Get-ChildItem -Recurse -Depth 2 | |
#Show content inside a file | |
Get-Content c:\filename | |
cat #alias to Get-Content | |
#For each object, replace content, write to a new file | |
Get-Content .\.gitignore | ForEach-Object {$_.ToString().Replace('.idea','.idea do flavio')} | Set-Content 'juca_temp.txt' | |
#Pipe: Show the content of txt files in current directory | |
Get-ChildItem *.txt | Get-Content | |
#Where-Object | |
$exclude = @(".cs", ".tt", ".xaml", ".csproj", ".sln", ".xml", ".cmd", ".txt") | |
Get-ChildItem -Path $path -Recurse | Where-Object { $exclude -notcontains $_.Extension } | |
dir -r -Directory | ? {$_.fullname -notlike "*node_modules*"} | |
#Save in a variable | |
$a = Get-ChildItem | |
#ForEach-Object | |
$b = Get-ChildItem | ForEach-Object {$_.fullname} | |
#List only some files recursive | |
$exclude = @(".cs", ".tt", ".xaml", ".csproj", ".sln", ".xml", ".cmd", ".txt") | |
Get-ChildItem -Path $path -Recurse | Where-Object { $exclude -notcontains $_.Extension } | |
#Select-String | |
$c = $b | Select-String 'tsconfig' | |
# | |
#aliases for DOS and Linux command-line | |
Get-Alias | |
#Select a string | |
# Using Get-childItem to get a list of files modified in last 3 days | |
(Get-ChildItem -Path c:\pstbak\*.* -Filter *.pst | ? { | |
$_.LastWriteTime -gt (Get-Date).Date.AddDays(-3) | |
}).Count | |
# List files by extensions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Procurar por clientes que usam 2 eixos micro