当我尝试访问 ShouldProcess 脚本块中的变量时,我得到一个空表达式。这就是我在脚本方法中所拥有的:
$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()
方法,那么一切正常。