none
Script soll Value abfragen. Also Pulldown oder ähnliches.Möglich? RRS feed

  • Frage

  • Hallo Zusammen,

    Ich arbeite mal wieder an einem Script bezüglich meines Archivierungsprojektes.
    Folgendes soll passieren:

    Ein User tritt aus. Für diesen wird eine Distributiongruppe erstellt und diese als Forwarder in die Mailbox eingetragen. Der Member dieser erstellen Distribution/Forwardergruppe soll meistens der eingetragen Manager sein der im Ad-Account(Manager Attribut) hinterlegt ist. Doch dies nicht immer standard fall ist, benötige ich eine Abfrage am besten als Pulldown wo der Manager drin steht oder wo man induviduell einen andern Samaccountname eintragen kann.

    Habt ihr dazu eine Idee wie man sowas realisieren kann?

    Viele grüße
    Thomas  



    • Bearbeitet Digiflex Donnerstag, 21. Juni 2012 14:31
    Donnerstag, 21. Juni 2012 14:03

Antworten

  • Dein Anliegen ist wirklich schwer zu verstehen!

    Bei PowerShell an ein Pulldown-Menü  zu denken fällt mir schwer!
    Pulldown-Menü in der Konsole ohne dass du eine  Grafische Benutzeroberfläche GUI hast ?

    >> Ein User tritt aus
    Wie ein Pferd oder muss er auf Toilette?

    Spaß beiseite, ich habe das mal versucht mit einer Manager Abfrage zu machen. Ich habe zwei Varianten eingebaut. Eine reine PowerShell Variante mit Read-Host und eine mit einer Inputbox:

    # wird einmalig für inputbox gebraucht
    [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') 
    
    # Define import path
    $strImport="C:\Scripts\User-to-Archive.csv"
    #Date
    $Date=get-date -Format yyyyMMdd
    
    # Read list
    foreach ($i in (Import-Csv $strImport)) { 
    	$usr_obj = Get-QADUser $i.Name -IncludeAllProperties | select employeeID,samaccountname,manager,FirstName,LastName,c,Displayname,mail
    	$ForwarderName = "Forwarder" + " - " + $usr_obj.Lastname + "." + $usr_obj.Firstname
    	# Check if Manager exist
    	if (get-mailbox -Identity $i.Name -Filter {(ForwardingAddress -eq $null)}){	
    		if(-not($usr_obj.Manager -eq $null)){
    			$ForwarderManager = Get-ADUser -Identity $i.Name -Properties manager |Select -Expand manager
    			
    			# Manager abfragen (Konsolen Version) (Leider hat Read-Host keinen default wert!)
    			$ReadManager = Read-Host -Prompt $("Für den Manager " + $ForwarderManager + " [ENTER] drücken. [A oder a] für Abbruch. Manager eingeben:")
    			IF ($ReadManager -eq $Null) {
    				# Enter Taste wurde gedrückt (Length =0), der Defaultwert wird genommen
    				# $ForwarderName = $ForwarderName
    			}
    			ELSE {
    				# User eingabe überprüfen
    				
    				IF ($ReadManager.Length -eq 1 -and $ReadManager.Tolower() -eq 'a') {
    					"Abbruch!"
    					Exit
    				}
    				
    				# Ein neuer Manager wurde eingegeben, Wert wird geändert
    				$ForwarderManager = $ReadManager
    				
    			}
    			
    			# Manager abfragen InputBox mit Defaultwert
    			$ReadManagerTxtBx = [Microsoft.VisualBasic.Interaction]::InputBox("Manager Name:", "Manager eingeben", $ForwarderManager) 
    		    IF ($ReadManagerTxtBx.Length -eq 0) {
    				# User hat abbrechen gedrückt (oder fenster geschlossen (ist das selbe))
    				EXIT
    			}
    			# Manager übernehmen
    			$ForwarderManager = $ReadManagerTxtBx
    			
    			
    			$ForwarderMember = Get-aduser -filter {distinguishedName -like $ForwarderManager } | Select -Expand samaccountname
    			$usr_objManager = Get-ADUser $ForwarderMember -Properties * | select employeeID,samaccountname,manager,FirstName,LastName,c,Displayname,mail
    			$ForwarderSMTP = "Forwarder." + $usr_obj.Firstname + "." + $usr_obj.Lastname + "@contoso.com"
    			$ForwarderOUPath = "OU=_Left_Employees,OU=Distribution_Mail,OU=" + $usr_obj.c + ",OU=COMPANY,DC=contoso,DC=local"
    			New-DistributionGroup -Name $ForwarderName -PrimarySmtpAddress $ForwarderSMTP -OrganizationalUnit $ForwarderOUPath -Members $ForwarderMember
    
    			Start-Sleep -Seconds 10
    			Set-DistributionGroup $ForwarderName -HiddenFromAddressListsEnabled $true -RequireSenderAuthenticationEnabled $false
    			Start-Sleep -Seconds 5
    			Set-Mailbox -Identity $i.Name -HiddenFromAddressListsEnabled $true -DeliverToMailboxAndForward $true -ForwardingAddress $ForwarderSMTP -Force
    			Start-Sleep -Seconds 5
    			Add-ADGroupMember -Identity "P_DoNotSendMailToOutside" -Members $i.Name
    			Start-Sleep -Seconds 5
    			Get-InboxRule -Mailbox $i.Name |select name,description|fl| Out-File ("C:\Temp\ScriptsOut\" + $i.Name + "_" + $Date + ".txt") -Force
    			
    			# Send Mail Notification to Manager
    			$MailNotifyFrom = "GlobalIT-UserArchive <GlobalIT-UserArchive@contoso.com>"
    			$MailNotifyTo = Get-Aduser -Identity $ForwarderMember -Properties mail |Select -Expand mail
    			$MailNotifyLeftUser = Get-ADUser -Identity $i.Name -Properties displayname |Select -Expand DisplayName
    			$MailNotifySubject = "ATTENTION: New mail forwarding for your left employee created."
    			$MailNotifyBody =  ("New mail forwarding for your left employees " + $MailNotifyLeftUser + " was created." + "`n" + "`n" + "Following Rule is activ:" + "`n" + "`n" + "All Mails to:" + "`n" + $MailNotifyLeftUser + "`n" + "would be forwarded to:" + "`n" + "your Mailbox." + "`n" + "`n" + "If you wish an other recipient so open a new case over the ServiceDesk." + "`n" + "`n" + "This mail has been generated automatically. Please don't reply." + "`n" + "`n" + "If you have questions you could contact the IT Service Desk:" + "`n" + "phone:	+49 35486 512" + "`n" + "email:	IT-ServiceDesk@contoso.com" + "`n" + "`n" + "Kindest regards" + "`n" + "Your ICT-Department")
    
    			Send-MailMessage -From $MailNotifyFrom -To $MailNotifyTo -Subject $MailNotifySubject -SmtpServer relay.pcw.local -Body $MailNotifyBody -priority High -dno onSuccess, onFailure
    			
    			# Send Mail Notification to HR
    			$MailNotifyHRFrom = "GlobalIT-UserArchive <GlobalIT-UserArchive@contoso.com>"
    			#$MailNotifyHRTo = "personalmanagement@contoso.de"
    			$MailNotifyHRTo = "Thomas@contoso.com"
    			$MailNotifyHRLeftUser = Get-ADUser -Identity $i.Name -Properties displayname |Select -Expand DisplayName
    			$MailNotifyHRSubject = ("ATTENTION: New mail forwarding for left employee " + $MailNotifyHRLeftUser + " created.")
    			$MailNotifyHRBody =  ("New mail forwarding for left employee " + $MailNotifyLeftUser + " was created." + "`n" + "`n" + "Following status of the Account is activ:" + "`n" + "`n" + "All Mails to:" + "`n" + $MailNotifyLeftUser + "`n" + "would be forwarded to the manager:" + "`n" + $usr_objManager.Displayname + ", " + $usr_objManager.mail + "`n" + "`n" + "If you wish an other recipient so open a new case over the ServiceDesk." + "`n" + "`n" + "This mail has been generated automatically. Please don't reply." + "`n" + "`n" + "If you have questions you could contact the ICT Service Desk:" + "`n" + "phone:	+49 3548 9854" + "`n" + "email:	IT-Test@contoso.com" + "`n" + "`n" + "Kindest regards" + "`n" + "Your IT")
    
    			Send-MailMessage -From $MailNotifyHRFrom -To $MailNotifyHRTo -Subject $MailNotifyHRSubject -SmtpServer relay.pcw.local -Body $MailNotifyHRBody -priority High -dno onSuccess, onFailure
    
    		}
    		else{Write-Host "Es konnte kein Forwarder erstellt werden, da beim User kein Manager eingetragen ist! Mail an ICT_OP & HR"}
    	}
    	else {
    	$ExistForwarder = Get-Mailbox -Identity $i.Name | select-object -ExpandProperty ForwardingAddress |select name
    	Write-Host "Es exestiert bereits ein Forwarder zu $ExistForwarder! Mail an IT_OP"}
    }


    Please click “Mark as Answer” if my post answers your question and click Vote as Help if my Post helps you.
    Bitte markiere hilfreiche Beiträge von mir als Hilfreich und Beiträge die deine Frage ganz oder teilweise beantwortet haben als Antwort.
    My PowerShell Blog http://www.admin-source.info
    [string](0..21|%{[char][int]([int]("{0:d}" -f 0x28)+('755964655967-86965747271757624-8796158066061').substring(($_*2),2))})-replace' '



    Freitag, 22. Juni 2012 10:36

Alle Antworten

  • Hier der aktuelle Script wo dies integriert werden soll:

    # Define import path
    $strImport="C:\Scripts\User-to-Archive.csv"
    #Date
    $Date=get-date -Format yyyyMMdd
    
    # Read list
    foreach ($i in (Import-Csv $strImport)) { 
    	$usr_obj = Get-QADUser $i.Name -IncludeAllProperties | select employeeID,samaccountname,manager,FirstName,LastName,c,Displayname,mail
    	$ForwarderName = "Forwarder" + " - " + $usr_obj.Lastname + "." + $usr_obj.Firstname
    	# Check if Manager exist
    	if (get-mailbox -Identity $i.Name -Filter {(ForwardingAddress -eq $null)}){	
    		if(-not($usr_obj.Manager -eq $null)){
    		$ForwarderManager = Get-ADUser -Identity $i.Name -Properties manager |Select -Expand manager
    		$ForwarderMember = Get-aduser -filter {distinguishedName -like $ForwarderManager } | Select -Expand samaccountname
    		$usr_objManager = Get-ADUser $ForwarderMember -Properties * | select employeeID,samaccountname,manager,FirstName,LastName,c,Displayname,mail
    		$ForwarderSMTP = "Forwarder." + $usr_obj.Firstname + "." + $usr_obj.Lastname + "@contoso.com"
    		$ForwarderOUPath = "OU=_Left_Employees,OU=Distribution_Mail,OU=" + $usr_obj.c + ",OU=COMPANY,DC=contoso,DC=local"
    		New-DistributionGroup -Name $ForwarderName -PrimarySmtpAddress $ForwarderSMTP -OrganizationalUnit $ForwarderOUPath -Members $ForwarderMember
    
    		Start-Sleep -Seconds 10
    		Set-DistributionGroup $ForwarderName -HiddenFromAddressListsEnabled $true -RequireSenderAuthenticationEnabled $false
    		Start-Sleep -Seconds 5
    		Set-Mailbox -Identity $i.Name -HiddenFromAddressListsEnabled $true -DeliverToMailboxAndForward $true -ForwardingAddress $ForwarderSMTP -Force
    		Start-Sleep -Seconds 5
    		Add-ADGroupMember -Identity "P_DoNotSendMailToOutside" -Members $i.Name
    		Start-Sleep -Seconds 5
    		Get-InboxRule -Mailbox $i.Name |select name,description|fl| Out-File ("C:\Temp\ScriptsOut\" + $i.Name + "_" + $Date + ".txt") -Force
    		
    		# Send Mail Notification to Manager
    		$MailNotifyFrom = "GlobalIT-UserArchive <GlobalIT-UserArchive@contoso.com>"
    		$MailNotifyTo = Get-Aduser -Identity $ForwarderMember -Properties mail |Select -Expand mail
    		$MailNotifyLeftUser = Get-ADUser -Identity $i.Name -Properties displayname |Select -Expand DisplayName
    		$MailNotifySubject = "ATTENTION: New mail forwarding for your left employee created."
    		$MailNotifyBody =  ("New mail forwarding for your left employees " + $MailNotifyLeftUser + " was created." + "`n" + "`n" + "Following Rule is activ:" + "`n" + "`n" + "All Mails to:" + "`n" + $MailNotifyLeftUser + "`n" + "would be forwarded to:" + "`n" + "your Mailbox." + "`n" + "`n" + "If you wish an other recipient so open a new case over the ServiceDesk." + "`n" + "`n" + "This mail has been generated automatically. Please don't reply." + "`n" + "`n" + "If you have questions you could contact the IT Service Desk:" + "`n" + "phone:	+49 35486 512" + "`n" + "email:	IT-ServiceDesk@contoso.com" + "`n" + "`n" + "Kindest regards" + "`n" + "Your ICT-Department")
    
    		Send-MailMessage -From $MailNotifyFrom -To $MailNotifyTo -Subject $MailNotifySubject -SmtpServer relay.pcw.local -Body $MailNotifyBody -priority High -dno onSuccess, onFailure
    		
    		# Send Mail Notification to HR
    		$MailNotifyHRFrom = "GlobalIT-UserArchive <GlobalIT-UserArchive@contoso.com>"
    		#$MailNotifyHRTo = "personalmanagement@contoso.de"
    		$MailNotifyHRTo = "Thomas@contoso.com"
    		$MailNotifyHRLeftUser = Get-ADUser -Identity $i.Name -Properties displayname |Select -Expand DisplayName
    		$MailNotifyHRSubject = ("ATTENTION: New mail forwarding for left employee " + $MailNotifyHRLeftUser + " created.")
    		$MailNotifyHRBody =  ("New mail forwarding for left employee " + $MailNotifyLeftUser + " was created." + "`n" + "`n" + "Following status of the Account is activ:" + "`n" + "`n" + "All Mails to:" + "`n" + $MailNotifyLeftUser + "`n" + "would be forwarded to the manager:" + "`n" + $usr_objManager.Displayname + ", " + $usr_objManager.mail + "`n" + "`n" + "If you wish an other recipient so open a new case over the ServiceDesk." + "`n" + "`n" + "This mail has been generated automatically. Please don't reply." + "`n" + "`n" + "If you have questions you could contact the ICT Service Desk:" + "`n" + "phone:	+49 3548 9854" + "`n" + "email:	IT-Test@contoso.com" + "`n" + "`n" + "Kindest regards" + "`n" + "Your IT")
    
    		Send-MailMessage -From $MailNotifyHRFrom -To $MailNotifyHRTo -Subject $MailNotifyHRSubject -SmtpServer relay.pcw.local -Body $MailNotifyHRBody -priority High -dno onSuccess, onFailure
    
    		}
    		else{Write-Host "Es konnte kein Forwarder erstellt werden, da beim User kein Manager eingetragen ist! Mail an ICT_OP & HR"}
    	}
    	else {
    	$ExistForwarder = Get-Mailbox -Identity $i.Name | select-object -ExpandProperty ForwardingAddress |select name
    	Write-Host "Es exestiert bereits ein Forwarder zu $ExistForwarder! Mail an IT_OP"}
    }

    VG
    Thomas
    Donnerstag, 21. Juni 2012 15:02
  • Dein Anliegen ist wirklich schwer zu verstehen!

    Bei PowerShell an ein Pulldown-Menü  zu denken fällt mir schwer!
    Pulldown-Menü in der Konsole ohne dass du eine  Grafische Benutzeroberfläche GUI hast ?

    >> Ein User tritt aus
    Wie ein Pferd oder muss er auf Toilette?

    Spaß beiseite, ich habe das mal versucht mit einer Manager Abfrage zu machen. Ich habe zwei Varianten eingebaut. Eine reine PowerShell Variante mit Read-Host und eine mit einer Inputbox:

    # wird einmalig für inputbox gebraucht
    [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') 
    
    # Define import path
    $strImport="C:\Scripts\User-to-Archive.csv"
    #Date
    $Date=get-date -Format yyyyMMdd
    
    # Read list
    foreach ($i in (Import-Csv $strImport)) { 
    	$usr_obj = Get-QADUser $i.Name -IncludeAllProperties | select employeeID,samaccountname,manager,FirstName,LastName,c,Displayname,mail
    	$ForwarderName = "Forwarder" + " - " + $usr_obj.Lastname + "." + $usr_obj.Firstname
    	# Check if Manager exist
    	if (get-mailbox -Identity $i.Name -Filter {(ForwardingAddress -eq $null)}){	
    		if(-not($usr_obj.Manager -eq $null)){
    			$ForwarderManager = Get-ADUser -Identity $i.Name -Properties manager |Select -Expand manager
    			
    			# Manager abfragen (Konsolen Version) (Leider hat Read-Host keinen default wert!)
    			$ReadManager = Read-Host -Prompt $("Für den Manager " + $ForwarderManager + " [ENTER] drücken. [A oder a] für Abbruch. Manager eingeben:")
    			IF ($ReadManager -eq $Null) {
    				# Enter Taste wurde gedrückt (Length =0), der Defaultwert wird genommen
    				# $ForwarderName = $ForwarderName
    			}
    			ELSE {
    				# User eingabe überprüfen
    				
    				IF ($ReadManager.Length -eq 1 -and $ReadManager.Tolower() -eq 'a') {
    					"Abbruch!"
    					Exit
    				}
    				
    				# Ein neuer Manager wurde eingegeben, Wert wird geändert
    				$ForwarderManager = $ReadManager
    				
    			}
    			
    			# Manager abfragen InputBox mit Defaultwert
    			$ReadManagerTxtBx = [Microsoft.VisualBasic.Interaction]::InputBox("Manager Name:", "Manager eingeben", $ForwarderManager) 
    		    IF ($ReadManagerTxtBx.Length -eq 0) {
    				# User hat abbrechen gedrückt (oder fenster geschlossen (ist das selbe))
    				EXIT
    			}
    			# Manager übernehmen
    			$ForwarderManager = $ReadManagerTxtBx
    			
    			
    			$ForwarderMember = Get-aduser -filter {distinguishedName -like $ForwarderManager } | Select -Expand samaccountname
    			$usr_objManager = Get-ADUser $ForwarderMember -Properties * | select employeeID,samaccountname,manager,FirstName,LastName,c,Displayname,mail
    			$ForwarderSMTP = "Forwarder." + $usr_obj.Firstname + "." + $usr_obj.Lastname + "@contoso.com"
    			$ForwarderOUPath = "OU=_Left_Employees,OU=Distribution_Mail,OU=" + $usr_obj.c + ",OU=COMPANY,DC=contoso,DC=local"
    			New-DistributionGroup -Name $ForwarderName -PrimarySmtpAddress $ForwarderSMTP -OrganizationalUnit $ForwarderOUPath -Members $ForwarderMember
    
    			Start-Sleep -Seconds 10
    			Set-DistributionGroup $ForwarderName -HiddenFromAddressListsEnabled $true -RequireSenderAuthenticationEnabled $false
    			Start-Sleep -Seconds 5
    			Set-Mailbox -Identity $i.Name -HiddenFromAddressListsEnabled $true -DeliverToMailboxAndForward $true -ForwardingAddress $ForwarderSMTP -Force
    			Start-Sleep -Seconds 5
    			Add-ADGroupMember -Identity "P_DoNotSendMailToOutside" -Members $i.Name
    			Start-Sleep -Seconds 5
    			Get-InboxRule -Mailbox $i.Name |select name,description|fl| Out-File ("C:\Temp\ScriptsOut\" + $i.Name + "_" + $Date + ".txt") -Force
    			
    			# Send Mail Notification to Manager
    			$MailNotifyFrom = "GlobalIT-UserArchive <GlobalIT-UserArchive@contoso.com>"
    			$MailNotifyTo = Get-Aduser -Identity $ForwarderMember -Properties mail |Select -Expand mail
    			$MailNotifyLeftUser = Get-ADUser -Identity $i.Name -Properties displayname |Select -Expand DisplayName
    			$MailNotifySubject = "ATTENTION: New mail forwarding for your left employee created."
    			$MailNotifyBody =  ("New mail forwarding for your left employees " + $MailNotifyLeftUser + " was created." + "`n" + "`n" + "Following Rule is activ:" + "`n" + "`n" + "All Mails to:" + "`n" + $MailNotifyLeftUser + "`n" + "would be forwarded to:" + "`n" + "your Mailbox." + "`n" + "`n" + "If you wish an other recipient so open a new case over the ServiceDesk." + "`n" + "`n" + "This mail has been generated automatically. Please don't reply." + "`n" + "`n" + "If you have questions you could contact the IT Service Desk:" + "`n" + "phone:	+49 35486 512" + "`n" + "email:	IT-ServiceDesk@contoso.com" + "`n" + "`n" + "Kindest regards" + "`n" + "Your ICT-Department")
    
    			Send-MailMessage -From $MailNotifyFrom -To $MailNotifyTo -Subject $MailNotifySubject -SmtpServer relay.pcw.local -Body $MailNotifyBody -priority High -dno onSuccess, onFailure
    			
    			# Send Mail Notification to HR
    			$MailNotifyHRFrom = "GlobalIT-UserArchive <GlobalIT-UserArchive@contoso.com>"
    			#$MailNotifyHRTo = "personalmanagement@contoso.de"
    			$MailNotifyHRTo = "Thomas@contoso.com"
    			$MailNotifyHRLeftUser = Get-ADUser -Identity $i.Name -Properties displayname |Select -Expand DisplayName
    			$MailNotifyHRSubject = ("ATTENTION: New mail forwarding for left employee " + $MailNotifyHRLeftUser + " created.")
    			$MailNotifyHRBody =  ("New mail forwarding for left employee " + $MailNotifyLeftUser + " was created." + "`n" + "`n" + "Following status of the Account is activ:" + "`n" + "`n" + "All Mails to:" + "`n" + $MailNotifyLeftUser + "`n" + "would be forwarded to the manager:" + "`n" + $usr_objManager.Displayname + ", " + $usr_objManager.mail + "`n" + "`n" + "If you wish an other recipient so open a new case over the ServiceDesk." + "`n" + "`n" + "This mail has been generated automatically. Please don't reply." + "`n" + "`n" + "If you have questions you could contact the ICT Service Desk:" + "`n" + "phone:	+49 3548 9854" + "`n" + "email:	IT-Test@contoso.com" + "`n" + "`n" + "Kindest regards" + "`n" + "Your IT")
    
    			Send-MailMessage -From $MailNotifyHRFrom -To $MailNotifyHRTo -Subject $MailNotifyHRSubject -SmtpServer relay.pcw.local -Body $MailNotifyHRBody -priority High -dno onSuccess, onFailure
    
    		}
    		else{Write-Host "Es konnte kein Forwarder erstellt werden, da beim User kein Manager eingetragen ist! Mail an ICT_OP & HR"}
    	}
    	else {
    	$ExistForwarder = Get-Mailbox -Identity $i.Name | select-object -ExpandProperty ForwardingAddress |select name
    	Write-Host "Es exestiert bereits ein Forwarder zu $ExistForwarder! Mail an IT_OP"}
    }


    Please click “Mark as Answer” if my post answers your question and click Vote as Help if my Post helps you.
    Bitte markiere hilfreiche Beiträge von mir als Hilfreich und Beiträge die deine Frage ganz oder teilweise beantwortet haben als Antwort.
    My PowerShell Blog http://www.admin-source.info
    [string](0..21|%{[char][int]([int]("{0:d}" -f 0x28)+('755964655967-86965747271757624-8796158066061').substring(($_*2),2))})-replace' '



    Freitag, 22. Juni 2012 10:36