Question Re:[Tutoriel] La gestion des erreurs sous PowerShell

Plus d'informations
il y a 10 ans 3 mois #16707 par Gaga
Salut,

Merci pour ce document très très bien fait !!

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 10 ans 3 mois #16732 par darphboubou
Bonjour,

J'ai créé un script pour automatiser la création et le paramétrage des mailbox utilisateur sur office 365 (en remote powershell).

a un moment je fais un test pour savoir si la mailbox existe, ce qui me génère parfois des erreur.
dont voici le descriptif:

PSMessageDetails :
OriginInfo : pod35psh.outlook.com
Exception : System.Management.Automation.RemoteException: Impossible d'effectuer l'opération, car l'objet '
Cette adresse e-mail est protégée contre les robots spammeurs. Vous devez activer le JavaScript pour la visualiser.' est introuvable sur 'DBXPR00000DC01.EURPR00000.prod.outlook.com'.
TargetObject :
CategoryInfo : NotSpecified: (:) [Set-CASMailbox], ManagementObjectNotFoundException
FullyQualifiedErrorId : [Server=AMSP465747B113,RequestId=cc9f692b-096c-4efd-FGDTRH-0b22f74f8164,TimeStamp=02/01/2014 14:17:
39] [FailureCategory=Cmdlet-ManagementObjectNotFoundException] CA01804C,Microsoft.Exchange.Mana
gement.RecipientTasks.SetCASMailbox
ErrorDetails :
InvocationInfo :
PipelineIterationInfo : {}



00000000000000000000000000000000000000000000000000000000000000000000000000000000


SerializedRemoteException : Microsoft.Exchange.Configuration.Tasks.ManagementObjectNotFoundException: Impossible d
'effectuer l'opération, car l'objet 'Cette adresse e-mail est protégée contre les robots spammeurs. Vous devez activer le JavaScript pour la visualiser.' est introuvable sur 'DBXPR05
000DC01.EURPR00000.prod.outlook.com'.
at Microsoft.Exchange.Configuration.Tasks.DataAccessTask`1.GetDataObject[TObject](I
IdentityParameter id, IConfigDataProvider session, ObjectId rootID, OptionalIdentityDa
ta optionalData, Nullable`1 notFoundError, Nullable`1 multipleFoundError, ExchangeErro
rCategory errorCategory)
at Microsoft.Exchange.Configuration.Tasks.RecipientTaskHelper.ResolveDataObject[TDa
taObject](IConfigDataProvider dataSession, IConfigDataProvider globalCatalogSession, A
DServerSettings serverSettings, IIdentityParameter identity, ObjectId rootId, Optional
IdentityData optionalData, String domainController, CategorizedGetDataObjectDelegate g
etDataObjectHandler, TaskVerboseLoggingDelegate logHandler, ErrorLoggerDelegate errorH
andler)
at Microsoft.Exchange.Configuration.Tasks.SetRecipientObjectTask`3.ResolveDataObjec
t()
at Microsoft.Exchange.Management.RecipientTasks.SetCASMailboxBase`2.ResolveDataObje
ct()
at Microsoft.Exchange.Management.RecipientTasks.SetCASMailbox.ResolveDataObject()
at Microsoft.Exchange.Configuration.Tasks.SetObjectTaskBase`2.PrepareDataObject()
at Microsoft.Exchange.Configuration.Tasks.SetRecipientObjectTask`3.PrepareDataObjec
t()
at Microsoft.Exchange.Management.RecipientTasks.SetCASMailbox.PrepareDataObject()
at Microsoft.Exchange.Configuration.Tasks.SetTaskBase`1.InternalValidate()
at Microsoft.Exchange.Configuration.Tasks.SetRecipientObjectTask`3.InternalValidate
()
at Microsoft.Exchange.Management.RecipientTasks.SetCASMailboxBase`2.InternalValidat
e()
at Microsoft.Exchange.Configuration.Tasks.Task.ProcessRecord()
SerializedRemoteInvocationInfo : System.Management.Automation.InvocationInfo
ErrorRecord : Impossible d'effectuer l'opération, car l'objet 'Cette adresse e-mail est protégée contre les robots spammeurs. Vous devez activer le JavaScript pour la visualiser.' est introuvable
sur 'DBXPR00000DC01.EURPR00000.prod.outlook.com'.
StackTrace :
WasThrownFromThrowStatement : False
Message : Impossible d'effectuer l'opération, car l'objet 'Cette adresse e-mail est protégée contre les robots spammeurs. Vous devez activer le JavaScript pour la visualiser.' est introuvable
sur 'DBXPR00000DC01.EURPR00000.prod.outlook.com'.
Data : {}
InnerException :
TargetSite :
HelpLink :
Source :


Je ne sais pas comment la gérer avec try catch, pouvez-vous m'aider?

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 10 ans 3 mois #16734 par Laurent Dardenne
Contenu effacé.<br><br>Message édité par: Laurent Dardenne, à: 5/01/14 12:45

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 10 ans 3 mois #16736 par Laurent Dardenne
Supprime le contenu de ton post je te répond ici .

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 10 ans 2 mois #16825 par Nicolas Lang
:blink: Wow...

Merci beaucoup, ça sera vraiment très utile!

Encore une fois félicitations pour tout le travail que vous accomplissez, et ce que vous partagez!

Bon...

Je vais avoir de la lecture moi :P

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 9 ans 2 mois #18981 par Laurent Dardenne
Un piège autour de l'instruction Catch et de l'exception System.Management.Automation.RuntimeException.

Le dernier bloc Catch n'est jamais exécuté, car le premier bloc Catch gére toutes les exceptions.
Selon les spécifications de PS : 'Each exception thrown is raised as a System.Management.Automation.RuntimeException'
[code:1]
try {
#[NotExist]&gt; $Null
Throw (New-Object System.ApplicationException(\&quot;Error.\&quot;«»))
} catch [System.Management.Automation.RuntimeException] {
Write-Warning \&quot;Exception type : $($_.Exception.GetType())\&quot;
}Catch {
Write-Warning \&quot;Autre\&quot;
}
#AVERTISSEMENT : Exception type : System.ApplicationException
[/code:1]
Si on décommente la première ligne qui déclenche bien l'exception System.Management.Automation.RuntimeException, on obtient :
[code:1]
#AVERTISSEMENT : Exception type : System.Management.Automation.RuntimeException
[/code:1]
Une solution pour gérer ce cas :
[code:1]
try {
#[NotExist]&gt; $Null
Throw (New-Object System.ApplicationException(\&quot;Error.\&quot;«»))

} catch [System.ApplicationException] {
Throw $_ #Gére ce type d'exception et la redéclenche
}
} catch [System.Management.Automation.RuntimeException] {
Write-Warning \&quot;Exception type : $($_.Exception.GetType())\&quot;
}
[/code:1]
Ici on ne gère que deux cas d'exceptions.

Une autre solution :
[code:1]
try {
[NotExist]&gt; $Null
Throw (New-Object System.ApplicationException(\&quot;Error.\&quot;«»))
}Catch {
if ($_.Exception -is [System.Management.Automation.RuntimeException])
{ Write-Warning 'Gére [System.Management.Automation.RuntimeException]'}
else
{ Throw $_ } #Redéclenche toutes les autres exceptions
}
[/code:1]<br><br>Message édité par: Laurent Dardenne, à: 9/02/15 16:18

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.099 secondes
Propulsé par Kunena