powershell: set modification date script RRS feed

  • Question

  • Q.I need to create a PowerShell script called "Set-FileTime" that will set a file's modification date to a
    specified value. The script should accept two command line parameters:

     The file whose date is to be set
     The date to which the file is to be set

    $filename = $args[0]
    $date = $args[1]

    gci $filename  | Where-object {$_.lastwritetime} | foreach-object { $_.lastwritetime = $date} -whatif

    can we do it this way?


    SQL 75

    (Learning powershell)

    Monday, April 6, 2015 9:39 PM


  • Don't use $args. It's not necessary and can actually make your script harder to read.

    PS C:\> help about_Parameters

    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by SQL75 Monday, April 6, 2015 10:55 PM
    Monday, April 6, 2015 9:43 PM