We help IT Professionals succeed at work.

Disable-Mailbox according to csv

Killerbe
Killerbe asked
on
I got 6 mailbox servers, 2 Exchange 2010 MBX servers and 4 2003 Back-ends. I 've got a list of 250 Users, and if they have a mailbox on one particular server, that mailbox on that server needs to be disbaled.

I really cant find a way to do that. What i got so far:
$Import = Import-csv c:\Scripts\Userlist.csv
ForEach ($Line in $Import) {get-mailbox | If ($_.ServerName -eq "[i]ServerName[/i]") | Disable-Mailbox

Open in new window

It cant be that hard, but cant figure it out.  

Comment
Watch Question



Param([string] $CSV)
Import-CSV $CSV | ForEach-Object -Process {disable-Mailbox $_.Name}

Save this the a file called disable.ps1

From powershell run  .\disable.ps1 “c:\scripts\userlist.csv”

Author

Commented:
That will disable the mailbox for all the users in that CSV. This is not required. Only if their mailbox resides on one particular server (Migration server), than the mailbox needs to be disabled.

Author

Commented:
Got a bit Further:
[Code]
$Import = Import-Csv C:\Scripts\test.cvs
ForEach ($Line in $Import)
{
$Entry = $Line.name
Get-Mailbox -id $Entry
}
But now i need to build in the seperator for the server
[/Code]

Author

Commented:
Update:
$Import = Import-Csv C:\Scripts\test.cvs
ForEach ($Line in $Import)
{
$Entry = $Line.name
Get-Mailbox -id $Entry |
If ($_.Servername -eq "exch02")
{Write-host "yeay"}
}
But then i get the error that the if command is not a valid powershell cmdlet....
Solutions Architect
Commented:
try

$Import = Import-Csv C:\Scripts\test.cvs

ForEach ($Line in $Import)
{
   $Entry = $Line.name
   $user = Get-Mailbox -id $Entry
  If ($user.Servername -eq "exch02")
    {Write-host "yeay"}
}

Author

Commented:
Thx Akhater,

Works like a charm!