Finding modified date of a file/folder

后端 未结 5 1131
执笔经年
执笔经年 2020-12-09 02:04

I am very new to PowerShell, and I was hoping I could get some help creating a script that tells me the modified date of a file.

I wish I knew more about PowerShell,

5条回答
  •  半阙折子戏
    2020-12-09 02:21

    To get the modified date on a single file try:

    $lastModifiedDate = (Get-Item "C:\foo.tmp").LastWriteTime
    

    To compare with another:

    $dateA= $lastModifiedDate 
    $dateB= (Get-Item "C:\other.tmp").LastWriteTime
    
    if ($dateA -ge $dateB) {
      Write-Host("C:\foo.tmp was modified at the same time or after C:\other.tmp")
    } else {
      Write-Host("C:\foo.tmp was modified before C:\other.tmp")
    }
    

提交回复
热议问题