Powershell, how to use an array(based on csv) to set attributes on specific maildatabases

Hi,

I am struggling with an Powershell script.

What i am trying to achieve is to set the customattribute1 to the same as the database name as exported.

What I have is :

get-mailboxdatabase -server "mailserver" | Select-Object name | Sort-Object name | Export-Csv c:\scripts\database.csv
Wait-Event -Timeout 15
$database=Import-Csv c:\scripts\database.csv
get-mailbox -database ($database) -filter {customattribute1 -eq $null} | set-mailbox -customattribute1 ($database)

What i want is that the list (with 16 entries) is read line by line and setting the appropriate custom attribute.

any suggestions ?
LVL 1
Mr WooberAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy LidbetterCommented:
Try This

$Databases = get-mailboxdatabase -server "mailserver" | Select name | Sort name

ForEach ($Database in $Databases) {Get-mailbox -database $database.name -filter {customattribute1 -eq $null} | set-mailbox -customattribute1 $database.name}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mr WooberAuthor Commented:
Worked like a charm.
Guy LidbetterCommented:
Good stuff!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.