我保存了这样的文件:
Get-ChildItem -Path $OSPathTemp |
Rename-Item -NewName {
$_.BaseName + '_' + $_.LastWriteTime.ToString('ddMMyyyy') + $_.Extension
}
如何再次选择此文件?我尝试过:
$Path = "\\SRVSCCM01\_Source$\OS\REFWS2016" + '_' + { $_.LastWriteTime } + $_.Extension
该文件名为:REFWS2016_XXXXX.Wim
答案 0 :(得分:5)
足够简单...将-PassThru
添加到Rename-Item
并将结果保存在变量中。
$File = Get-ChildItem -Path $OSPathTemp |
Rename-Item -NewName {
$_.BaseName + '_' + $_.LastWriteTime.ToString('ddMMyyyy') + $_.Extension
} -PassThru
然后只需参考$File
。
答案 1 :(得分:0)
我通过创建一个数组来解决它:
$arrayWimFiles = @()
$arrayWimFiles = @(
Get-ChildItem -Path "$OSPathTemp" -recurse | Rename-Item -NewName {$_.BaseName+'_'+$_.LastWriteTime.ToString('ddMMyyyy')+$_.Extension}
)
$Windows10ENBase = $arrayWimFiles | Where-Object { $_ -like "REFW10-X64EN-01*" } | Select-Object -ExpandProperty FullName
$WindowsSRV2016Base = $arrayWimFiles | Where-Object { $_ -like "REFWS2016*" } | Select-Object -ExpandProperty FullName