通过实例学习Windows Powershell

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

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

1 / 27
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功