ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    PowerShell - Using Variables to Delete SMTP Proxy Addresses in AD

    Scheduled Pinned Locked Moved IT Discussion
    powershelladactive directorywindowsget-aduser
    11 Posts 3 Posters 3.4k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      flaxking
      last edited by flaxking

      Probably either

      "smtp:$($GivenName).$($Surname)@$($Domain)"
      

      Or

      ('smtp:' + $GivenName + '.' + $Surname + '@' + $Domain)
      
      wrx7mW 1 Reply Last reply Reply Quote 1
      • F
        flaxking
        last edited by

        Did you test your string creation on its own?

        wrx7mW 1 Reply Last reply Reply Quote 0
        • wrx7mW
          wrx7m @flaxking
          last edited by

          @flaxking said in PowerShell - Using Variables to Delete SMTP Proxy Addresses in AD:

          Probably either

          "smtp:$($GivenName).$($Surname)@$($Domain)"
          

          Or

          ('smtp:' + $GivenName + '.' + $Surname '@' + $Domain)
          

          The first option yields the same results. The second, errors out.

          F 1 Reply Last reply Reply Quote 0
          • wrx7mW
            wrx7m @flaxking
            last edited by

            @flaxking said in PowerShell - Using Variables to Delete SMTP Proxy Addresses in AD:

            Did you test your string creation on its own?

            I have not and am not exactly sure how to.

            1 Reply Last reply Reply Quote 0
            • F
              flaxking @wrx7m
              last edited by

              @wrx7m said in PowerShell - Using Variables to Delete SMTP Proxy Addresses in AD:

              @flaxking said in PowerShell - Using Variables to Delete SMTP Proxy Addresses in AD:

              Probably either

              "smtp:$($GivenName).$($Surname)@$($Domain)"
              

              Or

              ('smtp:' + $GivenName + '.' + $Surname '@' + $Domain)
              

              The first option yields the same results. The second, errors out.

              Yeah, the second one was missing a +

              1 Reply Last reply Reply Quote 0
              • F
                flaxking
                last edited by

                You're also trying to put an object into a string, which will only work if that object it set to print out the value you're looking for by default

                1 Reply Last reply Reply Quote 0
                • F
                  flaxking
                  last edited by flaxking

                  So in order to access the GivenName property on the object you have you would do $GivenName.GivenName

                  you could just do:

                  $User = Get-ADUser -Identity $SamAccountName
                  $User.GivenName
                  $User.Surname
                  

                  in which case your smtp string would be "smtp:$($User.GivenName).$($User.Surname)@$Domain"

                  1 Reply Last reply Reply Quote 2
                  • F
                    flaxking
                    last edited by

                    Powershell is object oriented, which is super important to realize when working with it, and that is what usually gives people the problem with it, if they do not have previous experience with objects. It makes a big learning curve increase.

                    On you 'Write-Host' test on your Set-ADUser command, you see "System.Collections.DictionaryEntry" because that is telling you what object is there. You're creating dictionary objects, so it's not going to automatically write out the contents of the dictionary.

                    wrx7mW 1 Reply Last reply Reply Quote 1
                    • ObsolesceO
                      Obsolesce
                      last edited by

                      So what you're looking at now is something like this:

                      Import-Module ActiveDirectory
                      $SamAccountName = Read-Host -Prompt "SamAccountName"
                      $Domain = Read-Host -Prompt "Type the domain of the address you wish to DELETE"
                      $user = Get-ADUser -Identity $SamAccountName
                      Set-ADUser $user -Remove @{proxyAddresses="smtp:$($user.GivenName).$($user.Surname)@$Domain"}
                      
                      1 Reply Last reply Reply Quote 2
                      • wrx7mW
                        wrx7m @flaxking
                        last edited by

                        @flaxking said in PowerShell - Using Variables to Delete SMTP Proxy Addresses in AD:

                        if they do not have previous experience with objects

                        Describes me. lol

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post