RabbieBurns Posted May 13, 2010 Posted May 13, 2010 Ive got the following powershell script: # Copyright (c) Microsoft Corporation. All rights reserved. # # THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK # OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER. # # Synopsis: This script is designed to import WindowsLiveID to existing domain on a CSV file containing data. # # # Usage example: # # Populate credentials to variable: # $Livecred = Get-Credential # # .\listFromCSV.ps1 -UsersFile user_accounts.csv -RemoteURL https://ps.outlook.com/powershell/ -LiveCredential $LiveCred # Param( [string] $UsersFile = $(throw "Missing parameter: The -UsersFile parameter is required."), [string] $RemoteURL = $(throw "Missing parameter: The -$RemoteURL parameter is required."), [system.Management.automation.PSCredential] $LiveCredential = $(throw "Missing parameter: The -LiveCredential parameter is required.") ) ############################################################ Variable Declarations ################################################################ # Suppress warnings during script execution $WarningPreference="SilentlyContinue" ############################################################ Variable Declarations End ############################################################ ############################################################ Function Declarations ################################################################ # function clearRS { # Tries to close Runspace - clearing all since I can't create RS using -Name $error.Clear() Remove-PSSession $Session } ############################################################ Function Declarations End ############################################################ ############################################################ Main Script Block #################################################################### # Tries to create Runspace $error.Clear() $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $RemoteURL -Authentication Basic -Credential $LiveCredential -AllowRedirection Import-PSSession $Session # read recipients to be created $error.Clear() $UserFile = import-csv -Path $UsersFile -OutVariable string -ErrorAction $WarningPreference # Filters records and calls appropriate cmdlets foreach ($user in $UserFile) { $this_liveID = $user.EmailName # Retrieving mailbox echo "Retrieving $this_liveID" get-mailbox -Identity $this_liveID |fl } # finish script - clear Runspaces $error.Clear() clearRS $WarningPreference="Continue" ############################################################ Main Script End #################################################################### I want to modify it, so that when it iterates through the csv, what it does is runs a different command.. I want it to run: Set-Mailbox -Identity John -DeliverToMailboxAndForward $true -ForwardingAddress [email protected] But replacing John' with the username in the csv.. But im not too sure where to put it in.. Anyone clued up on powershell can see how Id put it in? Cheers!
jamesb Posted May 13, 2010 Posted May 13, 2010 Set-Mailbox -Identity $user.Name -DeliverToMailboxAndForward $true -ForwardingAddress $user.EmailName [/quote] Should do it if I've got the naming right. You may want to test the properties by putting: [code]foreach ($user in $UserFile) { $user } Get-Member $user That should list out all of the users with all of their properties, and give you a list of all the properties available at the end.
RabbieBurns Posted May 13, 2010 Author Posted May 13, 2010 Set-Mailbox -Identity $user.Name -DeliverToMailboxAndForward $true -ForwardingAddress $user.EmailName [/quote] Should do it if I've got the naming right. You may want to test the properties by putting: [code]foreach ($user in $UserFile) { $user } Get-Member $user That should list out all of the users with all of their properties, and give you a list of all the properties available at the end. Cheers, Ill try the test first.. The address im trying to put as the -ForwardingAddress is different form any existing email address it will know about.. How can I append the $user. to a hardcoded seperate domain ?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now