locked
how do i create a script to add multiple proxy RRS feed

  • Question

  • Currently i have an csv with these 2 fields userprincipalname and email address

    Import-Csv list.csv | foreach-object {
    SamAccountName = $_.userprincipalname
    get-aduser -identity "SamaccountName" | set-aduser -add @{'ProxyAddresses'=@("SMTP:_.emailaddress","SIP:_.emailaddress")}
    }

    Thursday, January 19, 2017 2:17 AM

Answers

  • Import-Csv list.csv | foreach-object {
    get-aduser -identity $_.userprincipalname | set-aduser -add @{ProxyAddresses = @("SMTP:$($_.emailaddress)", "SIP:$($_.emailaddress)") }
    }

    fixed it Thanks


    • Marked as answer by Pokemo Friday, January 20, 2017 2:16 PM
    • Edited by Pokemo Friday, January 20, 2017 2:16 PM
    Friday, January 20, 2017 2:15 PM

All replies

  • You have two typos in your code.


    \_(ツ)_/

    Thursday, January 19, 2017 9:37 AM
  • ... found it ...   ;-)

    $


    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Thursday, January 19, 2017 12:37 PM
  • Modified script:

    Import-Csv list.csv | foreach-object {
    $SamAccountName = $_.userprincipalname
    get-aduser -identity $SamaccountName | set-aduser -add @{'ProxyAddresses'=@("SMTP:$_.emailaddress","SIP:$_.emailaddress")}
    }

    Thursday, January 19, 2017 12:43 PM
  • this will import the whole column the code

    SIP:@{userprincipalname=Tuser2;EmailAddress=123@gmail.com};emailaddress

    Thursday, January 19, 2017 1:48 PM
  • Import-Csv list.csv | 
    	foreach-object {
    		get-aduser -identity $_.userprincipalname | 
    			set-aduser -add @{ProxyAddresses = @("SMTP:$($_.emailaddress)", "$(SIP:$_.emailaddress)") }
    	}
    


    \_(ツ)_/

    Thursday, January 19, 2017 1:53 PM
  • SIP:$_.emailaddress : The term 'SIP:$_.emailaddress' is not recognized as the 
    name of a cmdlet, function, script file, or operable program. Check the 
    spelling of the name, or if a path was included, verify that the path is 
    correct and try again.
    At C:\Temp\addproxy.ps1:2 char:112
    + ... laddress)", "$(SIP:$_.emailaddress)") }
    +                    ~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (SIP:$_.emailaddress:String) [], 
        CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
     
    set-aduser : add
    At C:\Temp\addproxy.ps1:2 char:45
    + get-aduser -identity $_.userprincipalname | set-aduser -add @{ProxyAddresses 
    = @ ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ~~~
        + CategoryInfo          : InvalidOperation: (CN=Tuser1,CN=Users,DC=mhadom 
       ain,DC=com:ADUser) [Set-ADUser], ADInvalidOperationException
        + FullyQualifiedErrorId : ActiveDirectoryServer:0,Microsoft.ActiveDirector 
       y.Management.Commands.SetADUser
     
    SIP:$_.emailaddress : The term 'SIP:$_.emailaddress' is not recognized as the 
    name of a cmdlet, function, script file, or operable program. Check the 
    spelling of the name, or if a path was included, verify that the path is 
    correct and try again.
    At C:\Temp\addproxy.ps1:2 char:112
    + ... laddress)", "$(SIP:$_.emailaddress)") }
    +                    ~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (SIP:$_.emailaddress:String) [], 
        CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
     
    set-aduser : add
    At C:\Temp\addproxy.ps1:2 char:45
    + get-aduser -identity $_.userprincipalname | set-aduser -add @{ProxyAddresses 
    = @ ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ~~~
        + CategoryInfo          : InvalidOperation: (CN=TUser2,CN=Users,DC=mhadoma 
       in,DC=com:ADUser) [Set-ADUser], ADInvalidOperationException
        + FullyQualifiedErrorId : ActiveDirectoryServer:0,Microsoft.ActiveDirector 
       y.Management.Commands.SetADUser
    • Edited by Pokemo Friday, January 20, 2017 2:15 PM
    Friday, January 20, 2017 2:13 PM
  • Import-Csv list.csv | foreach-object {
    get-aduser -identity $_.userprincipalname | set-aduser -add @{ProxyAddresses = @("SMTP:$($_.emailaddress)", "SIP:$($_.emailaddress)") }
    }

    fixed it Thanks


    • Marked as answer by Pokemo Friday, January 20, 2017 2:16 PM
    • Edited by Pokemo Friday, January 20, 2017 2:16 PM
    Friday, January 20, 2017 2:15 PM