Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

powershell reading an array from a file into a command

Posted on 2013-12-06
6
Medium Priority
?
339 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 71

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
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 71

Expert Comment

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

Author Comment

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

Accepted Solution

by:
Qlemo earned 2000 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

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

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

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline

972 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