2

私のスクリプトは、次の例外で私を悩ませ続けます

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 $_
}

それで、ここで何がうまくいかないのですか?うまくいくこともあれば、うまくいかないこともあります...

4

2 に答える 2