Latest Event Updates
Yes PowerShell has aliases for its commands, a lot of them. While typing them out long hand does have intellisense and tab completion, its much easier if you get used to using the aliases of your most used commands. Even Get-Alias has an alias “gal” that will list to the console the basic information below. Figure 1 is not the complete list, just a snippet as the list is way too long, but the idea is that you can only look at it, you can’t open it and refer to it to learn them.
I exported them to a CSV using the line: gal | Export-CSV -Filename which gave me a lot more data and I just deleted the 10 rows I didn’t need. I could have went ahead and selected names to shorten the out too, but its always nice to see what PowerShell provides you. One thing it does for the Get-Alias that you don’t see is the Microsoft link to the help page for that command. See figure 2 below to see the output.
Not only save time with less typing, it gives me shortcuts to look at the whole command in a browser instead of in a console with Get-Help and needing to know the parameters that go with it.
|Alias||gc -> Get-Content|
|Alias||gcb -> Get-Clipboard|
|Alias||gci -> Get-ChildItem|
|Alias||gcm -> Get-Command|
|Alias||gcs -> Get-PSCallStack|
|Alias||gdr -> Get-PSDrive|
|Alias||ghy -> Get-History|
|Alias||gi -> Get-Item|
|Alias||gjb -> Get-Job|
|Alias||gl -> Get-Location|
|Alias||gm -> Get-Member|
|Alias||gmo -> Get-Module|
|Alias||gp -> Get-ItemProperty|
|Alias||gps -> Get-Process|
|Alias||gpv -> Get-ItemPropertyValue|
|Alias||group -> Group-Object|
|Alias||gsn -> Get-PSSession|
|Alias||gsnp -> Get-PSSnapin|
|Alias||gsv -> Get-Service|
|Alias||gu -> Get-Unique|
|Alias||gv -> Get-Variable|
|Alias||gwmi -> Get-WmiObject|
We all have added many computers to a Domain, moved them between OU’s, renamed them too. Using the Windows GUI is a tedious process with many steps. The nice thing about PowerShell is that it’s quick, easy and can be scripted to do multiple computers at one time. Even in the one computer at a time scenario it saves a few minutes a computer.
So, how do we do it? Add-Computer, Move-ADObject, Rename-Computer, Restart-Computer are all great cmdlets that make the job seamless and fast. The following command adds the local computer naming it Win10-TL to the domain called “YourDomain” and then restarts the computer to process the change in AD and on the computer immediately.
Add-Computer -ComputerName “Win10-TL” -DomainName “YourDomain” -Restart
That is way too easy for me. I need a harder way to do it so my boss thinks I’m a genius when I get things done fast and efficiently. Now, I’m all for looking like Scotty from Star Trek, but I also value my time and will look for anything that will make my job easier so that I can work on other interesting projects.
Want to move that computer from the default Computer OU to the new OU it belongs in?
get-adcomputer Win10-TL | Move-ADObject -TargetPath ‘ou=staff computers,dc=mydomain,dc=net’
You can shorten the move command above by using other methods. One I like is placing the TargetPath into a Variable called $TP.
Work smarter, not harder.
This afternoon I updated a piece of software we use for instruction and classroom management on 37 servers. The software is actually a service, while its teacher and student versions are installed on the individual classroom machines via an auto update function within the service.
In a situation that many of us as Systems Administrators have been in, I would have normally did an RDP to each server, copied the service install, the teacher and student install to the server and ran the service MSI to install it. That would be on average 5 minutes on each server for a total time of just over 3 hours.
To avoid that we now have PowerShell and the Power of PowerShell. I wrote a script, tested it on a Dev server until I felt comfortable that is was debugged and then ran it on the production servers. The writing of the script took a half hour, testing a half hour and running it to completion from my desk in a PowerShell console took 4 minutes.
Yes, that’s 4 minutes to run the script to completion on all 37 servers. Add the writing and testing time and you get a total of one hour and four minutes. In my field, educational K12 we have maintenance Windows that run after school and district hours to avoid as much interruption to learning as possible. If I was to do the updates the manual method I would have had to start at 4:30pm on a Friday for 3 hours. While that would have been overtime, I would rather not stay after already working an eight hour day on a Friday if I don’t have to.
The Power of PowerShell made it so that my total time invested in the actual update was less than 10 minutes which includes the four the script took. The hour of writing and testing the script was during my normal work day so they don’t count. Because school is out, I was able to get the school based technology support personnel to agree to not be using the servers to let me start at 4pm instead of 4:30pm at the end of our day.
That means I was able to update a major tool of our classroom learning and IT software management during the work day in 4 minutes without any real disruption to anyone. Now that is what I consider good time management.
Overall, I saved the district 3 hours of overtime. At the same time I saved myself from an extra 3 hours at work on top of the eight I was already working and I was able to use them with my family. I also now have a script that I can use with a multitude of software installs to save even more time. That’s the Power of PowerShell.
Before I close I want to address the people that say I’ve hurt my value, made something that can replace me, or left pay in the bosses pockets. Well, to me those thoughts are from people who are insecure with themselves and are only looking out for themselves. I helped my value by making something that lets me spend more time on a different project that will help the students who I’m working for. I’ve also saved the district money that can be spent somewhere else that will help the students who I’m working for. We have a job not because of ourselves, but because of the end user. PowerShell makes that possible for me.