當我嘗試訪問ShouldProcess腳本塊內的變量時,我得到一個空表達式。這是我在一個腳本方法:PowerShell - 在腳本屬性中支持應用程序
$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()
方法,那麼一切工作正常。
您是否在函數的開頭加入了[[CmdletBinding(SupportsShouldProcess = $ true)]'屬性? – Poorkenny 2013-03-05 15:11:08
是的,它是作爲[CmdletBinding(SupportsShouldProcess = $ True)] – Sunit 2013-03-05 15:36:02
你能提供完整的例外嗎? – 2013-03-05 18:18:47