Options
Any Powershell Gurus out here ?
![jibbajabba](https://us.v-cdn.net/6030959/uploads/userpics/navatar208680_6.gif)
in Off-Topic
I am a bloody noob so hopefull someone can help me out here ![:) :)](https://community.infosecinstitute.com/resources/emoji/smile.png)
I found the following code
Which basically looks like that
Now I am using the following bits to add an alias to a mailbox
Can someone tell me how I could incoorporate the first script into the second so I get the same input, but instead of "what food do you like" I get for example "Please input email" and it executes those three lines based on my input (changing backups.aaa@domain.com based on my input basically) ?
Does that makes sense at all ?
![:) :)](https://community.infosecinstitute.com/resources/emoji/smile.png)
I found the following code
$op_file = Read-Host "What food do you like?" Write-Host "$op_file is awesome [IMG]https://us.v-cdn.net/6030959/uploads/images/smilies/icon_wink.gif[/IMG]"
Which basically looks like that
[PS] C:\>.\blurp.ps1
What food do you like?: Kebab
Kebab is awesome
Now I am using the following bits to add an alias to a mailbox
$Temp = Get-Mailbox -Identity Administrator $Temp.EmailAddresses += ("smtp:backups.aaa@domain.com") Set-Mailbox -Identity Administrator -EmailAddresses $Temp.EmailAddresses
Can someone tell me how I could incoorporate the first script into the second so I get the same input, but instead of "what food do you like" I get for example "Please input email" and it executes those three lines based on my input (changing backups.aaa@domain.com based on my input basically) ?
Does that makes sense at all ?
My own knowledge base made public: http://open902.com ![:p :p](https://community.infosecinstitute.com/resources/emoji/tongue.png)
![:p :p](https://community.infosecinstitute.com/resources/emoji/tongue.png)
Comments
-
Options
Pash Member Posts: 1,600 ■■■■■□□□□□
Sorry dont have exchange cmdlets at home.
But couldnt you just put something like:-
$Temp.EmailAddresses += ("smtp:$op_file")DevOps Engineer and Security Champion. https://blog.pash.by - I am trying to find my writing style, so please bear with me. -
Options
jibbajabba Member Posts: 4,317 ■■■■■■■■□□
Sorry dont have exchange cmdlets at home.
But couldnt you just put something like:-
$Temp.EmailAddresses += ("smtp:$op_file")
Tried that first thing but I got all sorts of errors. I now found out that this was due to the limit of maximum aliases already in use which was fixed with SP1 - I THOUGHT that server has SP1 already but didn't.
So yea - that works .. just not for the rest of the script. Another part (which isn't posted here) I also create a folder underneath the Inbox and also create a server side rule which checks the header for the alias.
I need to find a way to exclude the @domain part for the folder and rule otherwise (for some reason) it won't work .. might have to work with two variables or something .. not sure.My own knowledge base made public: http://open902.com -
Options
Pash Member Posts: 1,600 ■■■■■□□□□□
Tried that first thing but I got all sorts of errors. I now found out that this was due to the limit of maximum aliases already in use which was fixed with SP1 - I THOUGHT that server has SP1 already but didn't.
So yea - that works .. just not for the rest of the script. Another part (which isn't posted here) I also create a folder underneath the Inbox and also create a server side rule which checks the header for the alias.
I need to find a way to exclude the @domain part for the folder and rule otherwise (for some reason) it won't work .. might have to work with two variables or something .. not sure.
Or you could use the string split method to split anything off after @.
Having the whole script would let us help you more efficiently.
I am glad the first part is working....DevOps Engineer and Security Champion. https://blog.pash.by - I am trying to find my writing style, so please bear with me. -
Options
jibbajabba Member Posts: 4,317 ■■■■■■■■□□
I am trying to
1. Create an Alias underneath i.e. Administrator@domain.com
2. Create a subfolder based on the alias (without @domain.com)
3. Create a server side rule to look for the alias in the header (without domain, only alias@) and moves it into the folder created in step #2$Temp = Get-Mailbox -Identity Administrator $Temp.EmailAddresses += ("smtp:alias1@rudloff.me") Set-Mailbox -Identity Administrator -EmailAddresses $Temp.EmailAddresses new-MailboxFolder -Parent Administrator:\Inbox -Name alias1 new-InboxRule -Name "Alias1 Rule" -HeaderContainsWords "alias@" -MoveToFolder Administrator@rudloff.me:\Inbox\alias
Hope that makes sense ...My own knowledge base made public: http://open902.com -
Options
Pash Member Posts: 1,600 ■■■■■□□□□□
I completely understand what you are trying to do.
I wish I could help you further but I dont have any exchange management software installed anywhere currently where I can test this for you ( at least not until next week!)
You said the $variable within smtp: was working?
Like I said, you could use string split method to split up a variable like:-
$emailalias = Read-host "What is your email address?"
What is your email address?: howdy@cowboy.com
$alias = $emailalias.Split("@)[0] + @"
$domain = $emailalias.Split("@)[1]
$alias
howdy@
$domain
cowboy.comDevOps Engineer and Security Champion. https://blog.pash.by - I am trying to find my writing style, so please bear with me. -
Options
jibbajabba Member Posts: 4,317 ■■■■■■■■□□
Well, that works perfectly as well :$useradd = Read-Host "What is the mailbox you'd like to add:" $domainadd Read-Host "What is the domain of the mailbox: " $Temp = Get-Mailbox -Identity Administrator $Temp.EmailAddresses += ("smtp:$useradd@$domainadd") Set-Mailbox -Identity Administrator -EmailAddresses $Temp.EmailAddresses new-MailboxFolder -Parent Administrator:\Inbox -Name $useradd new-InboxRule -Name "$useradd Rule" -HeaderContainsWords "$useradd@" -MoveToFolder Administrator@domain.com:\Inbox\$useradd
My own knowledge base made public: http://open902.com -
Options
Pash Member Posts: 1,600 ■■■■■□□□□□
Well, that works perfectly as well :$useradd = Read-Host "What is the mailbox you'd like to add:" $domainadd Read-Host "What is the domain of the mailbox: " $Temp = Get-Mailbox -Identity Administrator $Temp.EmailAddresses += ("smtp:$useradd@$domainadd") Set-Mailbox -Identity Administrator -EmailAddresses $Temp.EmailAddresses new-MailboxFolder -Parent Administrator:\Inbox -Name $useradd new-InboxRule -Name "$useradd Rule" -HeaderContainsWords "$useradd@" -MoveToFolder Administrator@domain.com:\Inbox\$useradd
So it's working now??? I don't really get why you'd want user input twice, but I guess if you must. The point of scripts is to ease your workload and also develop your understanding, the split method is very useful with more complex strings as well.DevOps Engineer and Security Champion. https://blog.pash.by - I am trying to find my writing style, so please bear with me. -
Options
jibbajabba Member Posts: 4,317 ■■■■■■■■□□
So it's working now??? I don't really get why you'd want user input twice, but I guess if you must. The point of scripts is to ease your workload and also develop your understanding, the split method is very useful with more complex strings as well.
Prove of concept really ... I haven't seen your reply about the split method - I will try this now too
In our production Exchange we don't even need the input twice as we always add an alias to the same mailbox so most of script can be "hard coded".
Cheers for your help .. I will test it once I got my stupid VPN working againMy own knowledge base made public: http://open902.com -
Options
jibbajabba Member Posts: 4,317 ■■■■■■■■□□
Meh .. stuck again .. all the scripts working fine ... for the Adminsitrator mailbox only though.
Here you can see a list of mailboxes on that test server[PS] C:\Windows\system32>get-mailbox -server mail Name Alias ServerName ProhibitSendQuota ---- ----- ---------- ----------------- Administrator Administrator mail unlimited DiscoverySearchMailbox... DiscoverySearchMa... mail 50 GB (53,687,091,200 bytes) Michael Rudloff Michael mail unlimited
Here I create a folder for the Administrator[PS] C:\Windows\system32>new-mailboxfolder -Name SomeFolder -Parent Administrator:\Inbox Name FolderPath HasSubfolders ---- ---------- ------------- SomeFolder {Inbox, SomeFolder} False
Now for the user "Michael"[PS] C:\Windows\system32>new-mailboxfolder -Name SomeFolder -Parent Michael:\Inbox [color=red]The specified mailbox "Michael" doesn't exist. + CategoryInfo : NotSpecified: (0:Int32) [New-MailboxFolder], ManagementObjectNotFoundException + FullyQualifiedErrorId : 66AC40E4,Microsoft.Exchange.Management.StoreTasks.NewMailboxFolder[/color]
Tried the full email as well and all sorts of combinations ..My own knowledge base made public: http://open902.com -
Options
Claymoore Member Posts: 1,637
As entertaining as PowerShell can be, this is what email address policies are for. You can modify the default email address policy, but I prefer to create new ones and give them a higher priority. You can even filter the application of policies using LDAP queries down to specific groups or OUs.
How to Create an E-Mail Address Policy: Exchange 2007 Help
Managing E-Mail Address Policies in Exchange Server 2007 -
Options
jibbajabba Member Posts: 4,317 ■■■■■■■■□□
As entertaining as PowerShell can be, this is what email address policies are for. You can modify the default email address policy, but I prefer to create new ones and give them a higher priority. You can even filter the application of policies using LDAP queries down to specific groups or OUs.
How to Create an E-Mail Address Policy: Exchange 2007 Help
Managing E-Mail Address Policies in Exchange Server 2007
Sorry, I am confused. Email policies ? How do they help in creating folder underneath the inbox of a specific user ?!?My own knowledge base made public: http://open902.com -
Options
Claymoore Member Posts: 1,637
Gotcha, I thought you were only trying to create an email alias. For the folders, you can use custom managed folders and deploy them through a managed folder policy
How to Create a Managed Folder: Exchange 2007 Help
How to Create a Managed Folder Mailbox Policy: Exchange 2007 Help
As for a rule to move messages to that custom folder, I think you will have to create the rule in Oulook for each client. I don't believe transport rules can deliver items to specific folders. -
Options
jibbajabba Member Posts: 4,317 ■■■■■■■■□□
Gotcha, I thought you were only trying to create an email alias. For the folders, you can use custom managed folders and deploy them through a managed folder policy
How to Create a Managed Folder: Exchange 2007 Help
How to Create a Managed Folder Mailbox Policy: Exchange 2007 Help
As for a rule to move messages to that custom folder, I think you will have to create the rule in Oulook for each client. I don't believe transport rules can deliver items to specific folders.
They do .. You can certainly create server side rules through outlook, but you can also do so via powershell which is what I am trying to achieve.
Like I said earlier - it works perfectly for the admin user. I can create a subfolder underneath the inbox, create a server side rule to check the header for a certain string and move that into the folder in question - works a dream .. I just can't do that for other user ..
You can check the documentation for "new-mailboxfolder" and "new-inboxrule" and you will see that this is possible .. well in theory anyway ..My own knowledge base made public: http://open902.com -
Options
jibbajabba Member Posts: 4,317 ■■■■■■■■□□
Here an example and to show it is possible
Creating the folder
Check OWA to confirm
Create the serverside rule
Check OWA to confirm
So I got it working - but I have to run powershell as the user I want to perform changes to
Edit:If your logon account is the Administrator account, a member of the root Domain Administrators, a member of the Enterprise Administrators groups, or a member of the Exchange Organization Administrators role, you are explicitly denied access to all mailboxes that are not your mailbox, even if you have full administrative rights over the Exchange system. All Exchange 2007 administrative tasks can be performed without having to grant an administrator sufficient rights to read other people's mail.
http://technet.microsoft.com/en-us/library/bb310792(EXCHG.80).aspx
makes sense I guess ..My own knowledge base made public: http://open902.com -
Options
Pash Member Posts: 1,600 ■■■■■□□□□□
Nice mate. It's good to see its working and that there are limitations (with a solid link to back it up).
PashDevOps Engineer and Security Champion. https://blog.pash.by - I am trying to find my writing style, so please bear with me. -
Options
thehourman Member Posts: 723
Off-topic question.
I don't know any scripting language, but I am kind of interested learning powershell.
What would be the benefits of learning powershell?
When and where to use powershell?
I noticed that there is a bunch of PS in 70-640.Studying:
Working on CCNA: Security. Start date: 12.28.10
Microsoft 70-640 - on hold (This is not taking me anywhere. I started this in October, and it is December now, I am still on page 221. WTH!)
Reading:
Network Warrior - Currently at Part II
Reading IPv6 Essentials 2nd Edition - on hold -
Options
RobertKaucher Member Posts: 4,299 ■■■■■■■■■■
PowerShell is a component of the Windows Management Framework. It is built into every Windows OS as of Windows 7/Server 2008 and is integrated into every one of MS's major server applications (Exchange, SQL Server, SharePoint, etc). It is impossible to be a competent, modern Windows admin without knowing the basics of PowerShell.