Working with File Systems in Windows PowerShell 1.0
Given that Windows PowerShell is primarily targeted at easing the job of system administrators there is a good chance that part of developing scripts is going to involve interacting with Windows files and file systems. This chapter will focus on working with file systems with Windows PowerShell, while the next chapter, entitled Working with Files in Windows PowerShell, will cover working with the contents of individual files.
Windows PowerShell File System Cmdlets
Windows PowerShell provides a collection of cmdlets specifically for the purposes of interacting with file systems. Each command is accessible in a number of different ways:
- Cmdlet name - The standard cmdlet name, such as Get-Location.
- Alias - An preconfigured, abbreviated alias for the cmdlet name such as gl for Get-Location.
- cmd.exe command - The cmd.exe equivalent command to help users familiar with the Windows Command Prompt migrate to PowerShell.
- UNIX/Linux sh command The UNIX/Linux shell equivalent command to help user migrate skills to Windows PowerShell.
The following table lists the key file system related cmdlets together with the various alternate methods of accessing each one:
</td> <tr> <td>Set-Location</td> <td>sl</td> <td>cd, chdir</td> <td>cd, chdir</td> <td>Sets current directory</td> </tr> </table>
Cmdlet Name |
Alias |
Cmd Command |
UNIX sh Command |
Description |
---|---|---|---|---|
Clear-Item | cli | N/A | N/A | Clears content of a file |
Copy-Item | cpi | copy | cp | Copies file or folder |
Get-Content | gc | type | cat | Gets the content of a file |
Get-Location | gl | cd | pwd | Gets the current directory |
Move-Item | mi | move | mv | Moves file or folder |
New-Item | ni, md | N/A | N/A | Creates file or folder |
Remove-Item | ri | del, rd | rm, rmdir | Deletes file or folder |
Rename-Item | rni, rn | ren | mv | Renames file or folder |
Set-Content | sc | N/A | N/A | Sets file content |
Set-Item | si | N/A | N/A | Sets file content |