[英]How would I tell PS to read a file name and use it?
In my script I want PS to read whatever the name of the file is in the "Windows ISO" directory and use that file instead of hard coding the filename "Win10_20H2_v2_English_x64.iso" since that will change over time.在我的脚本中,我希望 PS 读取“Windows ISO”目录中的文件名并使用该文件而不是硬编码文件名“Win10_20H2_v2_English_x64.iso”,因为它会随着时间而改变。 How would I do this in the code below?我将如何在下面的代码中执行此操作?
#region MountDismountCopy
# ISO image - replace with path to ISO to be mounted
$isoImg = "C:\ESD\Windows 10 ISO\Win10_20H2_v2_English_x64.iso"
# Drive letter - use desired drive letter
$driveLetter = "Y:"
# Mount the ISO, without having a drive letter auto-assigned
$diskImg = Mount-DiskImage -ImagePath $isoImg -NoDriveLetter
# Get mounted ISO volume
$volInfo = $diskImg | Get-Volume
# Mount volume with specified drive letter (requires Administrator access)
mountvol $driveLetter $volInfo.UniqueId
[string]$sourceDirectory = "Y:\*"
[string]$destinationDirectory = "C:\ESD\Deployment"
Copy-item -Force -Recurse -Verbose $sourceDirectory -Destination $destinationDirectory
# Unmount drive
DisMount-DiskImage -ImagePath $isoImg
Copy-Item -Force -Recurse -Verbose 'C:\ESD\Deployment\sources\install.esd' 'C:\ESD\install.esd'
#endregion
In my script I want PS to read whatever the name of the file is in the "Windows ISO" directory and use that file instead of hard coding the filename "Win10_20H2_v2_English_x64.iso"在我的脚本中,我希望 PS 读取“Windows ISO”目录中的文件名并使用该文件而不是硬编码文件名“Win10_20H2_v2_English_x64.iso”
$isoImg = get-childitem -path "C:\ESD\Windows 10 ISO\*.iso" |select -expandproperty fullname
You may run into issues,if you have multiple ISO files如果您有多个 ISO 文件,您可能会遇到问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.