Get-FormatData
取得當前工作階段的格式資料。
語法
Default (預設值)
Get-FormatData
[[-TypeName] <String[]>]
[-PowerShellVersion <Version>]
[<CommonParameters>]
Description
Get-FormatData指令長 Commandlet 會取得當前工作階段的格式化資料。
會話中的格式資料包括格式 Format.ps1xml 化檔案的格式資料,例如目錄中的 $PSHOME 格式,你匯入會話的模組格式資料,以及使用 Import-PSSession cmdlet 匯入會話的指令格式資料。
你可以用這個 cmdlet 來檢查格式資料。 接著,你可以用 Export-FormatData cmdlet 序列化物件,轉換成 XML,並存檔。Format.ps1xml
如需在 PowerShell 中格式化檔案的詳細資訊,請參閱 about_Format.ps1xml。
範例
範例 1:取得所有格式化資料
這個範例會取得會話中所有格式化資料。
Get-FormatData
範例 2:依類型名稱取得格式化資料
此範例取得名稱以 System.Management.Automation.Cmd開頭的格式化資料項目。
Get-FormatData -TypeName '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
----- --------- -----
CommandType Undefined 15
Name Undefined 50
Version Undefined 10
Source Undefined 0
範例 4:取得格式資料並匯出
這個範例展示了如何使用 Get-FormatData 並 Export-FormatData 匯出由模組新增的格式資料。
$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-FormatData、 和 Import-ModuleCompare-Object cmdlet 來識別 BitsTransfer 模組為會話新增的格式類型。
第五個指令使用 Get-FormatData cmdlet 取得 BitsTransfer 模組新增的格式類型。 它使用管線運算子(|)將格式類型物件傳送給 Export-FormatData cmdlet,指令碼會將其轉回 XML 並儲存在指定的 Bits.format.ps1xml 檔案中。
最後一個指令顯示檔案內容的 format.ps1xml 摘錄。
範例 5:根據指定版本的 PowerShell 取得格式化資料
此範例展示了如何取得 Get-FormatData 指定 TypeName 與 PowerShell 版本的格式資料。
Get-FormatData -TypeName 'Microsoft.Powershell.Utility.FileHash' -PowerShellVersion $PSVersionTable.PSVersion
TypeNames FormatViewDefinition
--------- --------------------
{Microsoft.Powershell.Utility.FileHash} {Microsoft.Powershell.Utility.FileHash}
參數
-PowerShellVersion
請指定這個 cmdlet 格式化資料所用的 PowerShell 版本。 輸入一個兩位數,中間有句點。
此參數是在 PowerShell 5.1 中加入,目的是提升遠端執行舊版 PowerShell 的電腦相容性。
參數屬性
| 類型: | Version |
| 預設值: | None |
| 支援萬用字元: | False |
| 不要顯示: | False |
參數集
(All)
| Position: | Named |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
-TypeName
指定此 cmdlet 格式資料的類型名稱。 輸入類型名稱。 允許使用通配符。
參數屬性
| 類型: | String[] |
| 預設值: | None |
| 支援萬用字元: | True |
| 不要顯示: | False |
參數集
(All)
| Position: | 0 |
| 必要: | False |
| 來自管線的值: | False |
| 來自管線按屬性名稱的值: | False |
| 來自剩餘引數的值: | False |
CommonParameters
此 cmdlet 支援常見參數:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 如需詳細資訊,請參閱 about_CommonParameters。
輸入
None
您不能將物件透過管道傳送到此 Cmdlet。