0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Powershell - 良く使っているコマンドレットまとめ中

Last updated at Posted at 2016-07-10

カレントディレクトリ配下のテキストファイル内の文字列を検索

function Search-StringAllFiles{
    param(
        [parameter(mandatory)][string]$Pattern,
		[string[]]$Exclude = @("*.exe","*.dll","*.xlsx","*.xlsm","*.ppt","*.docx","*.jar","*.zip")
    )
	Get-ChildItem -Recurse -Exclude $Exclude | Select-String $Pattern
}
Set-Alias grep Search-StringAllFiles

カレントディレクトリ配下のディレクトリサイズを一括取得

function Get-DirectorySize{
Get-ChildItem -Force -Directory `
    | Select-Object Name, @{ name = "Size(MB)"; expression = { `
            [math]::round((Get-ChildItem $_.FullName -Recurse -Force `
                | Measure-Object Length -Sum `
            ).Sum /1MB ) `
    } }
}
Set-Alias ds Get-DirectorySize

カレントディレクトリのファイル名を一括置換

function Rename-AllFiles{
    param(
        [parameter(mandatory)][string]$search,
        [parameter(mandatory)][string]$replace
    )
    Get-ChildItem -File | %{ $newname = $_.Name -replace $search,$replace; Rename-Item $_ $newname }
}
Set-Alias rn Rename-AllFiles
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?