Solved

Powershell - Could anybody analyze my script?

Posted on 2013-05-27
21
326 Views
Last Modified: 2013-05-30
Hi folks,

the csv
I open this topic again for attention from other specialists. It is always good to get a second opinion.

Could anybody pay attention so far for my script?  First you see the pic of my CSV
with all values. I'm a real rookie with powershell so i've to test everything and spent
a lot of time for it. Thanks god i found this community with nice specialists  around.

I'm adding the setup of different custom attributes with the elseif command. Maybe
it should be better to use a hash-table for it.
like this form:
$compattrib3 = @{
"contoso" =  "D"
"contoso2" = "F"
"All other" = "Q"
}

$compattrib12 = @{
"contoso" = "ZE"
"contoso2" = "KU"
"All other" = "ER"
}

Open in new window



pls also see:
my other thread

Import-Module ActiveDirectory  
ForEach ($User in  Import-Csv "c:\export_51.csv"){#$user}
	switch($user){
		{$_.Version -eq "MSXC2010" -and $_.Action -eq "new"} {
			#user which have department EMC should not use the standard database
			$DBuser = (Get-ADUser -identity $user.UserID).department
			If ($DBuser -like "*EMC*") {
				$db = "DBEMC00$("{0:00}" -f (1..45 | Get-random))"
				Enable-Mailbox -Identity $user.UserId -Database $db
			} 
			else {
				Enable-Mailbox -Identity $user.UserId
			#}
		#}

             ##########################
            ###  here should set 2nd smtp and custom adress 
            ##########################


           ########################
           # Set custom attributes below without hash-table not working could you pls check
            ##########################
		   
	   
		 If ($user.company -eq "EMC")
                 {

                Set-Mailbox -CustomAttribute5 'E' -CustomAttribute11 'EM' -CustomAttribute13 'EMC' -Identity $User.userid
               }

             ElseIf ($user.company -eq "CAG")
             {
            Set-Mailbox -CustomAttribute5 'C' -CustomAttribute11 'CA' -CustomAttribute13 'CAG' -         Identity $User.userid
             }
           ElseIf ($user.company -ne "CAG" -or $user.company -ne "EMC")
           {
          Set-Mailbox -CustomAttribute5 'K' -CustomAttribute13 'ucom' -Identity $User.userid
           }
           ElseIf ($user.company -eq "CHT") 
          {
         Set-Mailbox -CustomAttribute11 'CHT' -Identity $User.userid
           }
          ElseIf ($user.company -eq "CFT*")
           {
          Set-Mailbox -CustomAttribute11 'LFT' -Identity $User.userid
           }
          ElseIf ($user.company -eq "CXD*")
            {
         Set-Mailbox -CustomAttribute10 'CXD' -Identity $User.userid
          }



           $descnew = $user.orderID
           $desccurrent = (Get-ADUser -identity $user.userid -Properties Description).Description
           set-aduser -identity $user.userid -description ($desccurrent+"/"+$descnew)
			}
				}
		{$_.Version -eq "MSXC2010" -and $_.Action -eq "delete"} {
		   
		   $dbnew = (Get-Mailbox -Identity $user.userid | Select-Object Database)
		   $desccurrent = (Get-ADUser -identity $user.userid -Properties   Description).Description
           set-aduser -identity $user.userid -description ($desccurrent+"/"+$dbnew)
		
			#disable mailbox exchange 2010
		   	Disable-Mailbox -Identity $user.UserID -confirm:$false
	   		write-host -ForegroundColor red -backgroundcolor blue "Mailbox of $_.user.UserId has been disabled"
	   	  
		
		}
		{$_.Version -eq "MSXC2010" -and $_.Action -eq "new"} {}
		{$_.Version -eq "MSXC2010" -and $_.Action -eq "delete"} {}
		{$_.Version -eq "" -and $_.Action -eq "new" -and $_.Product -eq "AdAccount"} {
		
		
		    $NewPassword = $user.UserId.Insert(5,"$")
	        $NewPassword = $newPassword.Insert(3,"e")
	        $NewPassword = $newPassword.Remove(0, 1)
	        $newPassword = $newPassword.Insert(0,"Z")          
	    	Set-ADAccountPassword -Identity $user.UserId -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $newPassword -Force)	  
		    write-host -ForegroundColor yellow "Password of $_.user.UserId has been set to $newPassword" 
	  	}
		
         	}
                  }

