locked
powershell: script error for copying items in a folder RRS feed

  • Question

  • Dear readers,

    gci | where-object { $_.creationtime.days -eq (get-date).adddays(-1) }

                                       | foreach {copy-item $_ back}

    This script is not displaying anything nor it is copying files that I created yesterday.

    Thank-you

    SQL 75

    (learning powershell)
    • Edited by SQL75 Monday, April 6, 2015 6:08 PM
    Monday, April 6, 2015 6:07 PM

Answers

  • There is no "days" property.

    This will output all files created yesterday:


    get-childitem | where-object {
      ($_.CreationTime -ge [DateTime]::Today.AddDays(-1)) -and ($_.CreationTime -lt [DateTime]::Today)
    }
    


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by SQL75 Monday, April 6, 2015 6:39 PM
    Monday, April 6, 2015 6:19 PM