Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Try Catch does not work for imported cmdlets

$
0
0

Hello,

i'm trying to enable lync users from a remote server.

for this i'm importing a few cmdlets from the lync server to the remote server:

$LyncSession =New-PSSession-ConnectionUri $LyncUri -AuthenticationNegotiateImport-PSSession-Session $LyncSession -CommandNameGet-CsAdUser,Enable-CsUser,Grant-CsExternalAccessPolicy

 

later in the script, when i enable the user i'm using a try catch to catch any error that may appear:

try{Enable-CsUser-Identity $csaduser.UserPrincipalName-RegistrarPool"server.domain.intra"-SipAddressTypeSamAccountName-SipDomain domain.intra -ErrorActionStop}catch{Log-Data-LogMessage $Error[0].Exception-UserDN $csaduser.DistinguishedName-LogError}

 

from some reason the try catch dos not catch the error....although an error occurs :

PS C:\Admin\Scripts> $Error[0]|fl *-Force


writeErrorStream      :TruePSMessageDetails:OriginInfo: server.domain.intraException:System.Management.Automation.RemoteException:Filter failed to return unique result,"[SipAddress : sip:username@domain.intra] "TargetObject:CategoryInfo:InvalidOperation:(:)[Enable-CsUser],InvalidOperationExceptionFullyQualifiedErrorId:ProcessRecord,Microsoft.Rtc.Management.AD.Cmdlets.EnableOcsUserCmdletErrorDetails:InvocationInfo:ScriptStackTrace:PipelineIterationInfo:{}

how can i catch this error ?

thanks,

Marius


Viewing all articles
Browse latest Browse all 6937

Trending Articles