Open in new window



Sorry that i post this topic. I dont wanna be the top thread starter here. :)
Hereby I would like also involve other powershell specilists. I'm working
for weeks on this problem and i like to finish my work asap.
Thank you for understanding.

Appreciate for your help
Mandy
0
Comment
Question by:Mandy_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 5
  • 4
21 Comments
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 167 total points
ID: 39200546
i fixed the custom attribute section in your script, take a look.
in regards to set 2ns smtp address and custom address, where are they located?

Import-Module ActiveDirectory  
ForEach ($User in  Import-Csv "c:\export_51.csv"){#$user}
	switch($user){
		{$_.Version -eq "MSXC2010" -and $_.Action -eq "new"} {
			#user which have department EMC should not use the standard database
			$DBuser = (Get-ADUser -identity $user.UserID).department
			If ($DBuser -like "*EMC*") {
				$db = "DBEMC00$("{0:00}" -f (1..45 | Get-random))"
				Enable-Mailbox -Identity $user.UserId -Database $db
			} 
			else {
				Enable-Mailbox -Identity $user.UserId
			
				##########################
	            ###  here should set 2nd smtp and custom adress 
				
	            ##########################


           		########################
           		# Set custom attributes below without hash-table not working could you pls check

		   		switch($user.company){
					"EMC" {Set-Mailbox -Identity $User.userid -CustomAttribute5 'E' -CustomAttribute11 'EM' -CustomAttribute13 'EMC'}
					"CAG" {Set-Mailbox -Identity $User.userid -CustomAttribute5 'C' -CustomAttribute11 'CA' -CustomAttribute13 'CAG'}
					"CHT" {Set-Mailbox -Identity $User.userid -CustomAttribute11 'CHT' -CustomAttribute5 'K' -CustomAttribute13 'ucom'}
					"CFT*" {Set-Mailbox -Identity $User.userid -CustomAttribute11 'LFT' -CustomAttribute5 'K' -CustomAttribute13 'ucom'}
					"CXD*" {Set-Mailbox -Identity $User.userid -CustomAttribute11 'CXD' -CustomAttribute5 'K' -CustomAttribute13 'ucom'}
				}
				##########################
							
				$descnew = $user.orderID
	           	$desccurrent = (Get-ADUser -identity $user.userid -Properties Description).Description
	           	set-aduser -identity $user.userid -description ($desccurrent+"/"+$descnew)
			}
		}
		
		{$_.Version -eq "MSXC2010" -and $_.Action -eq "delete"} {
		   
		   $dbnew = (Get-Mailbox -Identity $user.userid | Select-Object Database)
		   $desccurrent = (Get-ADUser -identity $user.userid -Properties   Description).Description
           set-aduser -identity $user.userid -description ($desccurrent+"/"+$dbnew)
		
			#disable mailbox exchange 2010
		   	Disable-Mailbox -Identity $user.UserID -confirm:$false
	   		write-host -ForegroundColor red -backgroundcolor blue "Mailbox of $_.user.UserId has been disabled"
		}
		
		{$_.Version -eq "MSXC2010" -and $_.Action -eq "new"} {}
		
		{$_.Version -eq "MSXC2010" -and $_.Action -eq "delete"} {}
		
		{$_.Version -eq "" -and $_.Action -eq "new" -and $_.Product -eq "AdAccount"} {
		    $NewPassword = $user.UserId.Insert(5,"$")
	        $NewPassword = $newPassword.Insert(3,"e")
	        $NewPassword = $newPassword.Remove(0, 1)
	        $newPassword = $newPassword.Insert(0,"Z")          
	    	Set-ADAccountPassword -Identity $user.UserId -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $newPassword -Force)	  
		    write-host -ForegroundColor yellow "Password of $_.user.UserId has been set to $newPassword" 
	  	}		
	}
}

Open in new window

0
 
LVL 2

Author Comment

by:Mandy_
ID: 39200785
sorry i delete the other thread. Pls let this questions. thank you
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39200787
Mandy,

what else do u need?
can u address my questions?
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 2

Author Comment

by:Mandy_
ID: 39200912
Thank you for your fast response.  

1. Custom attributes - I have 245 3- or 4-lettercodes
how can i write "all other" with the same custom attributes   5 = T  11=GU and 13=casu

2. Set mailadress (2nd smtp, custom) in line 15 of the script above

3. What about to handle Exchange 2003 account with the same activities as above?

thanks
mandy
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39200978
>>1. Custom attributes - I have 245 3- or 4-lettercodes
i don't understand.
can u give an example?

>>2. Set mailadress (2nd smtp, custom) in line 15 of the script above
where to take the mail address from?
0
 
LVL 2

Author Comment

by:Mandy_
ID: 39201290
hi,

i mean 245 company codes.  Can i do this with the default parameter to
set all other company with the same customer attributes?  pls see the last line

2. Mail these are only 2nd smtp like user.id@emc.com for every user nothing more
and a custom mail also for every user like  MRS@userid  thats all


switch($user.company){
					"EMC" {Set-Mailbox -Identity $User.userid -CustomAttribute5 'E' -CustomAttribute11 'EM' -CustomAttribute13 'EMC'}
					"CAG" {Set-Mailbox -Identity $User.userid -CustomAttribute5 'C' -CustomAttribute11 'CA' -CustomAttribute13 'CAG'}
					"CHT" {Set-Mailbox -Identity $User.userid -CustomAttribute11 'CHT' -CustomAttribute5 'K' -CustomAttribute13 'ucom'}
					"CFT*" {Set-Mailbox -Identity $User.userid -CustomAttribute11 'LFT' -CustomAttribute5 'K' -CustomAttribute13 'ucom'}
					"CXD*" {Set-Mailbox -Identity $User.userid -CustomAttribute11 'CXD' -CustomAttribute5 'K' -CustomAttribute13 'ucom'}

default {"-CustomAttribute11 'CXD' -CustomAttribute5 'K' -CustomAttribute13 'ucom'}
}

Open in new window

0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39201454
like this:
switch($user.company){
					"EMC" {Set-Mailbox -Identity $User.userid -CustomAttribute5 'E' -CustomAttribute11 'EM' -CustomAttribute13 'EMC'}
					"CAG" {Set-Mailbox -Identity $User.userid -CustomAttribute5 'C' -CustomAttribute11 'CA' -CustomAttribute13 'CAG'}
					"CHT" {Set-Mailbox -Identity $User.userid -CustomAttribute11 'CHT' -CustomAttribute5 'K' -CustomAttribute13 'ucom'}
					"CFT*" {Set-Mailbox -Identity $User.userid -CustomAttribute11 'LFT' -CustomAttribute5 'K' -CustomAttribute13 'ucom'}
					"CXD*" {Set-Mailbox -Identity $User.userid -CustomAttribute11 'CXD' -CustomAttribute5 'K' -CustomAttribute13 'ucom'}
default {Set-Mailbox -Identity $User.userid -CustomAttribute11 'CXD' -CustomAttribute5 'K' -CustomAttribute13 'ucom'}
}

Open in new window

0
 
LVL 2

Author Comment

by:Mandy_
ID: 39201469
yes thats nice that should be work. Currently only missing to set the mails as i decri be
above.
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39201481
to add second smtp address:
  $user = Get-Mailbox -Identity $User.userid
   $user.EmailAddresses+=<2nd smtp address>
   Set-Mailbox $user -EmailAddresses $user.EmailAddresses   

Open in new window

0
 
LVL 69

Assisted Solution

by:Qlemo
Qlemo earned 333 total points
ID: 39201869
In http:#a39201454, I would use the same sequence of custom attributes - that is much better to read:
switch($user.company){
  "EMC"  {Set-Mailbox -Identity $User.userid -CustomAttribute5 'E' -CustomAttribute11 'EM'  -CustomAttribute13 'EMC' }
  "CAG"  {Set-Mailbox -Identity $User.userid -CustomAttribute5 'C' -CustomAttribute11 'CA'  -CustomAttribute13 'CAG' }
  "CHT"  {Set-Mailbox -Identity $User.userid -CustomAttribute5 'K' -CustomAttribute11 'CHT' -CustomAttribute13 'ucom'}
  "CFT*" {Set-Mailbox -Identity $User.userid -CustomAttribute5 'K' -CustomAttribute11 'LFT' -CustomAttribute13 'ucom'}
  "CXD*" {Set-Mailbox -Identity $User.userid -CustomAttribute5 'K' -CustomAttribute11 'CXD' -CustomAttribute13 'ucom'}
 default {Set-Mailbox -Identity $User.userid -CustomAttribute5 'T' -CustomAttribute11 'GU'  -CustomAttribute13 'casu'}
}

Open in new window

Note that I have also changed the default, as you initially asked for that set of values, but in your example later copied the CXD* case.
0
 
LVL 2

Author Comment

by:Mandy_
ID: 39202321
hi,

i insert the mail and the custom attribute part. the debugger not showing any errors
but the script not running. Nothing happen. :(
Could you pls check?  thanks in advance mandy


Import-Module ActiveDirectory  
ForEach ($User in  Import-Csv "c:\export.csv"){ #$user}
	switch($user){
		{$_.Version -eq "MSXC2010" -and $_.action -eq "new"} {
			
			$DBuser = (Get-ADUser -identity $user.UserID).department
			If ($DBuser -like "*EMC*") {
				$db = "DBEMC00$("{0:00}" -f (1..45 | Get-random))"
				Enable-Mailbox -Identity $user.UserId -Database $db
			} 
			else {
				Enable-Mailbox -Identity $user.UserId
		     
Start-Sleep -Second 5
#set mailbox 
            $user = Get-Mailbox -Identity $User.userid
            $user.EmailAddresses = "$user.userid@emc.com"
            $custom.adress = "$User.userid@mrs"
            Set-Mailbox -EmailAddresses $user.Emailadresses,MRS:$custom.adress
            #Set-Mailbox $user -EmailAddresses $user.EmailAddresses   		

            write-host -ForegroundColor green "Mailbox of $($user.UserId) $($user.emailadresses) has been enabled"		
		   
 switch($user.company){
"LCA*" {Set-Mailbox -Identity $User.userid -CustomAttribute4 'T' -CustomAttribute10 'LC' -CustomAttribute14 'vcom'}
"LCG*" {Set-Mailbox -Identity $User.userid -CustomAttribute4 'K' -CustomAttribute10 'LCAG' -CustomAttribute14 'vcom'}
"LCY*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'LCY' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
"LCT*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'LCT' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
"LCP*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'LCP' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
"LTC*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'LTC' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
"LVT*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'LVT' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
"LCN*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'LCN' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
"BTL*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'BTL' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
"BTM*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'BTM' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
 "BTS*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'BTS' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
 "DTN*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'DTN' -CustomAttribute4 'R' -CustomAttribute14 'vcom'}
"KPA*" {Set-Mailbox -Identity $User.userid -CustomAttribute10 'KPA' -CustomAttribute4 'R'  -CustomAttribute14 'vcom'}
default {Set-Mailbox -Identity $User.userid -CustomAttribute10 'EMC' -CustomAttribute4 'R' -CustomAttribute13 'vcom'}
}

           $descnew = $user.orderid
           $desccurrent = (Get-ADUser -identity $user.userid -Properties  Description).Description
           set-aduser -identity $user.userid -description ($desccurrent+"/"+$descnew+" ")
                  }
   			
			}
		{$_.Version -eq "MSXC2010" -and $_.action -eq "delete"} { 
		   
  $dbnew = (Get-Mailbox -Identity $user.userid | Select-Object Database)
  $desccurrent = (Get-ADUser -identity $user.userid -Properties Description).Description
  set-aduser -identity $user.userid -description ($desccurrent+"/"+$dbnew+" ")
		
			#disable mailbox exchange 2010
		   	Disable-Mailbox -Identity $user.UserID -confirm:$false
write-host -ForegroundColor red -backgroundcolor yellow "Mailbox of $($user.UserId) has been disabled"
	   	  
		
		}
		{$_.Version -eq "MSXC2010" -and $_.action -eq "new"} {}
		{$_.Version -eq "MSXC2010" -and $_.action -eq "delete"} {}
		{$_.Version -eq "" -and $_.action -eq "new" -and $_.Produkt -eq "AdAccount"} {
		
		
		$NewPassword = $user.UserId.Insert(5,"$")
	        $NewPassword = $newPassword.Insert(3,"e")
	        $NewPassword = $newPassword.Remove(0, 1)
	        $newPassword = $newPassword.Insert(0,"Z")          
	    	Set-ADAccountPassword -Identity $user.UserId -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $newPassword -Force)	  
write-host -ForegroundColor yellow "Password of $($user.UserId) has been set to $newPassword" 
		}
		
	}

}

Open in new window

0
 
LVL 2

Author Comment

by:Mandy_
ID: 39203885
Anybody here could take a look to my script above?  Thank you so much
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39204203
1. This cases are doubled, once with action and once without:
    {$_.Version -eq "MSXC2010" -and $_.action -eq "new"} {}
    {$_.Version -eq "MSXC2010" -and $_.action -eq "delete"} {}

Open in new window

It doesn't matter, as the switch will evaluate all conditions, unless a break or continue is encountered.

2. To use wildcards in simple switch conditions, we need to tell switch that:
switch -wildcard ($user.company){
 "LCA*" {Set-Mailbox -Identity $User.userid -CustomAttribute4 'T' -CustomAttribute10 'LC'   -CustomAttribute14 'vcom'}
 "LCG*" {Set-Mailbox -Identity $User.userid -CustomAttribute4 'K' -CustomAttribute10 'LCAG' -CustomAttribute14 'vcom'}
 "LCY*" {Set-Mailbox -Identity $User.userid -CustomAttribute4 'R' -CustomAttribute10 'LCY'  -CustomAttribute14 'vcom'}
 "LCT*" {Set-Mailbox -Identity $User.userid -CustomAttribute4 'R' -CustomAttribute10 'LCT'  -CustomAttribute14 'vcom'}
 "LCP*" {Set-Mailbox -Identity $User.userid -CustomAttribute4 'R' -CustomAttribute10 'LCP'  -CustomAttribute14 'vcom'}
 "LTC*" {Set-Mailbox -Identity $User.userid -CustomAttribute4 'R' -CustomAttribute10 'LTC'  -CustomAttribute14 'vcom'}
 "LVT*" {Set-Mailbox -Identity $User.userid -CustomAttribute4 'R' -CustomAttribute10 'LVT'  -CustomAttribute14 'vcom'}
 "LCN*" {Set-Mailbox -Identity $User.userid -CustomAttribute4 'R' -CustomAttribute10 'LCN'  -CustomAttribute14 'vcom'}
 "BTL*" {Set-Mailbox -Identity $User.userid -CustomAttribute4 'R' -CustomAttribute10 'BTL'  -CustomAttribute14 'vcom'}
 "BTM*" {Set-Mailbox -Identity $User.userid -CustomAttribute4 'R' -CustomAttribute10 'BTM'  -CustomAttribute14 'vcom'}
 "BTS*" {Set-Mailbox -Identity $User.userid -CustomAttribute4 'R' -CustomAttribute10 'BTS'  -CustomAttribute14 'vcom'}
 "DTN*" {Set-Mailbox -Identity $User.userid -CustomAttribute4 'R' -CustomAttribute10 'DTN'  -CustomAttribute14 'vcom'}
 "KPA*" {Set-Mailbox -Identity $User.userid -CustomAttribute4 'R' -CustomAttribute10 'KPA'  -CustomAttribute14 'vcom'}
default {Set-Mailbox -Identity $User.userid -CustomAttribute4 'R' -CustomAttribute10 'EMC'  -CustomAttribute14 'vcom'}
}

Open in new window

Note that the default case changed attribute 13 instead of 14.
Also note that you are changing the context of $user from the CSV to a mailbox object - this is prone to errors.
I would change the switch to something more obvious anyway:
$attr = @{attr4 = 'R'; attr10 = $user.company.Substring(0,3)}
switch -wildcard ($user.company){
 "LCA*" {$attr = @{attr4 = 'T'; attr10 = 'LC'  }; break}
 "LCG*" {$attr = @{attr4 = 'K'; attr10 = 'LCAG'}; break}
 "LCY*" {break}
 "LCT*" {break}
 "LCP*" {break}
 "LTC*" {break}
 "LVT*" {break}
 "LCN*" {break}
 "BTL*" {break}
 "BTM*" {break}
 "BTS*" {break}
 "DTN*" {break}
 "KPA*" {break}
default {$attr.attr10 = 'EMC'}
}
Set-Mailbox -Identity $User.userid -CustomAttribute4 $attr.attr4 -CustomAttribute10 $attr.attr10 -CustomAttribute14 $attr.attr14

Open in new window

0
 
LVL 2

Author Comment

by:Mandy_
ID: 39204511
Thank you. In which form you would to insert the creation of secondary mail and
custome mailadress?

$user = Get-Mailbox -Identity $User.userid
            $user.EmailAddresses = "$user.userid@emc.com"
            $custom.adress = "$User.userid@mrs"
            Set-Mailbox -EmailAddresses $user.Emailadresses,MRS:$custom.adress


Youn mean this will have a conflict?
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 39204690
I would rather go and use a different var:
$mbox = Get-Mailbox -Identity $User.userid
$mbox.EmailAddresses = $user.userid + "@emc.com"
$custom.adress = $User.userid+ "@mrs"
Set-Mailbox -Identity $User.userid -EmailAddresses $mbox.Emailadresses,MRS:$custom.adress

Open in new window

0
 
LVL 2

Author Comment

by:Mandy_
ID: 39204743
thank you i will change and check again
0
 
LVL 2

Author Comment

by:Mandy_
ID: 39205707
hi,

so far everything is working fine. The only problem left to set the mail addresstype to MRS

i did it this way but not functional

 Set-Mailbox -Identity $User.userid -EmailAddresses $mbox.Emailaddresses +="MRS:$user.userid@MRS"  -EmailAddressPolicyEnabled $False

Open in new window


or this also not working

{$Temp = Get-Mailbox -identity $User.userid}; $Temp.EmailAddresses +="MRS:" + $mbox.mrs ;Set-Mailbox $temp  -EmailAddressPolicyEnabled $False

Open in new window

0
 
LVL 69

Accepted Solution

by:
Qlemo earned 333 total points
ID: 39206085
I can't tell how to set up MRS types, but you would need to change the expression in double quotes (and the assignment is not necessary):
 Set-Mailbox -Identity $User.userid -EmailAddresses $mbox.Emailaddresses +"MRS:$($user.userid)@MRS"  -EmailAddressPolicyEnabled $False

Open in new window

That is because "$var.property" will not resolve to the value stored in that property, but just replace $var with a string representation, and than add ".property" as text.
0
 
LVL 2

Author Closing Comment

by:Mandy_
ID: 39208893
Thank you so much for your help
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article outlines the process to identify and resolve account lockout in an Active Directory environment.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
how to add IIS SMTP to handle application/Scanner relays into office 365.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question