AnIntroductiontoWindowsPowerShellMicrosoft®VirtualLabsAnIntroductiontoWindowsPowerShellTableofContentsAnIntroductiontoWindowsPowerShell...................................................................................1Exercise1ListingFiles.................................................................................................................................................2Exercise2SortingData.................................................................................................................................................7Exercise3GroupingItemsandCalculatingStatistics.................................................................................................10Exercise4DeletingFiles.............................................................................................................................................14Exercise5CreatingFolders.........................................................................................................................................17Exercise6MovingFilestoDifferentFolders..............................................................................................................21Exercise7ViewingAlltheFilesinaFolderandItsSubfolders.................................................................................23Exercise8SavingDatatoaTextFile..........................................................................................................................24Exercise9WorkingWithPropertiesandMethods......................................................................................................25AnIntroductiontoWindowsPowerShellPage1of25AnIntroductiontoWindowsPowerShellObjectivesAftercompletingthislab,youwillbebetterableto:UseWindowsPowerShelltocarryoutsystemadministrationtasksTakeadvantageofthecapabilitiesbuiltintotheWindowsPowerShellconsoleScenarioIt’severysystemadministrator’sworstnightmare:oneofyourfileservershascrashed–hard–andnobackupexists.Aconsultingfirmwasabletocomeinandretrievefilesoffoneoftheharddrives(fortunately,thedrivecontaininguserdata).However,thebesttheconsultantscoulddowastorecoverthefiles;thedirectorystructurewasessentiallylost.Consequently,theysimplygrabbedallthefilestheycouldretrieveandsavedthemtoasinglefolder:C:\Restored.Inthislab,yourjobistoanalyzethecollectionofretrievedfiles,gettingridoffiles(suchastemporaryfiles)thatareofnouse,andarrangingthefilesinsomesortoftemporaryfilestructure.ToperformthistaskyouhavechosentouseWindowsPowerShell,andforreasonsthatshouldbecomeapparentbytheendofthelab.Note:Admittedlythestepsoutlinedinthislabprobablydon’trepresentthepreferred/recommendedmethodfordealingwithasituationsuchastheonedescribedabove.Butthat’sOK:remember,theintenthereistointroduceyoutoWindowsPowerShell,nottotellyouhowtorecoverfromafileservercrash.Totellyouthetruth,theScriptingGuysaremorelikelytoknowhowtocauseafilesevercrashthantheyaretoknowhowtorecoverfromsuchacrash.TipsforCompletingtheLabThelabrequiresyoutodoaconsiderableamountoftyping.Ifyoudon’twanttodoaconsiderableamountoftypingthat’sfine:allthecommandsusedinthelabcanbefoundinthefileVirtual_Lab_Shortcuts.txt(thisfileisavailablefromthedesktop).Ifyouprefer,youcansimplycopycommandsfromVirtual_Lab_Shortcuts.txtandpastethemintoWindowsPowerShell.Note,toothatthislabcontainsanumberofbonusexercises.Ifyouareconcernedaboutfinishingontimewerecommendthatyouskipthebonusexercises;afterall,youcanalwaysgobackandtrythemlater,eitheraspartofthislaborwhenrunningyourowncopyofWindowsPowerShell.PrerequisitesNone.BasicknowledgeofWindowssystemadministrationisuseful,butnotrequired.EstimatedTimetoCompleteThisLab60MinutesComputerusedinthisLabParisThepasswordfortheAdministratoraccountoninthislabis:pass@word1.AnIntroductiontoWindowsPowerShellPage2of25Exercise1ListingFilesScenarioKnowledgeispower,whichmeansthefirstthingweshoulddoistakealookatthefolderC:\Restoredandgetabetterideaofthetaskaheadofus;wecan’treallydecidewhatcourseofactiontotakeuntilweknowexactlywhatis–andisn’t–inthefolderC:\Restored.Inthefollowingseriesofexercises,we’llshowyouseveraldifferentmethodsofexploringthefilesystemusingWindowsPowerShell.TasksDetailedSteps1.ListingAlltheFilesinaFolderNote:Aswenoted,beforewecandoanythingelseweneedtounderstandexactlywhatfilesweareworkingwith,aswellashowmanyfilesweareworkingwith.Withthatinmind,ourfirststepistousetheGet-ChildItemCmdlettolistallthefilesinthefolderC:\Restored.Becausewe’reworkingwiththefilesystem,theGet-ChildItemCmdletwillfunctionverymuchliketheDircommand.However,Get-ChildItem–whichisdesignedtoreturninformationabouttheitemsfoundinaspecifiedlocation–canalsobeusedwithotherWindowsPowerShelldrives.Forexample,whenworkingwiththeregistry,Get-ChildItemcanbeusedtoreturnallthesubkeysinaspecifiedregistrykey.a.Ifyouhavenotdoneso,double-clickthedesktopiconlabeledWindowsPowerShell;thiswillstartheapplicationandopenaWindowsPowerShellcommandwindow.Inthecommandwindow,typethefollowingandthenpressENTER:get-childitemc:\restoredNote:AlistofallthefilesfoundinthefolderC:\Restoredshouldbedisp