# Script for to handle 2 variables

• ### Question

• Hi All,

Thanks in advance for the help.

I have a requirement where I need to parse 2 columns from a csv file. Below is the sample how it would look like:

Lwemail                                               Tmemail
test.sharedmailbox@ourdomain.com       abc@otherdomain.com
test.shared2@ourdomain.com                     xyz@otherdomain.com

Now, I need to collect each row at a time and parse them through a Exchange Shell command to create inbox rules.

I know the EMS command, but since I am still a learner in powershell I don't know how to handle the inputs from csv file.

Many Thanks,

Niru

Niranjan

Wednesday, January 31, 2018 8:59 AM

• We don't write scripts for you in this forum. I would suggest learning PowerShell as a simple Google could show you how to interact with a CSV file.

$CSVInput = Import-CSV -Path c:\path\to\csv foreach ($I in $CSVinput){$lewmail = $I.lewmail$tmemail = $I.tmemail #REST OF CODE HERE } Wednesday, January 31, 2018 9:19 AM ### All replies • Please post your script and any errors you are getting. Please carefully review the following to set your expectation of technical forums. Script requests \_(ツ)_/ Wednesday, January 31, 2018 9:13 AM • We don't write scripts on request. If you already have some code to show - show it and we will try to help. To start with your task you will probably need in the first place the cmdlets Import-CSV and Foreach-Object. Also find scripts here: PowerShell Gallery or here: TechNet Gallery - resources for IT professionals. Learn PowerShell: Microsoft Virtual Academy - Getting Started with Microsoft PowerShell. Script requests: Microsoft Technet Script Center - Requests. Best regards, (79,108,97,102|%{[char]$_})-join''

• Edited by Wednesday, January 31, 2018 9:17 AM
Wednesday, January 31, 2018 9:17 AM
• We don't write scripts for you in this forum. I would suggest learning PowerShell as a simple Google could show you how to interact with a CSV file.

$CSVInput = Import-CSV -Path c:\path\to\csv foreach ($I in $CSVinput){$lewmail = $I.lewmail$tmemail = $I.tmemail #REST OF CODE HERE } Wednesday, January 31, 2018 9:19 AM • "$input" is a reserved variable and con ot be used in a script.

\_(ツ)_/

Wednesday, January 31, 2018 9:41 AM
• Thanks everyone for the help, I got what I needed, here is the below script:

$lwtmeml = Import-CSV -Path C:\Users\username\Desktop\CSVs\lwtmemail.csv foreach ($I in $lwtmeml){$lewmail = $I.lwemail$tmemail = $I.tmemail New-InboxRule -Mailbox$lewmail -ForwardTo \$tmemail -Name "Redirect to my TM account" }

Many thanks to Delinquent.. I did not ask for the script, sometimes I don't know how to pose my questions to google and that's why I come here because I know guys here understand anything is being asked for..

Niranjan

Wednesday, January 31, 2018 11:19 AM