One of the things on my to do list is to learn PowerShell to a decent enough level where i am comfortable with it to perform my day to day duties. Me and scripting have never really got on very well even though i am aware of its usefulness and benefits. Throughout the years i have managed to get away with asking colleagues, using experts-exchange and Google to grab a script which somebody else has already written.
As technology is moving forwards I am seeing the need for scripting and automation more and more especially with PowerShell. So i have decided to take the plunge and get to learn PowerShell properly. I have used it over the past few years but never really in anger and usually just a few one-liners when required.
My tool of choice is going to be a book called PowerShell in a month of Lunches by the PowerShell guru Don Jones (http://concentratedtech.com/). The idea behind the book is to split the lessons into 23 lessons that you can do in your lunch hour. Since I generally do not take a lunch break I will be doing these mainly on weekends and in the evening
At the end of each chapter he sets a few tasks to make sure that you have learnt whatever you have just read. I will be posting the questions and my answers here so that i can re-call them for future reference if required. So the first ones are below:
1) Create a text file that contains the names of the files and folders in C:\Windows. Name the text file MyDir.txt.
DIR C:\WINDOWS > C:\MYDIR.TXT
2) Display the contents of that text file.
3) Rename the file from MyDir.txt to WindowsDir.txt.
RENAME-ITEM C:\MYDIR.TXT C:\WINDOWSDIR.TXT
4) Create a new folder named LabOutput you can either do this in your Documents folder, or in the root of your C: drive.
NEW-ITEM -ItemType Directory C:\Laboutput
Copy-Item C:\Windowsdir.txt C:\Laboutput\Windowsdir.txt
6) Delete the original copy of WindowsDir.txt—not the copy that you just made in LabOutput.
7) Display a list of running processes.
8) Redirect a list of running processes into a file named Procs.txt.
Get-Process >> c:\procs.txt
9) Move Procs.txt into the LabOutput folder if it isn’t in there already.
Move-Item c:\procs.txt c:\Laboutput\
10) Display the contents of Procs.txt so that only one page displays at a time
Get-Conent c:\laboutput\procs.txt | out-host -paging