lyric76
Goto Top

ScriptAgent und ein Fehler :-(

Guten Morgen,

ich komme schon seit tagen nicht weiter, vielleicht hat hier jemand eine Idee.
Das Script läuft beim aktivieren einer Mailbox mit.

hier mal das Script:
<?xml version="1.0" encoding="utf-8" ?>  
<Configuration version="1.0">  
 <Feature Name="MailboxProvisioning" Cmdlets="enable-mailbox">  
  <ApiCall Name="OnComplete">  
	if ($succeeded) 
	{
	do {
         start-sleep 20
         $mbxExists = Get-MailBoxPermission -Identity $USER -User "NT AUTHORITY\SELF" -ErrorAction SilentlyContinue | FW IsValid  
		} while (!$mbxExists)
		
			$USER = $provisioningHandler.UserSpecifiedParameters["Name"]  
			$OU = (Get-User -Identity $USER).OrganizationalUnit
			$ATT = (Get-mailbox -Identity $USER).customattribute1
	
		if (
			($OU -eq "it-contact.local/Frankfurt (FFM)/IT-Contact/Users") -and ($ATT -eq "extern")  
        	)	{
					Enable-Mailbox -Identity $USER -Archive -ArchivDatabase ArchivMDB
					Set-CASMailbox -Identity $USER -PopEnabled $false -ImapEnabled $false
					Set-Mailbox -Identity $USER _
					-SingleItemRecoveryEnabled $true _
					-UseDatabaseQuotaDefaults $false _
					-IssueWarningQuota 450MB _
					-ProhibitSendQuota 500MB _
					-ProhibitSendReceiveQuota 550MB _
					-ArchiveQuota 1GB _
					-ArchiveWarningQuota 800MB _
					-RetainDeletedItemsFor "30.00:00:00" _  
					-AddressBookPolicy "IT-Contact extern GmbH"  
				}
		
		elseif (
				($OU -eq "it-contact.local/Frankfurt (FFM)/IT-Contact/Users") -and ($ATT -ne "extern")  
				)	{
					Enable-Mailbox -Identity $USER -Archive -ArchivDatabase ArchivMDB
					Set-CASMailbox -Identity $USER -PopEnabled $false -ImapEnabled $false
					Set-Mailbox -Identity $USER _
					-SingleItemRecoveryEnabled $true _
					-UseDatabaseQuotaDefaults $false _
					-IssueWarningQuota 900MB _
					-ProhibitSendQuota 1GB _
					-ProhibitSendReceiveQuota 1,1GB _
					-ArchiveQuota 2GB _
					-ArchiveWarningQuota 1,8GB _
					-RetainDeletedItemsFor "30.00:00:00" _  
					-AddressBookPolicy "IT-Contact GmbH"  
					}		

		elseif (
				($OU -eq "it-contact.local/Frankfurt (FFM)/MOC Testumgebung/Users") -and ($ATT -eq "extern")  
				)	{
					Set-CASMailbox -Identity $USER -PopEnabled $false -ImapEnabled $false
					Set-Mailbox -Identity $USER _
					-SingleItemRecoveryEnabled $true _
					-UseDatabaseQuotaDefaults $false _
					-IssueWarningQuota 180MB _
					-ProhibitSendQuota 200MB _
					-ProhibitSendReceiveQuota 220MB _
					-RetainDeletedItemsFor "30.00:00:00" _  
					-AddressBookPolicy "MOC Testumgebung extern"  
					}	

		elseif (
				($OU -eq "it-contact.local/Frankfurt (FFM)/MOC Testumgebung/Users") -and ($ATT -ne "extern")  
				)	{
					Set-CASMailbox -Identity $USER -PopEnabled $false -ImapEnabled $false
					Set-Mailbox -Identity $USER _
					-SingleItemRecoveryEnabled $true _
					-UseDatabaseQuotaDefaults $false _
					-IssueWarningQuota 180MB _
					-ProhibitSendQuota 200MB _
					-ProhibitSendReceiveQuota 220MB _
					-RetainDeletedItemsFor "30.00:00:00" _  
					-AddressBookPolicy "MOC Test intern"  
					}	
	}
   </ApiCall>
  </Feature>
</Configuration>

und hier die Fehlerausgabe:
Summary: 1 item(s). 1 succeeded, 0 failed.
Elapsed time: 00:00:06


XXXXXX XXXXXX
Completed

Warning:
The cmdlet extension agent with the index 5 has thrown an exception in OnComplete(). The exception is: Microsoft.Exchange.Provisioning.ProvisioningException: ScriptingAgent: Exception thrown while invoking scriptlet for OnComplete API: Missing expression after unary operator '-'.. ---> System.Management.Automation.ParseException: Missing expression after unary operator '-'.  
   at System.Management.Automation.Runspaces.AsyncResult.EndInvoke()
   at System.Management.Automation.PowerShell.EndInvoke(IAsyncResult asyncResult)
   at Microsoft.Exchange.Configuration.MonadDataProvider.MonadPipelineProxy.ClosePipeline(MonadAsyncResult asyncResult)
   --- End of inner exception stack trace ---
   at Microsoft.Exchange.ProvisioningAgent.ScriptingAgentHandler.OnComplete(Boolean succeeded, Exception e)
   at Microsoft.Exchange.Provisioning.ProvisioningLayer.OnComplete(Task task, Boolean succeeded, Exception exception)

Exchange Management Shell command completed:
Enable-Mailbox -Identity 'it-contact.local/Frankfurt (FFM)/IT-Contact/Users/XXXXX XXXXX' -Alias 'XXXXX'  

Elapsed Time: 00:00:06

Nagut es ist laut der Ausgabe nicht wirklich ein Fehler sondern eine Warnung.
Nur wird es auch nicht ausgeführt als die Erweiterungen ein oder ausgeschaltet.

Vielen Dank für eure Ideen.
lG LyriC

Content-Key: 246470

Url: https://administrator.de/contentid/246470

Printed on: April 19, 2024 at 16:04 o'clock

Member: colinardo
colinardo Aug 14, 2014 updated at 11:32:32 (UTC)
Goto Top
Hallo LyriC,
den Codeumbruch via "_" gibt es vielleicht in VB, aber nicht in Powershell. In Powershell kannst du hierfür den Backtick (`) nutzen.

Auch für die GB-Werte wie z.B. 1,1GB solltest du den Punkt als Dezimaltrenner verwenden, sonst ist das für Powershell ein Array aus einer 1 und 1GB.

Dann würde ich Zeile 9 anders schreiben (Format-Wide ist normalerweise nicht dazu geeignet die Boolean-Eigenschaft zuverlässig weiterzugeben):
$mbxExists = (Get-MailBoxPermission -Identity $USER -User "NT AUTHORITY\SELF" -ErrorAction SilentlyContinue).IsValid 
Außerdem würde ich empfehlen längere Scripte in ein Powershell-Script auszulagern und die benötigten Parameter an dieses zu übergeben.

Noch zur Info für bestimmte Sonderzeichen in der XML-Datei:
- Verwenden Sie anstelle des Größer-als-Zeichens (>) die Folge &gt;
- Verwenden Sie anstelle des Kleiner-als-Zeichens (<) die Folge $lt;
- Verwenden Sie anstelle eines kaufmännischen Und-Zeichens (&) die Folge &amp;
Grüße Uwe
Member: LyriC76
LyriC76 Aug 14, 2014 at 16:23:26 (UTC)
Goto Top
Hallo Uwe,

vielen dank für den Tipp.
Nun läuft das Script zwar aber es hört nicht mehr auf zu laufen.
bin schon bei 30min. angekommen. mis...
Irgendwas stimmt damit noch nicht.
Member: colinardo
colinardo Aug 14, 2014 updated at 17:14:55 (UTC)
Goto Top
Ich vermute wenn das ein deutsches System ist musst du anstatt "NT AUTHORITY\SELF" die deutsche Variante nehmen "NT-AUTORITÄT\SELBST" checke das Ergebnis erst mal separat außerhalb des Scriptes !! Wenn in dem Befehl nämlich etwas nicht stimmt oder es keine Objekt zurückgibt läuft das unendlich in einer Schleife !
p.s. Die Schleife ist sowieso Schwachsinn, denn wenn das Event OnComplete abgeschlossen ist, existiert die Mailbox schon, man muss also nicht nochmal eine Prüfung einbauen.
Member: LyriC76
LyriC76 Aug 14, 2014 at 18:30:54 (UTC)
Goto Top
vielen Dank für die Antwort.face-smile

Ich habe den befehl getestet: (Get-MailBoxPermission -Identity $USER -User "NT AUTHORITY\SELF" -ErrorAction SilentlyContinue).IsValid
bekam ein true zurück.

stimmt vieleicht was mit dem sleep nicht?

ich poste nochmal das Script:
<?xml version="1.0" encoding="utf-8" ?>  
<Configuration version="1.0">  
 <Feature Name="MailboxProvisioning" Cmdlets="enable-mailbox">  
  <ApiCall Name="OnComplete">  
	if ($succeeded) 
	{
	
		$USER = $provisioningHandler.UserSpecifiedParameters["Name"]  
	
		do {
			sleep -seconds 1
			$mbxExists = Get-MailBoxPermission -Identity $USER -User "NT AUTHORITY\SELF" -ErrorAction SilentlyContinue | FW IsValid  
		} while (!$mbxExists)

		$OU = (Get-MailBox -Identity $USER).OrganizationalUnit
		$ATT = (Get-mailbox -Identity $USER).customattribute1
		
		if (
				($OU -eq "it-contact.local/Frankfurt (FFM)/IT-Contact/Users") -and ($ATT -eq "extern")  
		)	{
				Enable-Mailbox $USER -Archive -ArchivDatabase ArchivMDB
				Set-CASMailbox -Identity $USER -PopEnabled $false -ImapEnabled $false
				Set-Mailbox -Identity $USER `
					-SingleItemRecoveryEnabled $true `
					-UseDatabaseQuotaDefaults $false `
					-IssueWarningQuota 450MB `
					-ProhibitSendQuota 500MB `
					-ProhibitSendReceiveQuota 550MB `
					-ArchiveQuota 1GB `
					-ArchiveWarningQuota 800MB `
					-RetainDeletedItemsFor "30.00:00:00" `  
					-AddressBookPolicy "IT-Contact extern GmbH"  
				}
		
		elseif (
				($OU -eq "it-contact.local/Frankfurt (FFM)/IT-Contact/Users") -and ($ATT -ne "extern")  
		)		{
				Enable-Mailbox $USER -Archive -ArchivDatabase ArchivMDB
				Set-CASMailbox -Identity $USER -PopEnabled $false -ImapEnabled $false
				Set-Mailbox -Identity $USER `
					-SingleItemRecoveryEnabled $true `
					-UseDatabaseQuotaDefaults $false `
					-IssueWarningQuota 900MB `
					-ProhibitSendQuota 1GB `
					-ProhibitSendReceiveQuota "1.1GB" `  
					-ArchiveQuota 2GB `
					-ArchiveWarningQuota "1.8GB" `  
					-RetainDeletedItemsFor "30.00:00:00" `  
					-AddressBookPolicy "IT-Contact GmbH"  
			}		

		elseif (
				($OU -eq "it-contact.local/Frankfurt (FFM)/MOC Testumgebung/Users") -and ($ATT -eq "extern")  
		)		{
				Set-CASMailbox -Identity $USER -PopEnabled $false -ImapEnabled $false
				Set-Mailbox -Identity $USER `
					-SingleItemRecoveryEnabled $true `
					-UseDatabaseQuotaDefaults $false `
					-IssueWarningQuota 180MB `
					-ProhibitSendQuota 200MB `
					-ProhibitSendReceiveQuota 220MB `
					-RetainDeletedItemsFor "21.00:00:00" `  
					-AddressBookPolicy "MOC Testumgebung extern"  
				}	

		elseif (
				($OU -eq "it-contact.local/Frankfurt (FFM)/MOC Testumgebung/Users") -and ($ATT -ne "extern")  
		)		{
				Set-CASMailbox -Identity $USER -PopEnabled $false -ImapEnabled $false
				Set-Mailbox -Identity $USER `
					-SingleItemRecoveryEnabled $true `
					-UseDatabaseQuotaDefaults $false `
					-IssueWarningQuota 180MB `
					-ProhibitSendQuota 200MB `
					-ProhibitSendReceiveQuota 220MB `
					-RetainDeletedItemsFor "21.00:00:00" `  
					-AddressBookPolicy "MOC Test intern"  
			}	
	}
   </ApiCall>
  </Feature>
</Configuration>

Danke für deine (eure) Hilfe.
Member: colinardo
colinardo Aug 14, 2014 updated at 18:32:27 (UTC)
Goto Top
lass die Schleife weg, die brauchst du nicht ... überflüssig
Member: LyriC76
LyriC76 Aug 14, 2014 at 18:45:53 (UTC)
Goto Top
hm ich hab jetzt die schleife raus nun macht er nichts mehr vom script.
kann es sein das er die if und die elseif nicht mag?
Member: colinardo
colinardo Aug 14, 2014 updated at 18:47:46 (UTC)
Goto Top
Ist das dein Script oder hast du das wieder irgendwo "geklauft" ? Bist du Anfänger ?
Member: LyriC76
LyriC76 Aug 14, 2014 at 18:57:08 (UTC)
Goto Top
Hi,

naja also das ist mein script, bis auf den einen eintrag $mbxExists = (Get-MailBoxPermission -Identity $USER -User "NT AUTHORITY\SELF" -ErrorAction SilentlyContinue).IsValid .

Der Rest ist marke Eigenbau und leider ja bin Anfänger im Scripten geb ich zu aber jeder hat mal angefangen. ok vielleicht will ich ja zuviel.
Ich gehe nochmal ein wenig lesen.
Member: colinardo
Solution colinardo Aug 14, 2014, updated at Aug 17, 2014 at 11:56:29 (UTC)
Goto Top
probiers mal hiermit: (kann's gerade nicht testen, waren aber noch ein paar Fehler drin).
Ich würde dir empfehlen das Script in der Entwurfsphase nicht mit dem Scripting-Agent zu testen sondern es für Tests erst mal so zu schreiben das du es als normales Script testen kannst. Wenn es dann läuft kannst du es in den Scripting-Agent implementieren.
<?xml version="1.0" encoding="utf-8" ?>  
<Configuration version="1.0">  
 <Feature Name="MailboxProvisioning" Cmdlets="enable-mailbox">  
  <ApiCall Name="OnComplete">  
	if ($succeeded) 
	{
		$USER = $provisioningHandler.UserSpecifiedParameters["Name"]  
                $cnt = 0	
		do {
                        $cnt++
                        # maximale Wartezeit 60 Sekunden, dann Abbruch
                        if ($cnt -gt 60){exit}
			sleep -seconds 1
			$mbxExists = Get-MailBoxPermission -Identity $USER -User "NT AUTHORITY\SELF" -ErrorAction SilentlyContinue  
		} while (!$mbxExists)

		$OU = (Get-MailBox -Identity $USER).OrganizationalUnit
		$ATT = (Get-mailbox -Identity $USER).customattribute1
		
		if (($OU -eq "it-contact.local/Frankfurt (FFM)/IT-Contact/Users") -and ($ATT -eq "extern"))	{  
				Enable-Mailbox $USER -Archive -ArchivDatabase ArchivMDB
				Set-CASMailbox -Identity $USER -PopEnabled $false -ImapEnabled $false
				Set-Mailbox -Identity $USER `
					-SingleItemRecoveryEnabled $true `
					-UseDatabaseQuotaDefaults $false `
					-IssueWarningQuota 450MB `
					-ProhibitSendQuota 500MB `
					-ProhibitSendReceiveQuota 550MB `
					-ArchiveQuota 1GB `
					-ArchiveWarningQuota 800MB `
					-RetainDeletedItemsFor "30.00:00:00" `  
					-AddressBookPolicy "IT-Contact extern GmbH"  
	    }elseif (($OU -eq "it-contact.local/Frankfurt (FFM)/IT-Contact/Users") -and ($ATT -ne "extern")){  
				Enable-Mailbox $USER -Archive -ArchivDatabase ArchivMDB
				Set-CASMailbox -Identity $USER -PopEnabled $false -ImapEnabled $false
				Set-Mailbox -Identity $USER `
					-SingleItemRecoveryEnabled $true `
					-UseDatabaseQuotaDefaults $false `
					-IssueWarningQuota 900MB `
					-ProhibitSendQuota 1GB `
					-ProhibitSendReceiveQuota 1.1GB `
					-ArchiveQuota 2GB `
					-ArchiveWarningQuota 1.8GB `
					-RetainDeletedItemsFor "30.00:00:00" `  
					-AddressBookPolicy "IT-Contact GmbH"  
		}elseif (($OU -eq "it-contact.local/Frankfurt (FFM)/MOC Testumgebung/Users") -and ($ATT -eq "extern")){  
				Set-CASMailbox -Identity $USER -PopEnabled $false -ImapEnabled $false
				Set-Mailbox -Identity $USER `
					-SingleItemRecoveryEnabled $true `
					-UseDatabaseQuotaDefaults $false `
					-IssueWarningQuota 180MB `
					-ProhibitSendQuota 200MB `
					-ProhibitSendReceiveQuota 220MB `
					-RetainDeletedItemsFor "21.00:00:00" `  
					-AddressBookPolicy "MOC Testumgebung extern"  
		}elseif (($OU -eq "it-contact.local/Frankfurt (FFM)/MOC Testumgebung/Users") -and ($ATT -ne "extern")){  
				Set-CASMailbox -Identity $USER -PopEnabled $false -ImapEnabled $false
				Set-Mailbox -Identity $USER `
					-SingleItemRecoveryEnabled $true `
					-UseDatabaseQuotaDefaults $false `
					-IssueWarningQuota 180MB `
					-ProhibitSendQuota 200MB `
					-ProhibitSendReceiveQuota 220MB `
					-RetainDeletedItemsFor "21.00:00:00" `  
					-AddressBookPolicy "MOC Test intern"  
		}	
	}
   </ApiCall>
  </Feature>
</Configuration>
Grüße Uwe
Member: LyriC76
LyriC76 Aug 14, 2014 at 19:16:56 (UTC)
Goto Top
vielen Dank für die Hilfe.
Du hast recht es wäre einfacher wenn ich es erst mal in der Powershell versucht hätte.
Wahrscheinlich hätte ich auch dann Fehlermeldungen bekomme, mit denen ich vielleicht was hätte anfangen können.
Ich werde es morgen erstmal testen.
Ich habe gesehen das du da 2 - 3 Zusatztatsachen eingebaut hat $cnt = 0 und das darunter werde mal morgen nachschlagen was das bedeutet.
Danke nochmal für die Hilfe.
Werde melden ob es so funktioniert hat.

lG Micha
Member: colinardo
Solution colinardo Aug 14, 2014, updated at Aug 17, 2014 at 11:56:25 (UTC)
Goto Top
Ich habe gesehen das du da 2 - 3 Zusatztatsachen eingebaut hat $cnt = 0 und das darunter werde mal morgen nachschlagen was das bedeutet.
das ist nur eine Exit-Bedingung damit das Script nicht unendlich in einer Schleife hängen bleibt. Nach spätestens 60 Durchläufen bricht hier das Script ab falls $mbxExists immer noch $false sein sollte.
Member: LyriC76
LyriC76 Aug 17, 2014 updated at 09:04:57 (UTC)
Goto Top
Hi,
danke für die Hilfe.
Inzwischen läuft das Script musste noch ein paar Parameter ändern.
Ich poste hier mal das fertige Script. Ich werde es noch ein wenig erweitern, aber vielleicht hilft es anderen.
<?xml version="1.0" encoding="utf-8" ?>  
<Configuration version="1.0">  
 <Feature Name="MailboxProvisioning" Cmdlets="Enable-Mailbox">  
  <ApiCall Name="OnComplete">  
	if ($succeeded) 
	{
		$tObj = (Get-User $provisioningHandler.UserSpecifiedParameters["Identity"]).distinguishedName  
		do {
			sleep -seconds 1
			$mbxExists = Get-MailBoxPermission -Identity $tObj -User "NT AUTHORITY\SELF" -ErrorAction SilentlyContinue  
		} while (!$mbxExists)
		
		Set-ADServersettings -ViewEntireForest $true
		$USER = $provisioningHandler.UserSpecifiedParameters["Alias"]  
		$OU = (Get-User -Identity $USER).OrganizationalUnit
		$ATT = (Get-mailbox -Identity $USER).customattribute1
		
		if (($OU -eq "XXXXXXXXXXXXXXXXXXXXXXXXXXX") -and ($ATT -eq "extern"))	{  
				Enable-Mailbox -Identity $USER -Archive -ArchiveDatabase ArchivMDB
				Set-CASMailbox -Identity $USER -PopEnabled $false -ImapEnabled $false
				Set-Mailbox -Identity $USER `
					-SingleItemRecoveryEnabled $true `
					-UseDatabaseQuotaDefaults $false `
					-IssueWarningQuota 450MB `
					-ProhibitSendQuota 500MB `
					-ProhibitSendReceiveQuota 550MB `
					-ArchiveQuota 1GB `
					-ArchiveWarningQuota 800MB `
					-UseDatabaseRetentionDefaults $false `
					-RetainDeletedItemsFor "30.00:00:00" `  
					-AddressBookPolicy "XXXXXXXXXXXXXXXXXXX"  
	    }elseif (($OU -eq "XXXXXXXXXXXXXXXXXXXXXXXXXXXX") -and ($ATT -ne "extern")){  
				Enable-Mailbox -Identity $USER -Archive -ArchiveDatabase ArchivMDB
				Set-CASMailbox -Identity $USER -PopEnabled $false -ImapEnabled $false
				Set-Mailbox -Identity $USER `
					-SingleItemRecoveryEnabled $true `
					-UseDatabaseQuotaDefaults $false `
					-IssueWarningQuota 900MB `
					-ProhibitSendQuota 1GB `
					-ProhibitSendReceiveQuota "1,1GB" `  
					-ArchiveQuota 2GB `
					-ArchiveWarningQuota "1,8GB" `  
					-UseDatabaseRetentionDefaults $false `
					-RetainDeletedItemsFor "30.00:00:00" `  
					-AddressBookPolicy "XXXXXXXXXXXXXXXX"  
		}elseif (($OU -eq "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") -and ($ATT -eq "extern")){  
				Set-CASMailbox -Identity $USER -PopEnabled $false -ImapEnabled $false
				Set-Mailbox -Identity $USER `
					-SingleItemRecoveryEnabled $true `
					-UseDatabaseQuotaDefaults $false `
					-IssueWarningQuota 180MB `
					-ProhibitSendQuota 200MB `
					-ProhibitSendReceiveQuota 220MB `
					-UseDatabaseRetentionDefaults $false `
					-RetainDeletedItemsFor "21.00:00:00" `  
					-AddressBookPolicy "XXXXXXXXXXXXXXXXX"  
		}elseif (($OU -eq "XXXXXXXXXXXXXXXXXXXXXXXXXXX") -and ($ATT -ne "extern")){  
				Set-CASMailbox -Identity $USER -PopEnabled $false -ImapEnabled $false
				Set-Mailbox -Identity $USER `
					-SingleItemRecoveryEnabled $true `
					-UseDatabaseQuotaDefaults $false `
					-IssueWarningQuota 180MB `
					-ProhibitSendQuota 200MB `
					-ProhibitSendReceiveQuota 220MB `
					-UseDatabaseRetentionDefaults $false `
					-RetainDeletedItemsFor "21.00:00:00" `  
					-AddressBookPolicy "XXXXXXXXXXXXXXXX"  
		}	
	}
   </ApiCall>
  </Feature>
</Configuration>

Die XXXXXXXXXXXXXX bitte dem Passenden Wert ersetzen der bei euch zutrifft.

Nochmals vielen Dank.

lG
Micha