Can anyone help me write a powershell script to set call immediate call forwarding on users from a .csv file?

Dave 20 Reputation points
2023-04-20T09:02:53.2266667+00:00

Hello, I'm looking to write a script to do the following:

  • Set an "immediately forward" on a user to another number. So for example:
  • Set-CsUserCallingSettings -Identity ******@domain.com -IsForwardingEnabled $true -ForwardingType Immediate -ForwardingTarget +3.......-ForwardingTargetType SingleTarget ^ Of course this works like this. But I want to do this in bulk from a .csv file. So it would look something like User Forwardnumber
    UPN +3...... (With a script that uses the import function) I can't seem to get this part to work. Could you help me out? Thank you!
Windows for business | Windows Server | User experience | PowerShell
Microsoft Teams | Microsoft Teams for business | Other
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 47,901 Reputation points
    2023-04-20T18:26:05.4666667+00:00

    Try this:

    Import-CSV <csv-path> |
        ForEach-Object{
            $u = $_.user    # for use in Catch block if update fails
            Try{
                Set-CsUserCallingSettings -Identity $_.user -IsForwardingEnabled $true -ForwardingType Immediate -ForwardingTarget $_.ForwardingTarget -ForwardingTargetType SingleTarget ^ -ErrorAction STOP
            }
            Catch{
                Write-Host "Could not make changes to '$_.u'"
                $_
            }
        }
    
    

    The CSV file should look something like this:

    User,ForwardingTarget
    ******@domain.com,+3.......
    Another******@domain.com,+3.......
    
    

    EDIT: corrected the "Write-Host" to use the variable "$u".

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.