PowerShell/ハッシュの配列を表形式(Format-Table)で表示する方法
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
* ハッシュの配列を表形式(Format-Table)で表示する方法 [#i6...
ハッシュに同じキーで各種値を設定した情報を配列で持ってい...
#contents
#htmlinsertpcsp(win-top.html,win-sp.html)
* 関連記事 [#s7766e5e]
-[[ハッシュ(連想配列)の要素をforeachで表示するサンプルコ...
-[[PowerShellでハッシュ(連想配列)に要素を追加する>PowerSh...
-[[PowerShellでCSVファイルのインポート>PowerShell/CSVファ...
-[[配列やハッシュの各値を要素としたループのサンプル>Power...
-[[PowerShellで配列内の文字列を連結し1つの変数に格納した...
-[[ハッシュの配列を表形式(Format-Table)で表示する方法>Pow...
* PSCustomObjectを使用する [#saa3c76b]
以下の通り、実際にハッシュ変数の配列変数作成し、表形式で...
+ハッシュ変数の配列を準備~
以下のように、ハッシュの配列を作成します。
$hls = (
@{Distribution="Ubuntu"; ostype="Linux"; base="Debian"},
@{Distribution="Debian"; ostype="Linux"; base="Independ...
@{Distribution="Red Hat Enterprise Linux"; ostype="Linu...
@{Distribution="FreeBSD"; ostype="BSD"; base="Independe...
@{Distribution="TrueOS"; ostype="BSD"; base="FreeBSD"},
@{Distribution="OpenBSD"; ostype="BSD"; base="Independe...
)
+ 上記の構文を実際にPowerShell上で実行したときの出力です。~
上記でハッシュの配列を格納した$hls変数を確認のため表示さ...
PS C:\> $hls = (
>> @{Distribution="Ubuntu"; ostype="Linux"; base="Debi...
>> @{Distribution="Debian"; ostype="Linux"; base="Inde...
>> @{Distribution="Red Hat Enterprise Linux"; ostype="...
>> @{Distribution="FreeBSD"; ostype="BSD"; base="Indep...
>> @{Distribution="TrueOS"; ostype="BSD"; base="FreeBS...
>> @{Distribution="OpenBSD"; ostype="BSD"; base="Indep...
>> )
PS C:\> $hls
Name Value
---- -----
Distribution Ubuntu
ostype Linux
base Debian
Distribution Debian
ostype Linux
base Independent
Distribution Red Hat Enterprise Linux
ostype Linux
base Fedora
Distribution FreeBSD
ostype BSD
base Independent
Distribution TrueOS
ostype BSD
base FreeBSD
Distribution OpenBSD
ostype BSD
base Independent
+PSCustomObjectを使って、表形式にします。
$fls = $hls | % { New-Object PSCustomObject -Property $_ }
+ 上記の構文を実際にPowerShell上で実行したときの出力です。
PS C:\> $fls = $hls | % { New-Object PSCustomObject -Pro...
PS C:\> $fls
Distribution ostype base
------------ ------ ----
Ubuntu Linux Debian
Debian Linux Independent
Red Hat Enterprise Linux Linux Fedora
FreeBSD BSD Independent
TrueOS BSD FreeBSD
OpenBSD BSD Independent
+ Format-TableのPropertyに項目名を指定すれば、指定した項...
PS C:\> $fls | Format-Table -Property Distribution, base
Distribution base
------------ ----
Ubuntu Debian
Debian Independent
Red Hat Enterprise Linux Fedora
FreeBSD Independent
TrueOS FreeBSD
OpenBSD Independent
以上、ハッシュの配列を表形式で表示する方法でした。
#htmlinsertpcsp(win-btm.html,win-sp.html)
終了行:
#navi(../)
* ハッシュの配列を表形式(Format-Table)で表示する方法 [#i6...
ハッシュに同じキーで各種値を設定した情報を配列で持ってい...
#contents
#htmlinsertpcsp(win-top.html,win-sp.html)
* 関連記事 [#s7766e5e]
-[[ハッシュ(連想配列)の要素をforeachで表示するサンプルコ...
-[[PowerShellでハッシュ(連想配列)に要素を追加する>PowerSh...
-[[PowerShellでCSVファイルのインポート>PowerShell/CSVファ...
-[[配列やハッシュの各値を要素としたループのサンプル>Power...
-[[PowerShellで配列内の文字列を連結し1つの変数に格納した...
-[[ハッシュの配列を表形式(Format-Table)で表示する方法>Pow...
* PSCustomObjectを使用する [#saa3c76b]
以下の通り、実際にハッシュ変数の配列変数作成し、表形式で...
+ハッシュ変数の配列を準備~
以下のように、ハッシュの配列を作成します。
$hls = (
@{Distribution="Ubuntu"; ostype="Linux"; base="Debian"},
@{Distribution="Debian"; ostype="Linux"; base="Independ...
@{Distribution="Red Hat Enterprise Linux"; ostype="Linu...
@{Distribution="FreeBSD"; ostype="BSD"; base="Independe...
@{Distribution="TrueOS"; ostype="BSD"; base="FreeBSD"},
@{Distribution="OpenBSD"; ostype="BSD"; base="Independe...
)
+ 上記の構文を実際にPowerShell上で実行したときの出力です。~
上記でハッシュの配列を格納した$hls変数を確認のため表示さ...
PS C:\> $hls = (
>> @{Distribution="Ubuntu"; ostype="Linux"; base="Debi...
>> @{Distribution="Debian"; ostype="Linux"; base="Inde...
>> @{Distribution="Red Hat Enterprise Linux"; ostype="...
>> @{Distribution="FreeBSD"; ostype="BSD"; base="Indep...
>> @{Distribution="TrueOS"; ostype="BSD"; base="FreeBS...
>> @{Distribution="OpenBSD"; ostype="BSD"; base="Indep...
>> )
PS C:\> $hls
Name Value
---- -----
Distribution Ubuntu
ostype Linux
base Debian
Distribution Debian
ostype Linux
base Independent
Distribution Red Hat Enterprise Linux
ostype Linux
base Fedora
Distribution FreeBSD
ostype BSD
base Independent
Distribution TrueOS
ostype BSD
base FreeBSD
Distribution OpenBSD
ostype BSD
base Independent
+PSCustomObjectを使って、表形式にします。
$fls = $hls | % { New-Object PSCustomObject -Property $_ }
+ 上記の構文を実際にPowerShell上で実行したときの出力です。
PS C:\> $fls = $hls | % { New-Object PSCustomObject -Pro...
PS C:\> $fls
Distribution ostype base
------------ ------ ----
Ubuntu Linux Debian
Debian Linux Independent
Red Hat Enterprise Linux Linux Fedora
FreeBSD BSD Independent
TrueOS BSD FreeBSD
OpenBSD BSD Independent
+ Format-TableのPropertyに項目名を指定すれば、指定した項...
PS C:\> $fls | Format-Table -Property Distribution, base
Distribution base
------------ ----
Ubuntu Debian
Debian Independent
Red Hat Enterprise Linux Fedora
FreeBSD Independent
TrueOS FreeBSD
OpenBSD Independent
以上、ハッシュの配列を表形式で表示する方法でした。
#htmlinsertpcsp(win-btm.html,win-sp.html)
ページ名: