I hope this makes sense...
I am working on a script to allow some of our OU managers to update CustomAttribute2 for their users based on some pre-defined settings. We use this value to set an Email Address Policy for that user.
I can use Get-EmailAddressPolicy with a filter to get the address policies they should be using but some of them have multiple policies to choose from. I am trying unroll the EnabledEmailAddressTemplates note property so I can use it in a description for a choice menu I am creating.
My current process manually builds the menu so i add the definitions but as we add more of these groups it is becoming cumbersome to maintain.
Basically I am trying to create a PSObject that I can use that has the Name, ConditionalCustomAttribute2 , EnabledPrimarySMTPAddressTemplate, and a nicely formated user readable EnabledEmailAddressTemplates.
Get the policy options:
$EAP = Get-EmailAddressPolicy | Select Name,ConditionalCustomAttribute2,EnabledPrimarySMTPAddressTemplate,EnabledEmailAddressTemplates | Where {$_.Name -Like "$Deptinit"}
Sample Menu Build:
CMI-ExchAdmins {
$Title = "Address Policy"
$Message = "Please choose which address policy you would like to apply."
$CMIFILN = New-Object System.Management.Automation.Host.ChoiceDescription "&FILN", "Uses first initial and last name in the address. <filn>@SomeAddress1, <netid>@SomeAddress2, <netid>@SomeAddress3"
$CMIFILN2 = New-Object System.Management.Automation.Host.ChoiceDescription "&FILN2", "Uses first initial and last name in the address. <filn>@SomeAddress1, <filn>@SomeAddress4, <filn>@SomeAddress5, <netid>@SomeAddress2, <netid>@SomeAddress3"
$CMIFILN3 = New-Object System.Management.Automation.Host.ChoiceDescription "&FILN3", "Uses first initial and last name in the address. <filn>@SomeAddress1, <filn>@SomeAddress4, <filn>@SomeAddress5, <ln>@SomeAddress6, <fn>@SomeAddress6,<fn.ln>@SomeAddress6,<netid>@SomeAddress2, <netid>@SomeAddress3"
$CMIFILN4 = New-Object System.Management.Automation.Host.ChoiceDescription "&FILN4", "Uses first initial and last name in the address. <filn>@SomeAddress1, <filn>@SomeAddress4, <filn>@SomeAddress5, <ln>@SomeAddress6, <netid>@SomeAddress6,<netid>@SomeAddress5,<netid>@SomeAddress2, <netid>@SomeAddress3"
$CMIFIMILN = New-Object System.Management.Automation.Host.ChoiceDescription "&FIMILN", "Uses first initial, middle initial, and last name in the address. <fimiln>@SomeAddress6, <fimiln>@SomeAddress5, <filn>@SomeAddress6, <filn>@SomeAddress5, <ln>@SomeAddress6,<ln>@SomeAddress5,<netid>@SomeAddress2, <netid>@SomeAddress3"
$Options = [System.Management.Automation.Host.ChoiceDescription[]]($CMIFILN, $CMIFILN2, $CMIFILN3, $CMIFILN4, $CMIFIMILN)
$Result = $host.ui.PromptForChoice($title, $message, $options, 0)
switch ($Result){
0 {"You selected FILN"
$CA2 = "CMI-FILN"
}
1 {"You selected FILN2"
$CA2 = "CMI-FILN2"
}
2 {"You selected FILN3"
$CA2 = "CMI-FILN3"
}
3 {"You selected FILN4"
$CA2 = "CMI-FILN"
}
4 {"You selected FIMILN"
$CA2 = "CMI-FIMILN"
}
5 {"You selected CMI-Student"
$CA2 = "CMI-Student"
}
}
}