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?

2 Answers 2


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
  • Thanks. I hvae to use the full url for GetFile but now it works.
    – jlai
    Feb 7, 2017 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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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