Yanor.net/
Wiki
Blog
GitHub
Sandbox
開始行:
* dirコマンドの出力をカスタマイズ [#j2493594]
** 目的 [#mbc4864f]
- dirコマンドの出力は標準では以下のようになる。
- ここではLengthの代わりにFileSizeという新しいファイルサ...
- FileSizeは新しいType Dataで、1000バイトなら1KBと表示す...
ディレクトリ: C:\tmp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2017/02/12 19:22 4750 bar.txt
-a---- 2017/02/12 19:22 0 foo.txt
-a---- 2015/11/14 22:45 81711 baz.jpg
** 手順 [#n2d15e4d]
*** 1. Type Dataを作成する [#a9c54a9a]
copy $PSHOME\Types.ps1xml $Env:USERPROFILE\Documents\Win...
notepad $Env:USERPROFILE\Documents\WindowsPowershell\MyT...
Update-TypeData -PrependPath $Env:USERPROFILE\Documents\...
- システム標準のTypes.ps1xmlをマイドキュメント以下にコピ...
- 編集が終わったら、ロードする。
- Get-ChildItem | Format-Table -Property Name, Length, Fi...
<?xml version="1.0" encoding="utf-8" ?>
<Types>
<Type>
<Name>System.IO.FileInfo</Name>
<Members>
<ScriptProperty>
<!-- Filesize converts the length to a h...
format (kb, mb, gb, tb) -->
<Name>FileSize</Name>
<GetScriptBlock>
switch($this.length) {
{ $_ -gt 1tb }
{ "{0,4:n2} TB" -f ($_ / 1tb...
{ $_ -gt 1gb }
{ "{0,4:n2} GB" -f ($_ / 1gb...
{ $_ -gt 1mb }
{ "{0,4:n2} MB " -f ($_ / 1m...
{ $_ -gt 1kb }
{ "{0,4:n2} KB " -f ($_ / 1K...
default
{ "{0,4} B " -f $_}
}
</GetScriptBlock>
</ScriptProperty>
</Members>
</Type>
</Types>
** 2. FileSystemのフォーマットファイルを修正 [#f138fe36]
copy $PSHOME\FileSystem.format.ps1xml $Env:USERPROFILE\D...
notepad $Env:USERPROFILE\Documents\WindowsPowershell\MyF...
Update-FormatData -PrependPath $Env:USERPROFILE\Document...
- システム標準のFileSystem.format.ps1xmlをマイドキュメン...
- 編集が終わったら、ロードする。
*** [#od3a3037]
** 参考 [#o5057c40]
http://superuser.com/questions/468782/show-human-readable...
終了行:
* dirコマンドの出力をカスタマイズ [#j2493594]
** 目的 [#mbc4864f]
- dirコマンドの出力は標準では以下のようになる。
- ここではLengthの代わりにFileSizeという新しいファイルサ...
- FileSizeは新しいType Dataで、1000バイトなら1KBと表示す...
ディレクトリ: C:\tmp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2017/02/12 19:22 4750 bar.txt
-a---- 2017/02/12 19:22 0 foo.txt
-a---- 2015/11/14 22:45 81711 baz.jpg
** 手順 [#n2d15e4d]
*** 1. Type Dataを作成する [#a9c54a9a]
copy $PSHOME\Types.ps1xml $Env:USERPROFILE\Documents\Win...
notepad $Env:USERPROFILE\Documents\WindowsPowershell\MyT...
Update-TypeData -PrependPath $Env:USERPROFILE\Documents\...
- システム標準のTypes.ps1xmlをマイドキュメント以下にコピ...
- 編集が終わったら、ロードする。
- Get-ChildItem | Format-Table -Property Name, Length, Fi...
<?xml version="1.0" encoding="utf-8" ?>
<Types>
<Type>
<Name>System.IO.FileInfo</Name>
<Members>
<ScriptProperty>
<!-- Filesize converts the length to a h...
format (kb, mb, gb, tb) -->
<Name>FileSize</Name>
<GetScriptBlock>
switch($this.length) {
{ $_ -gt 1tb }
{ "{0,4:n2} TB" -f ($_ / 1tb...
{ $_ -gt 1gb }
{ "{0,4:n2} GB" -f ($_ / 1gb...
{ $_ -gt 1mb }
{ "{0,4:n2} MB " -f ($_ / 1m...
{ $_ -gt 1kb }
{ "{0,4:n2} KB " -f ($_ / 1K...
default
{ "{0,4} B " -f $_}
}
</GetScriptBlock>
</ScriptProperty>
</Members>
</Type>
</Types>
** 2. FileSystemのフォーマットファイルを修正 [#f138fe36]
copy $PSHOME\FileSystem.format.ps1xml $Env:USERPROFILE\D...
notepad $Env:USERPROFILE\Documents\WindowsPowershell\MyF...
Update-FormatData -PrependPath $Env:USERPROFILE\Document...
- システム標準のFileSystem.format.ps1xmlをマイドキュメン...
- 編集が終わったら、ロードする。
*** [#od3a3037]
** 参考 [#o5057c40]
http://superuser.com/questions/468782/show-human-readable...
ページ名: