How to do it...

The awk command works with text, and based on the delimiters in the output text, separates the output into columns. This separated output is displayed as columns again, using a the print function, like in C. PowerShell works a little differently.

Let us get started.

  1. If you did not create files, please do so. Here are some commands you could use to create the files.
PS> New-Item ./random/cities -ItemType Directory -Force
PS> Set-Location ./random/
PS> New-Item random-text.txt, himalayas.jpg, crunched-numbers.csv, bangalore.jpg, screenshot-001.png, screenshot-002.png, screenshot-003.png, demo.doc, my-plugin.rb, ./cities/mumbai.html, ./cities/nyc.html, ./cities/cairo.html, ./cities/dubai.html, ./cities/paris.html -ItemType File
  1. You may also want to download some real multimedia content, just so we get the length (file size) property for future use. Just download any random images or media files.
  2. Navigate to the location where you saved the files. I have them in a directory called random in my home directory. You would, too, if you used the script.
PS> Set-Location ./random/
Use tab-completion to complete the cmdlet as well as the path.
  1. List out the contents in the current location.
PS> Get-ChildItem -Path .
  1. Let us say, you do not require the Mode column.
PS> Get-ChildItem -Path . | Select-Object LastWriteTime, Length, Name
If you notice, select does not seem to follow the naming or capitalisation convention that PowerShell uses. How is that? Run Get-Command select to find out.
  1. This sequence does not really make sense to you in the current context. Shuffle the columns.
PS> Get-ChildItem -Path . | Select-Object Name, Length, LastWriteTime

That looks much better.

  1. Now, change the column name of LastWriteTime to Modified.
PS> Get-ChildItem -Path . | Select-Object Name, Length, @{Name='Modified'; Expression={$_.LastWriteTime}}

Notice the name of the last column now, and compare it with the previous output.

  1. Now, pick just the year; not the entire date.
PS> Get-ChildItem -Path . | Select-Object Name, Length, @{Name='Modified'; Expression={$_.LastWriteTime.Year}}
  1. See how many days have passed since the last change.
PS> Get-ChildItem -Path . | select Name, Length, @{Name='DaysSinceModification'; Expression={[math]::Round(((Get-Date) - $_.LastWriteTime).TotalDays)}}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.120.109