Ich versuche, um die Warnung zu erfassen, die ausgelöst werden, wenn ich versuche, Postfachberechtigungen für jemanden aus einem Postfach zu entfernen, die Berechtigungen nicht an erster Stelle.Capturing Power Warnung
#$WarningPreference = "continue"
try
{
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
Remove-MailboxPermission -Identity "test2" -User "test1" -AccessRights FullAccess -InheritanceType All -confirm:$False | Out-File c:\temp\output2.txt -Encoding ASCII
}
catch
{
#Write-Warning -Message $($_.Exception.Message) 3 > c:\temp\warning.txt
}
Es erfolgt keine Ausgabe entweder in output2.txt oder warning.txt ist - was mache ich falsch?
Die Warnungen Ich versuche, in gelb zu erfassen erscheinen und sagen:
WARNING: The cmdlet extension agent with the index 0 has thrown an exception in OnComplete(). The exception is:
System.InvalidOperationException: Operation is not valid due to the current state of the object.
at Microsoft.Exchange.Data.Storage.ExchangePrincipal.get_ServerFullyQualifiedDomainName()
at Microsoft.Exchange.Data.Storage.MailboxSession.Initialize(MapiStore linkedStore, LogonType logonType,
ExchangePrincipal owner, DelegateLogonUser delegateUser, Object identity, OpenMailboxSessionFlags flags,
GenericIdentity auxiliaryIdentity)
at Microsoft.Exchange.Data.Storage.MailboxSession.<>c__DisplayClass12.<CreateMailboxSession>b__10(MailboxSession
mailboxSession)
at Microsoft.Exchange.Data.Storage.MailboxSession.InternalCreateMailboxSession(LogonType logonType,
ExchangePrincipal owner, CultureInfo cultureInfo, String clientInfoString, IAccountingObject budget, Action`1
initializeMailboxSession, InitializeMailboxSessionFailure initializeMailboxSessionFailure)
at Microsoft.Exchange.Data.Storage.MailboxSession.ConfigurableOpen(ExchangePrincipal mailbox, MailboxAccessInfo
accessInfo, CultureInfo cultureInfo, String clientInfoString, LogonType logonType, PropertyDefinition[]
mailboxProperties, InitializationFlags initFlags, IList`1 foldersToInit, IAccountingObject budget)
at Microsoft.Exchange.Data.Storage.MailboxSession.OpenAsSystemService(ExchangePrincipal mailboxOwner, CultureInfo
cultureInfo, String clientInfoString)
at Microsoft.Exchange.ProvisioningAgent.MailboxLoggerFactory.XsoMailer.Log(AdminLogMessageData data,
LogMessageDelegate logMessage)
at Microsoft.Exchange.ProvisioningAgent.AdminLogProvisioningHandler.OnComplete(Boolean succeeded, Exception e)
at Microsoft.Exchange.Provisioning.ProvisioningLayer.OnComplete(Task task, Boolean succeeded, Exception exception)
WARNING: Can't remove the access control entry on the object "CN=xxxxx" for account "xxxxx" because the ACE doesn't exist on the
object.
Vielen Dank für all die Hilfe so weit! Mein Code sieht nun wie folgt aus:
$WarningPreference = "continue"
try
{
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
Remove-MailboxPermission -Identity "test1" -User "test2" -AccessRights FullAccess -InheritanceType All -confirm:$False 2> c:\temp\errors.txt 3> c:\temp\warnings.txt -ErrorAction Stop
}
catch
{
2> c:\temp\errors.txt
}
* ENDLÖSUNG - DANKE ALL *
$WarningPreference = "continue"
try
{
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
Remove-MailboxPermission -Identity "test1" -User test2" -AccessRights FullAccess -InheritanceType All -confirm:$False 2> c:\temp\errors.txt 3> c:\temp\warnings.txt -ErrorAction Stop
}
catch
{
$_ > c:\temp\errors.txt
}
'2> c: \ temp \ fehler.txt' ->' $ _> c: \ temp \ fehler.txt' - '$ _' steht für die Ausnahme. (Was '2> c: \ temp \ errors.txt' tut, ist das Senden einer Ganzzahl' 2' (stringifiziert) über den erfolgreichen Ausgabestrom an die Datei). – mklement0