Presentation is loading. Please wait.

Presentation is loading. Please wait.

CN1266 Network Scripting Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+

Similar presentations


Presentation on theme: "CN1266 Network Scripting Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+"— Presentation transcript:

1 CN1266 Network Scripting Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+

2 Agenda Chapter 12: Readin’ and Writin’ Files Quiz Exercise

3 Moving around the file system Set-Location ▫Alias : CD Get-Location ▫Return a string

4 Managing Directories Creating directories ▫MD ’C:\test folder ’ ▫MKDIR ’C:\test folder ’ Deleting directories ▫Remove-Item ’C:\test folder’ ▫Remove-Item –Recurse ’C:\’test folder’ Copying directories ▫Copy-Item ’C:\test folder’ ▫Copy-Item –Recurse ’C:\’test folder’

5 Managing Directories (2) Moving directories ▫Move-Item ’C:\test folder’ C:\folder2 ▫Move ’C:\’test folder’ C:\folder2 Renaming directories ▫Rename-Item ’C:\’test folder’ C:\NewFolder ▫Rename-Item –Recurse ’C:\’test folder’

6 Writing Files 3 ways to write a file ▫Redirection operator  Get-ChildItem C:\Windows\system32 > C:\temp\contents.txt ▫Out-File  Get-ChildItem C:\Windows\system32 | Out-File C:\temp\contents2.txt  See Table 12-1 on Page 165 for options ▫Set-Content  Get-ChildItem C:\Windows\system32 | Set-Content C:\temp\contents3.txt

7 Reading files $data = Get-Content C:\temp\contents.txt ▫Result will be stored in two dimensions array ▫write-host ($data[20][0] +$data[20][17]) Specific numbers of lines to read ▫$data = Get-Content C:\temp\contents.txt – TotalCount 20

8 Working with XML Extensible Markup Language ▫ ▫ Joe ▫ Mark ▫ Allan ▫ See diagram on Page 167

9 Reading and Writing XML files You have to cast variable first for XML file ▫See – strXML.ps1 ▫[xml]$myXML = Get-Content c:\temp\sam.xml ▫$myXML.desert.name ▫$myXML.desert.animal ▫See – XML2.ps1

10 Add new element Create new element ▫$newAnimal = $myXML.CreateElement("animal") ▫$newAnimal.setAttribute("type","vulture") ▫$newAnimal.psbase.innertext = "George" ▫$myXML.desert.AppendChild($newAnimal) Use Save method to save the XML file ▫$myXML.save("C:\temp\sam.xml")

11 Saving objects in XML files Export ▫Get-Process | Export-CliXML C:\temp\proc.xml Import ▫$procHistory = Import-CliXML C:\temp\proc.xml ▫$procHistory ▫$procHistory | Where-Object {$_.Handles -gt 100} | Sort-Object Handles

12 Working with HTML To get the result in HTML format ▫Get-Process | ConvertTo-HTML | Out-File c:\temp\proc.html To make it easier to read or nicer ▫See Code on Page 173


Download ppt "CN1266 Network Scripting Kemtis Kunanuraksapong MSIS with Distinction MCTS, MCDST, MCP, A+"

Similar presentations


Ads by Google