PowerShell for Hackers #2

Output & File Operations

Creating a file in PowerShell:

  • echo $null hello.txt # create an empty file

  • echo "Hey" hello1.txt # create a file with some text

  • cat filename and type filename shows the output of a file.

File Listing

  • Get-ChildItem | Format-List lists the files and folders. You can also use gci | fl if you don't want to type the full command.

  • Get-ChildItem | Format-List * lists a very detailed output.

  • Get-ChildItem | Format-Wide lists the files and folders.

You can format the output in so many ways. Get-ChildItem | Out-GridView gives you so many options to filter your dataset.

Move Command

mvis more of a Linux way to do that also works in PowerShell. mvis an alias for Move-Item cmdlet. Similarly, there are other commands such as cp, rm and more...

Similarly, we can remove a file or a directory using the command rm. Please note that to remove more than one item you need to specify a comma rm .\hello\, .\hello2\.