简体   繁体   English

我将如何告诉 PS 读取文件名并使用它?

[英]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.

相关问题 在将参数传递给 PS 文件时,如何使用 invoke-command 从 windows 命令行运行 PS 文件? - How do I use invoke-command to run a PS file from the windows command line while passing parameters to the PS file? 我将如何编写一个批处理文件来命名 Windows Explorer 自动重命名等目录中的文件? - How would I write a batch file which will name files in a directory like Windows Explorer auto rename? 我如何使用文件大小来读取WinAPI中的文件? - How can I use a filesize in order to read a file in WinAPI? 如何在没有外部 ps1 文件的情况下创建一个执行 powershell 脚本的 bat 文件? - How do I create a bat file that executes powershell script without an external ps1 file? 如何在.bat文件(Windows)中使用ImageMagick调整所有子目录中所有图像的大小? - How would I use ImageMagick in a .bat file (Windows) to resize all images in all sub-directories? 如何判断Windows上Python中的另一个应用程序是否正在使用文件 - How to tell if a file is in use by another application in Python on Windows 如何从正在使用的文件中读取 - How to read from a file that is in use 如何告诉 CMake 在 Windows 上使用 Clang? - How do I tell CMake to use Clang on Windows? 我如何告诉cmake使用Winpcap做这两个步骤? - How do I tell cmake to do these two steps to use winpcap? 如何通过工作表名称读取 Perl 中的 Excel 文件 - How to read Excel file in Perl by sheet name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM