0

モジュール化するために、作業スクリプトを変更しようとしています。スクリプトの目的は、DPM サーバーに接続し、接続されているライブラリを取得して、それらのインベントリを作成することです。インベントリが完了すると、スクリプトは適切なテープを「空き」としてマークします。スクリプトは以下

2 つの問題があります。私がスクリプトを編集したので、最初のものは行き来しました。スクリプト .\script.ps1 を実行すると、Powershell は次のように言います。

C:\it\test.ps1: パラメーター 'DPMLibrary' の引数を検証できません。引数がヌルです。NULL 以外の引数を指定して、コマンドを再試行してください。

行:1 文字:11 + .\test.ps1 <<<<

  • CategoryInfo : NotSpecified: (:) [書き込みエラー]、WriteErrorException FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,test.ps1

2 つ目の問題は、関数をシェルにコピーした直後に発生します。Get-Libraries 関数は正常に機能し、接続されたライブラリのプロパティを返します。パラメータを Inventory-DPMLibrary に渡すと、インベントリが完了します。ライブラリ パラメーターを Update-TapeStatus 関数に渡すと、次のエラーが表示されます。

演算子 '-notmatch' の引数が正しくありません: "スロット" を解析中 - 量指定子 {x,y} の後に何もありません..

行:6 文字:77

  • $テープ = Get-DPMTape -DPMLibrary $lib | Where {$_.Location -notmatch <<<< " *slot *"} | 場所の並べ替え
    • CategoryInfo : InvalidOperation: (:) []、RuntimeException ? + FullyQualifiedErrorId : BadOperatorArgument

変数は null ではありませんが、$liblist パラメータは null のようです。何を与える?

スクリプトは次のとおりです。

[CmdletBinding()]
param(
    [ValidateSet("Fast","Full")]
    [string]$InventoryType = 'Fast',

    [string]$DPMServerName = 'server1'
)

Function Import-DPMModule {
    Try {
        Import-Module DataProtectionManager -ErrorAction Stop
    }
    Catch [System.IO.FileNotFoundException] {
        Throw ("The DPM Powershell module is not installed or is not importable. The specific error message is: {0}" -f $_.Exception.Message)
    }
    Catch {
        Throw ("Unknown error importing DPM powershell module. The specific error message is: {0}" -f $_.Exception.Message)
    }
}

Function Get-Libraries {
    Write-Verbose ("Getting list of libraries connected to {0}." -f $DPMServerName)
    Try { 
       $libraries = Get-DPMLibrary $DPMServerName -ErrorAction Stop | Where {$_.IsOffline -eq $False}
    }
    Catch [Microsoft.Internal.EnterpriseStorage.Dls.Utils.DlsException] {
        Write-Error ("Cannot connect to the DPM library. It appears that the servername is not valid. The specific error message is: {0}" -f $_.Exception.Message)
        Return
    }
    Catch {
        Write-Error ("Unknown error getting library. The specific error message is: {0}" -f $_.Exception.Message)
        Return
    }

    Return $libraries
}

Function Inventory-DPMLibraries ($liblist) {
    Foreach ($lib in $liblist) {
        If ($InventoryType -eq "Fast") {
            Write-Verbose ("Starting fast inventory on {0}" -f $lib)
            $inventoryStatus = Start-DPMLibraryInventory -DPMLibrary $lib -FastInventory -ErrorAction SilentlyContinue
        }
        Else {
            Write-Verbose ("Starting detailed inventory on {0}" -f $lib)
            $inventoryStatus = Start-DPMLibraryInventory -DPMLibrary $lib -DetailedInventory -ErrorAction SilentlyContinue
        }

        While ($inventoryStatus.HasCompleted -eq $False) {
            Write-Output ("Running {0} inventory on library: {1}" -f $InventoryType.ToLower(),$lib.UserFriendlyName)
            Start-Sleep 5
        }
        If ($inventoryStatus.Status -ne "Succeeded") {
            Throw ("Unknown error in inventory process. The specific error message is: {0}" -f $_.Exception.Message)
            Return
        }
    }
}

Function Update-TapeStatus ($liblist) {
    Foreach ($lib in $liblist) {
    write-host ("in tapestatus. the lib is: {0}" -f $lib)
        Write-Verbose ("Beginning the process to determine which tapes to mark 'free' on {0}" -f $lib)
        Write-Verbose ("Getting list of tapes in {0}." -f $lib)
        $tapes = Get-DPMTape -DPMLibrary $lib | Where {$_.Location -notmatch "*slot*"} | Sort Location

        Foreach ($tape in $tapes) {
            If ($tape.DisplayString -eq "Suspect") {
                Write-Verbose ("Remove suspect tapes from the DPM database.")
                Invoke-Command -ScriptBlock {osql -E -S server2 -d DPMDB_server1 -Q "UPDATE tbl_MM_ArchiveMedia SET IsSuspect = 0"} -whatif
                Start-DPMLibraryInventory -DPMLibrary $lib -FastInventory -Tape $tape -whatif
            }
            #Run a full inventory on "unknown" tapes
            #Make recyclable tapes "free"
            If (($tape.DisplayString -notlike "Free*" -and $tape.DataSetState -eq "Recyclable") -or ($tape.DisplayString -like "Unrecognized")) {
                Write-Output ("Marking the tape in slot {0} as free." -f $tape.Location)
                Set-DPMTape $tape -Free -whatif
            }
            If ($tape.OMIDState -eq "Unknown") {
                Write-Warning ("Unknown tape found in slot {0}. Beginning detailed inventory." -f $tape.location)
                $inventoryStatus = Start-DPMLibraryInventory -DPMLibrary $lib -DetailedInventory -Tape $tape -whatif
                While ($inventoryStatus.HasCompleted -eq $False) {Write-Output ("Running full inventory on the tape in slot {0} (label {1})" -f $tape.Location,$tape.Label); Start-Sleep 10}
            }
        }
    }
}

#Calling functions
Try {
    Import-DPMModule
}
Catch {
    Write-Error $_
    Exit
}

Try {
    $liblist = Get-Libraries
}
Catch {
    Write-Error $_
    Exit
}

Try {
    Inventory-DPMLibraries
}
Catch {
    Write-Error $_
    Exit
}

Update-TapeStatus $liblist

ありがとう。

4

1 に答える 1

0

関数Inventory-DPMLibrariesにはパラメーター ( $liblist) が必要です:

Function Inventory-DPMLibraries ($liblist) {
  ...
}

ただし、関数を呼び出すときにそのパラメーターを指定しません。

Try {
  Inventory-DPMLibraries
}
Catch {
  Write-Error $_
  Exit
}

上記を次のように変更します。

Try {
  Inventory-DPMLibraries $liblist
}
Catch {
  Write-Error $_
  Exit
}
于 2013-11-18T17:33:01.000 に答える