SHORT DESCRIPTION

DETAILED DESCRIPTION

The FileSystem provider exposes Windows PowerShell drives that correspond to the logical drives on your computer, including drives that are mapped to network shares. This lets you reference these drives from within Windows PowerShell.

The FileSystem provider lets you refer to files and folders in Windows PowerShell in the same way that you refer to them in Windows.

To refer to a drive, specify the drive name followed by a colon. Like most of Windows PowerShell, the FileSystem provider is not case-sensitive. For example, to get the files and folders on the C drive, you refer to the "C:" drive or the "c:" drive.

A fully qualified name includes the drive name, followed by a colon, any directory and subdirectory names, and the file name (when applicable). Each element of the fully qualified name must be separated either by a backslash (\) or a forward slash (/).

The following example shows the fully qualified name for the Shell.dll file in the System32 subdirectory of the Windows directory on the C drive:

C:\Windows\System32\shell.dll

If any element in the fully qualified name includes spaces, you must enclose the name in quotation marks.

For example,

"C:\Program Files\Internet Explorer\iexplore.exe"

The current location in the file system is represented by a dot or period character (.)

For example, the current location is the C:\Windows\System32 directory, then you can refer to the Shell.dll file in that directory as the following:

.\Shell.dll

To use the FileSystem provider to view and manage files and folders, use the provider cmdlets, such as Get-ChildItem ("dir", "ls") and Set-Location ("cd"). Windows PowerShell also includes a "mkdir" function (alias = "md") that uses the New-Item cmdlet to create a new directory.

CAPABILITIES

Filter, ShouldProcess

EXAMPLES

Splitting a Large File

-------------------------- EXAMPLE 1 --------------------------

By default, the Get-Content cmdlet uses the end-of-line character as its delimiter, so it gets a file as a collection of strings, with each line as one string in the file.

You can use the Delimiter parameter to specify an alternate delimiter. If you set it to the characters that denote the end of a section or the beginning of the next section, you can split the file into logical parts.

The first command gets the Employees.txt file and splits it into sections, each of which ends with the words "End of Employee Record" and it saves it in the $e variable.

The second command uses array notation to get the first item in the collection in $e. It uses an index of 0, because Windows PowerShell arrays are zero-based.

Getting File and Directory Information

-------------------------- EXAMPLE 1 --------------------------

By default, the Get-ChildItem cmdlet does not recurse. If files and folders are present in the current directory when you run this command, a System.IO.FileInfo object and a System.IO.DirectoryInfo object are returned.

-------------------------- EXAMPLE 4 --------------------------

The command uses the Path parameter of the Get-Item cmdlet to get the C:\ps-test directory. It pipes the directory object to the Format-List cmdlet, which displays all (*) the properties and values of the directory in a list.

-------------------------- EXAMPLE 5 --------------------------

The command uses the Path parameter of the Get-Item cmdlet to get the test.txt file. It pipes the file object to the Format-List cmdlet, which displays all (*) the properties and values of the file in a list.

Copying Files and Directories

-------------------------- EXAMPLE 1 --------------------------

This command copies the A.txt file from the C:\A directory to the C:\A\Bb directory:

-------------------------- EXAMPLE 2 --------------------------

It uses the original names of the files. The command overwrites the existing files in the destination directory without prompting for confirmation.

-------------------------- EXAMPLE 3 --------------------------

Copies all the directories and files in the C:\a directory to the C:\c directory. If any of the directories to copy already exist in the destination directory, the command will fail unless you specify the Force parameter.

-------------------------- EXAMPLE 2 --------------------------

You can pipe the contents of the file to another cmdlet. For example, the following command reads the contents of the Test.txt file and then supplies them as input to the ConvertTo-HTML cmdlet:
get-content -path test.txt | convertto-html

-------------------------- EXAMPLE 3 --------------------------

This command replaces the contents of the Test.txt file with the "test content" string:

Managing Security Descriptors

-------------------------- EXAMPLE 1 --------------------------

For more information about this object, pipe the command to the Get-Member cmdlet. Or, see "FileSecurity Class" in the MSDN (Microsoft Developer Network) library at http://go.microsoft.com/fwlink/?LinkId=145718.

-------------------------- EXAMPLE 2 --------------------------

This command returns a System.Security.AccessControl.DirectorySecurity object:

Cmdlets supported:

Delimiter <System.String>

Specifies the delimiter that Get-Content uses to divide the file into objects while it reads.

The default is "\n", the end-of-line character.

Therefore, by default, when reading a text file, Get-Content returns a collection of string objects, each of which ends with an end-of-line character.

When you enter a delimiter that does not exist in the file, Get-Content returns the entire file as a single, undelimited object.

You can use this parameter to split a large file into smaller files by specifying a file separator, such as "End of Example", as the delimiter. The delimiter is preserved (not discarded) and becomes the last item in each file section.

Troubleshooting Note: Currently, when the value of the Delimiter parameter is an empty string, Get-Content does not return anything. This is a known issue. To force Get-Content to return the entire file as a single, undelimited string, enter a value that does not exist in the file.