+ Post New Thread
Results 1 to 3 of 3
Scripts Thread, Powershell help needed please! in Coding and Web Development; Ive got the following powershell script: Code: # Copyright (c) Microsoft Corporation. All rights reserved. # # THIS CODE IS ...
  1. #1

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,476
    Thank Post
    1,305
    Thanked 469 Times in 306 Posts
    Blog Entries
    6
    Rep Power
    198

    Powershell help needed please!

    Ive got the following powershell script:

    Code:
    # 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:

    Code:
    Set-Mailbox -Identity John -DeliverToMailboxAndForward $true -ForwardingAddress john@mydomain.edu.au
    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!

  2. #2

    Join Date
    Mar 2008
    Location
    Surrey
    Posts
    2,161
    Thank Post
    95
    Thanked 318 Times in 260 Posts
    Blog Entries
    4
    Rep Power
    111
    [code]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.

  3. #3

    RabbieBurns's Avatar
    Join Date
    Apr 2008
    Location
    Sydney
    Posts
    5,476
    Thank Post
    1,305
    Thanked 469 Times in 306 Posts
    Blog Entries
    6
    Rep Power
    198
    Quote Originally Posted by jamesb View Post
    [code]Set-Mailbox -Identity $user.Name -DeliverToMailboxAndForward $true -ForwardingAddress $user.EmailName
    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.[/QUOTE]

    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 ?

SHARE:
+ Post New Thread

Similar Threads

  1. Powershell Help
    By mbedford in forum Coding
    Replies: 0
    Last Post: 1st August 2009, 03:25 PM
  2. Powershell Exchange 2007 help
    By maf_001 in forum Coding
    Replies: 2
    Last Post: 14th June 2009, 08:57 PM
  3. WSUS & Powershell
    By FN-GM in forum Windows
    Replies: 1
    Last Post: 25th March 2009, 10:44 AM
  4. Powershell
    By Ric_ in forum Windows
    Replies: 3
    Last Post: 25th November 2008, 11:54 PM
  5. Microsoft Windows PowerShell v1.0
    By tarquel in forum Downloads
    Replies: 20
    Last Post: 26th March 2007, 07:32 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •