[英]In Powershell, save and restore array of PSCustomObjects to a file for later reload and re-use
有沒有辦法將 Get-ChildItem 的輸出寫入文件並保留 [PSCustomObjects] 數組,然后再讀取此文件並將其轉換回 [PSCustomObjects] 數組?
$gci = get-childitem -recurse
# How to implement this
save_file -file "list.gci". -value $gci
# How to implement this
$gci2 = load_file -file "list.gci"
foreach ($item in $gci2) {
$fullname = $gci2.fullname
$CreatationDate = $gci2.CreationDate
write-host "$fullname"
}
擴展 Olaf 的評論,Powershell 可以使用CLIXML將具有類型信息和屬性的復雜對象保存到文件中:
# export to file
$gci = Get-ChildItem -Recurse
$gci | Export-Clixml c:\path\to\file.xml
# import later:
$gci2 = Import-Clixml c:\path\to\file.xml
# objects are still FileInfo objects:
$gci2 | Get-Member
TypeName: Deserialized.System.IO.FileInfo
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.