Provides access to files and directories. (FileSystem)
PROVIDER NAME FileSystem DRIVES C, DSYNOPSISProvides access to files and directories.DESCRIPTIONThe Windows PowerShell FileSystem provider lets you get, add, change, clear, and delete files and directories in Windows PowerShell. The FileSystem provider exposes Windows PowerShell drives that correspond to the logical drives configured on your computer, including drives mapped to network shares. For example, a computer with one floppy disk drive, one hard disk drive, and one mapped network shared directory might have drives named A, C, and Z. The FileSystem provider exposes Windows PowerShell drives that correspond directly to A, C, and Z, allowing you to reference these drives from within Windows PowerShell. For example, to reference drive C, you use C:, as shown in the following example: get-childitem c: The command returns all the contents on the C drive, including files and directories. When you reference a specific directory or file through the FileSystem provider, you must provide the information necessary to identify that directory or file. This means that, in some cases, you must provide a fully qualified name. A fully qualified name includes the drive name (along with a colon), any directory and subdirectory names, and the file name (when applicable). For instance, the following example shows the fully qualified name for the Shell.dll file, which is located in the System32 subdirectory of the Windows directory on the C drive: c:\windows\system32\shell.dll As you can see, each element of the fully qualified name is separated by a backslash (\). Windows PowerShell also allows you to use a forward slash (/) to be consistent with a variety of other shells. In some cases, you do not need to supply a fully-qualified name when referencing a file or directory. For example, if you want to access a file in your current working location, you need to provide only the file name. If your current working location is c:\windows, you can view a list of all the .dll files in that directory by using the following command: get-childitem *.dll If your working directory is something other than c:\windows, such as c:\program files\Windows PowerShell, your command might need to include the fully qualified name: get-childitem c:\windows\*.dll In some cases, you can use relative references to a location. If your working location is c:\windows, and you want to view a list of .dll files in the c:\windows\system32 directory, you can use the following command: get-childitem .\system32\*.dll The period before \system32 represents the current working location. In some situations, your current working location will be on a drive other than a FileSystem drive. If this is the case, you must always include the name of the target drive in your reference. For example, suppose that your current working location is the env: drive. To view the contents of the C drive, you would use the following command: get-childitem c: CAPABILITIES TASKS TASK: Navigating the File SystemExamples
EXAMPLE 1This command gets the current location: get-location The Get-Location cmdlet includes the functionality of commands like the cd command in the Windows Command Prompt and the pwd command in UNIX. For more information, type: get-help get-locationEXAMPLE 2This command sets the current location: set-location C: TASK: Getting File and Directory InformationEXAMPLE 1This command gets all the files and directories in the current directory: get-childitem 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 2This command gets all the files and directories in the current directory by using Get-ChildItem: get-childitem | where-object {!$_.psiscontainer} It pipes the results to Where-Object, which examines the PSIsContainer property and lets only the objects that are not (!) containers through the pipeline.EXAMPLE 3This command gets all the files and directories in the current directory by using Get-ChildItem. It pipes the results to Where-Object, which examines the PSIsContainer property and lets only the objects that are containers through the pipeline. get-childitem | where-object {$_.psiscontainer}EXAMPLE 4This command gets all the files and directories in the current directory by using Get-ChildItem: get-item -path a | format-list * It pipes the results to the Where-Object cmdlet, which examines the PSIsContainer property and lets only the objects that are containers through the pipeline.EXAMPLE 5This command uses the Get-Item cmdlet to get information about the Test.txt file: get-item -path test.txt | format-list * The Format-List cmdlet is used to display all the properties of the resulting object. TASK: Copying Files and DirectoriesEXAMPLE 1This command copies the A.txt file from the C:\A directory to the C:\A\Bb directory: copy-item -path C:\a\a.txt -destination C:\a\bb\a.txt It overwrites files in the destination directory without prompting for confirmation.EXAMPLE 2This command copies all the files in the C:\A\Bb directory that have the .txt file name extension to the C:\A\Cc\Ccc\ directory: copy-item -path C:\a\bb\*.txt -destination C:\a\cc\ccc\ It uses the original names of the files. The command overwrites the existing files in the destination directory without prompting for confirmation.EXAMPLE 3Copies 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. copy-item -path C:\a\* -destination C:\c -recurse TASK: Moving Files and DirectoriesEXAMPLE 1This command moves the C.txt file in the C:\A directory to the C:\A\Aa directory: move-item -path C:\a\c.txt -destination C:\a\aa The command will not automatically overwrite an existing file that has the same name. To force the cmdlet to overwrite an existing file, specify the Force parameter.EXAMPLE 2This command moves the C:\A directory and all its contents to the C:\B directory: move-item -path C:\a -destination C:\b You cannot move a directory when that directory is the current location. TASK: Managing File ContentEXAMPLE 1This command appends the "test content" string to the Test.txt file: add-content -path test.txt -value "test content" The existing content in the Test.txt file is not deleted.EXAMPLE 2This command gets the contents of the Test.txt file and displays them in the console: get-content -path test.txt 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-htmlEXAMPLE 3This command replaces the contents of the Test.txt file with the "test content" string: set-content -path test.txt -value "test content" It overwrites the contents of Test.txt. You can use the Value parameter of the New-Item cmdlet to add content to a file when you create it. TASK: Managing Security DescriptorsEXAMPLE 1This command returns a System.Security.AccessControl.FileSecurity object: get-acl -path test.txt | format-list -property * 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 2This command returns a System.Security.AccessControl.DirectorySecurity object: get-acl -path test_directory | format-list -property * For more information about this object, pipe the command to the Get-Member cmdlet. Or, see "DirectorySecurity Class" in the MSDN library at http://go.microsoft.com/fwlink/?LinkId=145736. TASK: Creating Files and DirectoriesEXAMPLE 1This command creates the Logfiles directory on the C drive: new-item -path c:\ -name logfiles -type directoryEXAMPLE 2This command creates the Log2.txt file in the C:\Logfiles directory and then adds the "test log" string to the file: new-item -path c:\logfiles -name log.txt -type fileEXAMPLE 3Creates a file called Log2.txt in the C:\logfiles directory and adds the string "test log" to the file. new-item -path c:\logfiles -name log2.txt -type file -value "test log" TASK: Renaming Files and DirectoriesEXAMPLE 1This command renames the A.txt file in the C:\A directory to B.txt: rename-item -path c:\a\a.txt -newname b.txtEXAMPLE 2This command renames the C:\A\Cc directory to C:\A\Dd: rename-item -path c:\a\cc -newname dd TASK: Deleting Files and DirectoriesEXAMPLE 1This command deletes the Test.txt file in the current directory: remove-item -path test.txtEXAMPLE 2This command deletes all the files in the current directory that have the .xml file name extension: remove-item -path *.xml TASK: Starting a Program by Invoking an Associated FileEXAMPLE 1The first command uses the Get-Service cmdlet to get information about local services. It pipes the information to the Export-Csv cmdlet and then stores that information in the Services.csv file. The second command uses Invoke-Item to open the Services.csv file in the program associated with the .csv extension: get-service | export-csv -path services.csv invoke-item -path services.csv DYNAMIC PARAMETERS -Encoding <Microsoft.PowerShell.Commands.FileSystemCmdletProviderEncoding> Unknown The encoding type is unknown or invalid. The data can be treated as binary. String Uses the encoding type for a string. Unicode Encodes in UTF-16 format using the little-endian byte order. Byte Encodes a set of characters into a sequence of bytes. BigEndianUnicode Encodes in UTF-16 format using the big-endian byte order. UTF8 Encodes in UTF-8 format. UTF7 Encodes in UTF-7 format. ASCII Uses the encoding for the ASCII (7-bit) character set. Cmdlets Supported: Add-Content, Get-Content, Set-Content -Delimiter <System.String> Specifies the delimiter to use when reading the file. The default is "\n" (end of line). Cmdlets Supported: Get-Content -Wait <System.Management.Automation.SwitchParameter> Waits for content to be appended to the file. If content is appended, it returns the appended content. If the content has changed, it returns the entire file. When waiting, Get-Content checks the file once each second until you interrupt it, such as by pressing CTRL+C. Cmdlets Supported: Get-ContentNOTESRELATED LINKS about_Providers C:\Windows>powershell get-help Function -full
Microsoft Windows [Version 10.0.19045.3693]
Copyright (c) 2023 Microsoft Corporation.
ColorConsole [Version 3.7.1000] PowerShell 2.0-Export