Solved

powershell reading an array from a file into a command

Posted on 2013-12-06
6
320 Views
Last Modified: 2013-12-11
I have users who need certain aliases removed. Like the example Microsoft uses http://technet.microsoft.com/en-us/library/bb123794(v=exchg.150).aspx on their technet site removing aliases from a user but except I would like to remove them from a file. I am just beginning to learn about arrays and they are very handy with something like this


Set-Mailbox "Janet Schorr" -EmailAddresses @{remove="janet.schorr@corp.contoso.com","janets@tailspintoys.com"}

So I wondered and I know I am missing info but would like to try something like this

$emaillist=get-content c:\emailalias.csv

foreach($i in $emaillist) {

set-mailbox "janet schorr" -emailaddresses @{remove=and this is where I am list}

}
0
Comment
Question by:techdrive
  • 3
  • 2
6 Comments
 
LVL 13

Expert Comment

by:Felix Leven
ID: 39700876
I use somthing like this to work with data from an CVS file

Get-Content C:\test.csv | ConvertFrom-Csv -Delimiter ";" | Out-GridView

maybe you are missing just the delimiter or need to convert the data.
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 39700944
MrGraves, instead of that, just use
Import-CSV -Delimiter ';' C:\test.csv | Out-GridView

Open in new window

No need to do more.

techdrive, I'm not clear about what exactly is in the CSV file. Is it just a comma-separatated list of aliasses you want to remove from a single account (which doesn't make much sense that way), or more of:
Account; Alias
"Janet schorr", "janet.schorr@corp.contoso.com,janets@tailspintoys.com"

Open in new window

0
 

Author Comment

by:techdrive
ID: 39700960
I am sorry the list of aliases are like this


alias1@contoso.local
alias2@contoso.local
alias3@contoso.local
alias4@contoso.local
so on and so on.
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 68

Expert Comment

by:Qlemo
ID: 39701080
And all for a single account?
0
 

Author Comment

by:techdrive
ID: 39701331
no multiple accounts
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
ID: 39701604
If you insist (it is easier than you might think):
Set-Mailbox "Janet Schorr" -EmailAddresses @{remove=get-content c:\emailalias.csv}

Open in new window

0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Synchronize a new Active Directory domain with an existing Office 365 tenant
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

930 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now