ShouldProcess スクリプト ブロック内の変数にアクセスしようとすると、null 式が返されます。これは私がスクリプトメソッドに持っているものです:
$scaObject = [PerfWorker.CmdLets.PSDbInfoFactory]::GetPSDbInfo($info, $false)
$oracleObj = [PerfWorker.CmdLets.OracleParamsDto]$scaObject
Add-Member -InputObject $oracleObj -MemberType ScriptMethod -Name DropSchemas -Value {
$oraWorker = [PerfWorker.CmdLets.PSDbOracleInfo]$this.DbWorker
$args | foreach {
#Start getting error "You cannot call a method on a null-valued expression" from line below
if($psCmdLet.ShouldProcess(
"Delete Oracle Schema $_ on $($this.Hostname)? This action cannot be undone!",
"Delete Schema?"))
{
$oraWorker.DropS3DSchemas($_)
}
}
}
$psCmdlet.ShouldProcess
ブロックを削除して$oraWorker.DropS3DSchemas()
メソッドを呼び出すと、すべて正常に動作します。