gpt4 book ai didi

exception - PowerShell:复制项抛出 DriveNotFoundException

转载 作者:行者123 更新时间:2023-12-02 22:41:37 24 4
gpt4 key购买 nike

我的脚本一直困扰着我,但出现以下异常

copy-item : Cannot find drive. A drive with the name 'F' does not exist.
At C:\Program Files (x86)\CA\ARCserve Backup\Templates\RB_Pre_Process.ps1:58 char:1
+ copy-item -Path $drive -Destination $DST_DRIVE -Recurse -ErrorAction Stop
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (F:String) [Copy-Item], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.CopyItemCommand

这就是我的脚本的样子。我正在驱动器 F: 上安装 ISO 镜像,并且添加了“start-slepp -s 5”命令,以便我可以验证镜像是否已安装,确实如此!

$BACKUP_PATH = "E:\00_BACKUP_DATA"
$DR_PATH = "E:\01_DR_DATA"
$ISO_IMAGE = "C:\Program Files (x86)\CA\ARCserve Backup\Templates\Winpe_x64.iso"
$DST_DRIVE = "E:\"

try {
New-EventLog -LogName Application -Source "RB_Pre_Process.ps1" -ErrorAction Stop
} catch [System.InvalidOperationException] {
Write-host $_
}

try {
Write-Host "Preparing RDX cartridge..."

# Query for disk object
$disk_number = (Get-Disk | Where-Object -Property FriendlyName -like "TANDBERG RDX*").Number

# Remove partitions
Get-Disk $disk_number | Clear-Disk -RemoveData -Confirm:$false | Out-Null

# Create new partition
New-Partition -DiskNumber $disk_number -UseMaximumSize | Out-Null

# Format partition
Format-Volume -DriveLetter E -FileSystem NTFS -NewFileSystemLabel "RDX_TAPE" -Confirm:$false | Out-Null

# Set partition as active
Set-Partition -DriveLetter E -IsActive:$true | Out-Null
} catch {
Write-Host $_
Write-EventLog -LogName Application -Source $MyInvocation.MyCommand.Name -EventID 2 -Message $_
}

try {
Write-Host "Creating folder structure..."

new-item -itemtype directory -Path $BACKUP_PATH -ErrorAction stop | Out-Null
new-item -itemtype directory -path $DR_PATH -ErrorAction stop | Out-Null
} catch {
Write-Host $_
Write-EventLog -LogName Application -Source $MyInvocation.MyCommand.Name -EventID 2 -Message $_
}

try {
Write-Host "Mounting ISO image..."

$image = Mount-DiskImage -ImagePath $ISO_IMAGE -PassThru -ErrorAction Stop
} catch [ParameterBindingException] {
Write-Host $_
Write-EventLog -LogName Application -Source $MyInvocation.MyCommand.Name -EventId 2 -Message $_
}

$drive = ($image | Get-Volume).DriveLetter
$drive += ":\*"

Start-Sleep -s 5

try {
Write-Host "Copying ISO content..."

copy-item -Path $drive -Destination $DST_DRIVE -Recurse -ErrorAction Stop
} catch {
Write-Host $_
Write-EventLog -LogName Application -Source $MyInvocation.MyCommand.Name -EventId 2 -Message $_
}

try {
Write-Host "Unmounting ISO image..."

Dismount-DiskImage -ImagePath $ISO_IMAGE -ErrorAction Stop
} catch [System.Exception] {
Write-Host $_
Write-EventLog -LogName Application -Source $MyInvocation.MyCommand.Name -EventId 2 -Message $_
}

那么,这里出了什么问题?有时有效有时无效...

最佳答案

我“解决”了这个问题...当直接从 PowerShell 提示符而不是 PowerShell ISE 启动时,我的脚本运行得非常好...所以 IDE 是罪魁祸首。

关于exception - PowerShell:复制项抛出 DriveNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18735886/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com