Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 我如何告诉PS读取文件名并使用它?_Windows_Powershell - Fatal编程技术网

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

Windows 我如何告诉PS读取文件名并使用它?,windows,powershell,Windows,Powershell,在我的脚本中,我希望PS读取“Windows ISO”目录中文件的任何名称,并使用该文件,而不是硬编码文件名“Win10_20H2_v2_English_x64.ISO”,因为这会随着时间的推移而改变。我将如何在下面的代码中执行此操作 #region MountDismountCopy # ISO image - replace with path to ISO to be mounted $isoImg = "C:\ESD\Windows 10 ISO\Win10_20H2_v2_E

在我的脚本中,我希望PS读取“Windows ISO”目录中文件的任何名称,并使用该文件,而不是硬编码文件名“Win10_20H2_v2_English_x64.ISO”,因为这会随着时间的推移而改变。我将如何在下面的代码中执行此操作

#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
在我的脚本中,我希望PS读取“Windows ISO”目录中的文件名,并使用该文件,而不是硬编码文件名“Win10\u 20H2\u v2\u English\u x64.ISO”

如果您有多个ISO文件,则可能会遇到问题

$isoImg =  get-childitem -path "C:\ESD\Windows 10 ISO\*.iso" |select   -expandproperty fullname