PowerShell/File System

This lesson introduces PowerShell file system processing.

Objectives and Skills
After completing this lesson, you will be able to:
 * Describe basic PowerShell file system concepts.
 * Create PowerShell scripts to manage files and folders.
 * Create PowerShell scripts to read and write text file content.

Readings

 * 1)  File system
 * 2)  Directory (computing)
 * 3)  Directory structure
 * 4)  Text file
 * 5) BonusBits: Mastering PowerShell Chapter 15 - The File System

Multimedia

 * 1) YouTube: Creating Files and Folders in PowerShell
 * 2) YouTube: Grab content from a file in Powershell
 * 3) YouTube: PowerShell - How To - Working with TXT and CSV Files

Get-ChildItem
The Get-ChildItem cmdlet gets items and child items from a given location. It is similar in concept to a DIR command to list files in a directory.

New-Item
The New-Item cmdlet creates a new item of the given type at the given path location.

Move-Item
The Move-Item cmdlet moves an item from the given path location to the given destination.

Copy-Item
The Copy-Item cmdlet copies an item from the given path location to the given destination.

Remove-Item
The Remove-Item cmdlet removes an item from the given path location.

Test-Path
The Test-Path cmdlet determines whether a path exists.

Set-Content
The Set-Content cmdlet is a string-processing cmdlet that writes or replaces the content in the specified item, such as a file.

Add-Content
The Add-Content cmdlet appends content to a specified item or file.

Get-Content
The Get-Content cmdlet gets the content of a given item.

Clear-Content
The Clear-Content cmdlet deletes the contents of an item, such as deleting the text from a file, but it does not delete the item.

Activities

 * 1) Review Microsoft TechNet: Using the Get-ChildItem Cmdlet.  Experiment with using Get-ChildItem to retrieve directory listings.
 * 2) Review Microsoft TechNet: Using the New-Item Cmdlet.  Experiment with creating folders and files.
 * 3) Review Microsoft TechNet: Using the Move-Item Cmdlet.  Experiment with moving folders and files.
 * 4) Review Microsoft TechNet: Using the Copy-Item Cmdlet.  Experiment with copying folders and files.
 * 5) Review Microsoft TechNet: Using the Remove-Item Cmdlet.  Experiment with removing folders and files.
 * 6) Review Microsoft TechNet: Using the Get-Content Cmdlet.  Use the Get-Content cmdlet to read a file and process the file content line by line.  For example, create a file with student names and test scores.  Process the file line by line and display the average score for the class.  Use Test-Path to verify that the file path exists before getting the file content, and a Try-Catch-Finally block to handle any errors that occur during file processing.
 * 7) Review WindowsITPro: Get Hex Dumps of Files in PowerShell.  Use the Get-Content cmdlet and with -Encoding Byte and -ReadCount 1 to read one character at a time and then display each character's ASCII value.  Display a multi-line text file and verify that each line does, indeed, end with CR and LF characters (13 and 10).

Lesson Summary

 * A file system is used to control how data is stored and retrieved. There are many different kinds of file systems. Each one has different structure and logic, properties of speed, flexibility, security, size and more.
 * File systems are responsible for arranging storage space; reliability, efficiency, and tuning with regard to the physical storage medium are important design considerations.
 * File systems allocate space in a granular manner, usually multiple physical units on the device.
 * A filename (or file name) is used to identify a storage location in the file system.
 * File systems typically have directories (also called folders) which allow the user to group files into separate collections.
 * A file system stores all the metadata associated with the file—including the file name, the length of the contents of a file, and the location of the file in the folder hierarchy—separate from the contents of the file.
 * Directory utilities may be used to create, rename and delete directory entries.
 * File utilities create, list, copy, move and delete files, and alter metadata.
 * All file systems have some functional limit that defines the maximum storable data capacity within that system.
 * A directory is a file system cataloging structure which contains references to other computer files, and possibly other directories.
 * A text file is a kind of computer file that is structured as a sequence of lines of electronic text.
 * MS-DOS and Windows use a common text file format, with each line of text separated by a two-character combination: CR and LF, which have ASCII codes 13 and 10.
 * The Get-ChildItem cmdlet gets items and child items from a given location.
 * The New-Item cmdlet creates a new item of the given type at the given path location.
 * The Move-Item cmdlet moves an item from the given path location to the given destination.
 * The Copy-Item cmdlet copies an item from the given path location to the given destination.
 * The Remove-Item cmdlet removes an item from the given path location.
 * The Test-Path cmdlet determines whether a path exists.
 * The Set-Content cmdlet is a string-processing cmdlet that writes or replaces the content in the specified item, such as a file.
 * The Add-Content cmdlet appends content to a specified item or file.
 * The Get-Content cmdlet gets the content of a given item.
 * The Clear-Content cmdlet deletes the contents of an item, such as deleting the text from a file, but it does not delete the item.

Key Terms

 * ASCII (American Standard Code for Information Interchange)
 * A character-encoding scheme originally based on the English alphabet which encodes 128 specified characters into 7-bit binary integers.


 * descriptive metadata
 * Data about individual instances of application data, or data content.


 * file system fragmentation
 * The inability of a file system to lay out related data sequentially (contiguously)


 * flat file system
 * A file system in which there are no subdirectories.


 * hierarchical filesystem
 * A filesystem in which files and directories are organized in a manner that resembles a tree.


 * metadata
 * Data about data, including structural metadata and descriptive metadata.


 * root
 * The top-most directory in a hierarchical filesystem.


 * structural metadata
 * Data about the design and specification of data structures, or the containers of data.


 * subdirectory
 * A directory contained inside another directory.

Assessments

 * Flashcards: Quizlet: Windows PowerShell - File System
 * Quiz: Quizlet: Windows PowerShell - File System