次の方法で共有


Get-FormatData

現在のセッションの書式設定データを取得します。

構文

Default (既定)

Get-FormatData
    [[-TypeName] <String[]>]
    [<CommonParameters>]

説明

Get-FormatData コマンドレットは、現在のセッションの書式設定データを取得します。

セッションの書式設定データには、$pshome ディレクトリ内のファイルなど、Format.ps1xml 書式設定ファイルの書式設定データ、セッションにインポートするモジュールの書式設定データ、Import-PSSession コマンドレットを使用してセッションにインポートするコマンドの書式設定データが含まれます。

このコマンドレットを使用して、書式設定データを調べることができます。 その後、Export-FormatData コマンドレットを使用してオブジェクトをシリアル化し、XML に変換して、Format.ps1xml ファイルに保存できます。

PowerShell でのファイルの書式設定の詳細については、「about_Format.ps1xml」を参照してください。

例 1: すべての書式設定データを取得する

このコマンドは、セッション内のすべての書式設定データを取得します。

Get-FormatData

例 2: 型名で書式設定データを取得する

Get-FormatData -TypeName 'System.Management.Automation.Cmd*'

このコマンドは、名前が System.Management.Automation.Cmd* で始まる書式設定データ項目を取得します。

例 3: 書式設定データ オブジェクトを調べる

$F = Get-FormatData -TypeName 'System.Management.Automation.Cmd*'
$F
TypeName        FormatViewDefinition
--------        --------------------
HelpInfoShort   {help , TableControl}
$F.FormatViewDefinition[0].control
Headers          : {System.Management.Automation.TableControlColumnHeader, System.Management.Automation.TableControlColumnHeader, System.Management.Automation.TableControlColumnHeader,
                   System.Management.Automation.TableControlColumnHeader}
Rows             : {System.Management.Automation.TableControlRow}
AutoSize         : False
HideTableHeaders : False
GroupBy          :
OutOfBand        : False
$F.FormatViewDefinition[0].control.Headers
Label         Alignment      Width
-----         ---------      -----
Name          Left           33
Category      Left           9
Undefined      0

この例では、書式設定データ オブジェクトを取得し、そのプロパティを調べる方法を示します。

例 4: 書式設定データを取得してエクスポートする

$A = Get-FormatData
Import-Module bitstransfer
$B = Get-FormatData
Compare-Object $A $B
InputObject                                                SideIndicator
-----------                                                -------------
Microsoft.BackgroundIntelligentTransfer.Management.BitsJob =>
Get-FormatData *bits* | Export-FormatData -FilePath c:\test\bits.format.ps1xml
Get-Content c:\test\bits.format.ps1xml
<?xml version="1.0" encoding="utf-8"?><Configuration><ViewDefinitions>
<View><Name>Microsoft.BackgroundIntelligentTransfer.Management.BitsJob</Name>
...

この例では、 Get-FormatDataExport-FormatData を使用して、モジュールによって追加された書式設定データをエクスポートする方法を示します。

最初の 4 つのコマンドでは、 Get-FormatData、Import-Module、および Compare-Object コマンドレットを使用して、BitsTransfer モジュールがセッションに追加する形式の種類を識別します。

5 番目のコマンドでは、 Get-FormatData コマンドレットを使用して、BitsTransfer モジュールが追加する形式の種類を取得します。 パイプライン演算子 (|) を使用して、形式型オブジェクトを Export-FormatData コマンドレットに送信し、 コマンドレットによって XML に変換され、指定された format.ps1xml ファイルに保存されます。

最後のコマンドは、format.ps1xml ファイルの内容の抜粋を示しています。

パラメーター

-TypeName

このコマンドレットが書式設定データに対して取得する型名を指定します。 型名を入力します。 ワイルドカードを使用できます。

パラメーターのプロパティ

型:

String[]

規定値:None
ワイルドカードのサポート:True
DontShow:False

パラメーター セット

(All)
配置:0
必須:False
パイプラインからの値:False
プロパティ名別のパイプラインからの値:False
残りの引数からの値:False

CommonParameters

このコマンドレットでは、一般的なパラメーター -Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction、-WarningVariable の各パラメーターがサポートされています。 詳細については、about_CommonParametersを参照してください。

入力

None

パイプを使用してこのコマンドレットに入力を渡すことはできません。

出力

ExtendedTypeDefinition