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

    Solved Trying to Improve my Powershell Skills - Need some guidance

    IT Discussion
    powershell windows scripting
    2
    9
    1.1k
    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.
    • DustinB3403D
      DustinB3403
      last edited by scottalanmiller

      Import-Module ActiveDirectory 
      $userInput = $null 
      Do 
      { 
      	$prompt = Read-Host -Prompt "New employee" 
      	$proxy = Read-host -Prompt "full proxy address as SMTP:[email protected]"
      	$user = Get-ADUser $prompt -Properties mail, ProxyAddresses
      	$userInput = "$($user.samaccountname)" 
      } While($user -eq $null)
      
      Set-ADUser $user -Add @{ProxyAddresses="$proxy"}
      

      What I'd like to remove is the need to fill in the full proxy address.

      I had tried Set-ADUser $user -Add @{ProxyAddresses=("SMTP:"+"$user"+"@domain.com")}

      That didn't work at least not how I'd expected... What I have now, adds the proxy address, but it leaves room for a lot of error. Any pointers on how I can concatenate that last entry?

      1 Reply Last reply Reply Quote 3
      • DustinB3403D
        DustinB3403
        last edited by DustinB3403

        I think I got it.

        $fullproxy = ("SMTP:"+$userInput+"@domain.com")

        and then the set-aduser . . . .

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

          I wouldn't try to automatically use a capitalized "SMTP" as in the example you "had tried" at the end of your post. If you did then every entry you add in to a proxyAddress attribute would have a capitalized SMTP. Only the main login should have capital SMPT, the rest of them (aliases) should be lower case).

          As for improving PowerShell skills, I bought this when it was released: https://www.amazon.com/Windows-PowerShell-Step-3rd/dp/0735675112
          and I highly recommend it. I haven't gotten though much of it yet because I'm trying to finish up some MCSE's first, but I will be diving a lot more into it soon.

          DustinB3403D 1 Reply Last reply Reply Quote 0
          • DustinB3403D
            DustinB3403
            last edited by

            Maybe if I create a variable as

            $fullproxy = ("SMTP:"+"$user"+"@domain.com")

            And use the $fullproxy variable...

            ObsolesceO 1 Reply Last reply Reply Quote 0
            • DustinB3403D
              DustinB3403 @Obsolesce
              last edited by

              @Tim_G We recently had to break our hybrid environment, so we have to create the proxy records. So this would be the only record we "care" about so we can create user accounts.

              I'm trying to avoid have to open ADUC, finding the user and then adding the record by hand.

              Thanks for the tip though.

              1 Reply Last reply Reply Quote 0
              • DustinB3403D
                DustinB3403
                last edited by DustinB3403

                I think I got it.

                $fullproxy = ("SMTP:"+$userInput+"@domain.com")

                and then the set-aduser . . . .

                1 Reply Last reply Reply Quote 0
                • ObsolesceO
                  Obsolesce @DustinB3403
                  last edited by Obsolesce

                  @DustinB3403

                  I usually make big lists in Excel and use that in PowerShell. You could output all users "sAMAccountName" to CSV... then on the first line in the next column type the @domain.com and drag it down to the end.

                  Then in the columns before and after it, do the same thing... type in the powershell commands you need, drag it down tot he bottom to copy it to each line, copy it into notepad++, replace all tabs with spaces, and call it a .PS1.

                  Sounds like a lot, but it really only takes literally 2 minutes to make a list of hundreds or thousands and turn it into a .ps1.

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

                    Also, if you have a specific group of people, you can use a "get-" command instead of .csv list. I meant that lists like I said about above are best if it's not an easy grab using a get command.

                    I'm probably not explaining myself right, you know what I mean?

                    1 Reply Last reply Reply Quote 0
                    • DustinB3403D
                      DustinB3403
                      last edited by DustinB3403

                      @Tim_G I considered using a csv to import the records, but this is only for the users we have to add going forward from today. (until we reconnect the hybrid)

                      It was actually the first kind of post I had found (import using CSV) but since we have so few uses we add (maybe a handful a month) doing so is overkill.

                      ObsolesceO 1 Reply Last reply Reply Quote 0
                      • ObsolesceO
                        Obsolesce @DustinB3403
                        last edited by

                        @DustinB3403 Ahh I see, then yes a prompt for input script is best then.

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