PowerShell

更新日 2025-03-20 (木) 08:37:49

フォルダごとの容量表示

PS > (Get-ChildItem c:\inetpub -recurse -force |  Select-Object   Fullname,Length  | Sort-Object Lengt -descending )[0..10]

FullName                                                                 Length
--------                                                                 ------
C:\inetpub\logs\LogFiles\W3SVC2\u_ex141108.log                         32456825
C:\inetpub\logs\LogFiles\W3SVC2\u_ex141025.log                         32277852
C:\inetpub\logs\LogFiles\W3SVC2\u_ex141109.log                         31886503
C:\inetpub\logs\LogFiles\W3SVC2\u_ex141208.log                         31823243
C:\inetpub\logs\LogFiles\W3SVC2\u_ex141207.log                         31813949
C:\inetpub\logs\LogFiles\W3SVC2\u_ex141209.log                         31804347
C:\inetpub\logs\LogFiles\W3SVC2\u_ex141211.log                         31797162
C:\inetpub\logs\LogFiles\W3SVC2\u_ex141201.log                         31781543
C:\inetpub\logs\LogFiles\W3SVC2\u_ex141004.log                         31780594
C:\inetpub\logs\LogFiles\W3SVC2\u_ex141206.log                         31776803
C:\inetpub\logs\LogFiles\W3SVC2\u_ex141210.log                         31776425

無名ハッシュテーブル(連想配列)について

ファイルの中の様子

無名ハッシュテーブルは配列のようになっている。
Driver.png の中のLastWriteTimeは配列で中に要素がある

PS F:\RemoteDrive\temp> dir Driver.png | select *


PSPath            : Microsoft.PowerShell.Core\FileSystem::F:\RemoteDrive\temp\D river.png
PSParentPath      : Microsoft.PowerShell.Core\FileSystem::F:\RemoteDrive\temp
PSChildName       : Driver.png
PSDrive           : F
PSProvider        : Microsoft.PowerShell.Core\FileSystem
PSIsContainer     : False
Mode              : -a----
VersionInfo       : File:             F:\RemoteDrive\temp\Driver.png
                    InternalName:
                    OriginalFilename:
                    FileVersion:
                    FileDescription:
                    Product:
                    ProductVersion:
                    Debug:            False
                    Patched:          False
                    PreRelease:       False
                    PrivateBuild:     False
                    SpecialBuild:     False
                    Language:

BaseName          : Driver
Target            : {}
LinkType          :
Name              : Driver.png
Length            : 116395
DirectoryName     : F:\RemoteDrive\temp
Directory         : F:\RemoteDrive\temp
IsReadOnly        : False
Exists            : True
FullName          : F:\RemoteDrive\temp\Driver.png
Extension         : .png
CreationTime      : 2021/01/20 9:22:54
CreationTimeUtc   : 2021/01/20 0:22:54
LastAccessTime    : 2021/10/13 15:01:10
LastAccessTimeUtc : 2021/10/13 6:01:10
LastWriteTime     : 2021/01/20 9:47:46
LastWriteTimeUtc  : 2021/01/20 0:47:46
Attributes        : Archive

LastWriteTime.DayOfWeekを表示する

以下は無名ハッシュテーブルLastWriteTimeキーDayOfWeekを表示Youbiに表示している

PS F:\RemoteDrive\temp> dir *.png | select Name, LastWriteTime, @{Name = "Youbi"; Expression = {$_.LastWriteTime.DayOfWeek}}

Name                        LastWriteTime           Youbi
----                        -------------           -----
Azureモジュールでの接続.png 2022/03/14 12:12:32    Monday
Driver.png                  2021/01/20 9:47:46  Wednesday
NIC認識1.png                2021/01/20 9:47:30  Wednesday
PS F:\RemoteDrive\temp> dir *.png | select Name, LastWriteTime, @{N = "Youbi"; E = {$_.LastWriteTime.DayOfWeek}}        
Name                        LastWriteTime           Youbi
----                        -------------           -----
Azureモジュールでの接続.png 2022/03/14 12:12:32    Monday
Driver.png                  2021/01/20 9:47:46  Wednesday
NIC認識1.png                2021/01/20 9:47:30  Wednesday

包含演算子

-contains: コレクションに指定した値が含まれている
PS F:\RemoteDrive\temp> "abc" -contains "abc"
True
PS F:\RemoteDrive\temp> "abc" -contains "ab"
False
PS F:\RemoteDrive\temp> "abc" -contains "abcd"
False

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS