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

    Favorite PowerShell Commands?

    IT Discussion
    9
    12
    1.6k
    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.
    • ?
      A Former User
      last edited by A Former User

      I dont tinker with PS as much as I should, but when moving roles around DCs this is WAYYYYY faster than doing it manually.

      Here is an example of moving all roles to a new DC:

      Move-ADDirectoryServerOperationMasterRole -Identity “Target_DC_Name” –OperationMasterRole 0,1,2,3,4
      

      And here is what 0-4 equate to:

      PDC Emulator – 0
      RID Master – 1
      Infrastructure Master – 2
      Schema Master – 3
      Domain Naming Master – 4
      

      If you have to seize the roles from a server that's gone down use the following:

      Move-ADDirectoryServerOperationMasterRole -Identity “Target_DC_name” –OperationMasterRole PDCEmulator,RIDMaster,InfrastructureMaster,SchemaMaster,DomainNamingMaster -Force
      

      You can also use the 0,1,2,3,4 here.

      1 Reply Last reply Reply Quote 5
      • T
        thanksajdotcom
        last edited by

        Good reference! Thanks!

        1 Reply Last reply Reply Quote 0
        • C
          Carnival Boy
          last edited by

          I don't think I'll ever get to the stage where I write my own Powershell scripts from scratch. Mostly, I just cut and paste commands that people have posted on the internet.

          I use it for Exchange a bit. For example, the last command I ran was
          Get-ADGroupMember “Remote Users” | %($name) {Get-Mailbox $_.name | set-casmailbox –owaenabled:$true –activesyncenabled:$true}

          I couldn't write that myself, I must have nicked it from somewhere.

          B 1 Reply Last reply Reply Quote 0
          • M
            Martin9700
            last edited by

            I love using Select-String. Nothing quite as cool as taking a huge log file, parsing out EXACTLY what you want out of it and making a custom object. Version 5 of PowerShell now has the ConvertFrom-String cmdlet that'll make doing this much easier than using RegEx. But where's the challenge?!?!

            1 Reply Last reply Reply Quote 2
            • B
              Bill Kindle @Carnival Boy
              last edited by

              @Carnival-Boy said:

              I don't think I'll ever get to the stage where I write my own Powershell scripts from scratch. Mostly, I just cut and paste commands that people have posted on the internet.

              I use it for Exchange a bit. For example, the last command I ran was
              Get-ADGroupMember “Remote Users” | %($name) {Get-Mailbox $_.name | set-casmailbox –owaenabled:$true –activesyncenabled:$true}

              I couldn't write that myself, I must have nicked it from somewhere.

              I'm sort of the same way. I also type very little. Love Tab completion with Intellisense!

              1 Reply Last reply Reply Quote 1
              • R
                Rob Dunn
                last edited by

                C'mon! Send-MailMessage for the win. Just the fact that it took so much coding in VBScript in comparison to do this very thing. Very useful to pop at the end of a script designed to gather some stats or other stuff.

                1 Reply Last reply Reply Quote 1
                • S
                  scottalanmiller
                  last edited by

                  Hard to beet old fashioned BASH and mailx...

                  mail -s "This is the Subject" me@address.com < message.txt
                  
                  ? 1 Reply Last reply Reply Quote 0
                  • ?
                    A Former User @scottalanmiller
                    last edited by A Former User

                    @scottalanmiller said:

                    Hard to beet old fashioned BASH and mailx...

                    mail -s "This is the Subject" me@address.com < message.txt
                    

                    what does this do? I assume it sends an email if you're using in house exchange?

                    S 1 Reply Last reply Reply Quote 0
                    • S
                      scottalanmiller @A Former User
                      last edited by

                      @Hubtech said:

                      what does this do? I assume it sends an email if you're using in house exchange?

                      Sends an email regardless of what you run. No Exchange needed. In Linux, there is an SMTP MTA on every system by default (of course you can opt out of that) so ever server can send emails right out of the box. The only extra package in use here is mailx which is commonly installed because it is so handy. Just do ...

                      yum -y install mailx
                      

                      It gives you the handy "mail" command syntax. Otherwise you need to know more complicated syntax and no reason to do that.

                      1 Reply Last reply Reply Quote 1
                      • S
                        scottalanmiller
                        last edited by

                        On my systems it would leverage Postfix, which is what most people run on Linux today. There are many MTA options but Postfix and Sendmail are the leaders that own, I would guess, over 99% of the single server market.

                        1 Reply Last reply Reply Quote 0
                        • S
                          StrongBad
                          last edited by

                          I'll vote for Postfix on Linux too. Great email handler. But I think that we've diverged from the point of the thread considerably.

                          1 Reply Last reply Reply Quote 0
                          • ?
                            A Former User
                            last edited by

                            This is one script we did when me and James used to work together at the town. It was mainly to make sure users where restarting to get updates from WSUS as well as new GPOs that needed restarts. We were tempted to take the okay button away after 14 days and make it only a Restart now but that got shot down of course.

                            http://community.spiceworks.com/scripts/show/1478-uptime-notification

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