Unix tail equivalent command in Windows Powershell

I have to look at the last few lines of a large file (typical size is 500MB-2GB). I am looking for a equivalent of Unix command tail for Windows Powershell. A few alternatives available on are, http://tailforwin32.sourceforge.net/ and Get-Content [filename] | Select-Object -Last 10 For me, it is not allowed to use the first alternative, … Read more

Create directory if it does not exist

I am writing a PowerShell script to create several directories if they do not exist. The filesystem looks similar to this D:\ D:\TopDirec\SubDirec\Project1\Revision1\Reports\ D:\TopDirec\SubDirec\Project2\Revision1\ D:\TopDirec\SubDirec\Project3\Revision1\ Each project folder has multiple revisions. Each revision folder needs a Reports folder. Some of the “revisions” folders already contain a Reports folder; however, most do not. I need to … Read more

How do I pass multiple parameters into a function in PowerShell?

If I have a function which accepts more than one string parameter, the first parameter seems to get all the data assigned to it, and remaining parameters are passed in as empty. A quick test script: Function Test([string]$arg1, [string]$arg2) { Write-Host “`$arg1 value: $arg1” Write-Host “`$arg2 value: $arg2” } Test(“ABC”, “DEF”) The output generated is … Read more

How can I pass an argument to a PowerShell script?

There’s a PowerShell script named itunesForward.ps1 that makes iTunes fast forward 30 seconds: $iTunes = New-Object -ComObject iTunes.Application if ($iTunes.playerstate -eq 1) { $iTunes.PlayerPosition = $iTunes.PlayerPosition + 30 } It is executed with a prompt line command: powershell.exe itunesForward.ps1 Is it possible to pass an argument from the command line and have it applied in … Read more