Finding modified date of a file/folder

后端 未结 5 1118
执笔经年
执笔经年 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:12

    Here's what worked for me:

    $a = Get-ChildItem \\server\XXX\Received_Orders\*.* | Where{$_.LastWriteTime -ge (Get-Date).AddDays(-7)}
    if ($a = (Get-ChildItem \\server\XXX\Received_Orders\*.* | Where{$_.LastWriteTime -gt (Get-Date).AddDays(-7)}  
    #Im using the -gt switch instead of -ge
    {}
    Else
    {
    'STORE XXX HAS NOT RECEIVED ANY ORDERS IN THE PAST 7 DAYS'
    }
    
    
    $b = Get-ChildItem \\COMP NAME\Folder\*.* | Where{$_.LastWriteTime -ge (Get-Date).AddDays(-1)}
    if ($b = (Get-ChildItem \\COMP NAME\TFolder\*.* | Where{$_.LastWriteTime -gt (Get-Date).AddDays(-1)))}
    {}
    Else
    {
    'STORE XXX DID NOT RUN ITS BACKUP LAST NIGHT'
    }
    
    0 讨论(0)
  • 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")
    }
    
    0 讨论(0)
  • 2020-12-09 02:31

    PowerShell code to find all document library files modified from last 2 days.

    $web = Get-SPWeb -Identity http://siteName:9090/ 
            $list = $web.GetList("http://siteName:9090/Style Library/")
            $folderquery =  New-Object Microsoft.SharePoint.SPQuery  
            $foldercamlQuery =  
            '<Where>   <Eq> 
                    <FieldRef Name="ContentType" />  <Value Type="text">Folder</Value> 
                </Eq> </Where>' 
            $folderquery.Query = $foldercamlQuery 
            $folders = $list.GetItems($folderquery) 
            foreach($folderItem in $folders) 
            { 
                $folder = $folderItem.Folder
                if($folder.ItemCount -gt 0){ 
                Write-Host " find Item count " $folder.ItemCount
                    $oldest = $null
                    $files = $folder.Files
    
                    $date = (Get-Date).AddDays(-2).ToString(“MM/dd/yyyy”)
                    foreach ($file in $files){ 
                        if($file.Item["Modified"]-Ge $date)
                        {
                            Write-Host "Last 2 days modified folder name:"   $folder   " File Name: "  $file.Item["Name"]   " Date of midified: "  $file.Item["Modified"] 
                        } 
                    } 
                } 
                else
                 { 
                    Write-Warning "$folder['Name'] is empty" 
                } 
            }
    
    0 讨论(0)
  • 2020-12-09 02:36

    You can try dirTimesJS.bat and fileTimesJS.bat

    example:

    C:\>dirTimesJS.bat %windir%
    
    directory timestamps for C:\Windows :
    
    Modified : 2020-11-22 22:12:55
    Modified - milliseconds passed : 1604607175000
    Modified day of the week : 4
    
    Created : 2019-12-11 11:03:44
    Created - milliseconds passed : 1575709424000
    Created day of the week : 6
    
    Accessed : 2020-11-16 16:39:22
    Accessed - milliseconds passed : 1605019162000
    Accessed day of the week : 2
    
    C:\>fileTimesJS.bat %windir%\notepad.exe
    
    file timestamps for C:\Windows\notepad.exe :
    
    Modified : 2020-09-08 08:33:31
    Modified - milliseconds passed : 1599629611000
    Modified day of the week : 3
    
    Created : 2020-09-08 08:33:31
    Created - milliseconds passed : 1599629611000
    Created day of the week : 3
    
    Accessed : 2020-11-23 23:59:22
    Accessed - milliseconds passed : 1604613562000
    Accessed day of the week : 4
    
    0 讨论(0)
  • 2020-12-09 02:39

    If you run the Get-Item or Get-ChildItem commands these will output System.IO.FileInfo and System.IO.DirectoryInfo objects that contain this information e.g.:

    Get-Item c:\folder | Format-List  
    

    Or you can access the property directly like so:

    Get-Item c:\folder | Foreach {$_.LastWriteTime}
    

    To start to filter folders & files based on last write time you can do this:

    Get-ChildItem c:\folder | Where{$_.LastWriteTime -gt (Get-Date).AddDays(-7)}
    
    0 讨论(0)
提交回复
热议问题