I have a custom file customstyle.css in my site collestion's style library. How can I get this file's last modified date into a variable in PowerShell?


Try it as below:

$site = "https://sitecollectionurl"

#path of your css file
$sourcefile = "/style library/customstyle.css"

$web = Get-SPWeb $site

$file = $web.GetFile($site + $sourcefile)

$listItem = $file.ListItemAllFields

$modified = $listItem["Modified"]

write-host $modified
| improve this answer | |
  • Thanks. I hvae to use the full url for GetFile but now it works. – jlai Feb 7 '17 at 7:45
$FileURL = "http://something.com/...../customstyle.css"
$site = New-Object Microsoft.SharePoint.SPSite($FileURL)
$web = $site.OpenWeb()
$item = $web.GetListItem($FileURL)
$modified = $item["Modified"]
Write-Host $item.Name was modified on $modified

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.