I'm iterating through all files of a document library using powershell trying to update some files in some folders. I can read the file properties but I'm not able to update them.

Here is my code:

foreach($list in $web.Lists) {

    if ($list.Title -ne "My Documents") {

    Write-Host $list.Title

    foreach($folder in $list.RootFolder.SubFolders) {

        if ($folder.Name -ne "My Folder") {

        Write-Host $folder.Name -ForegroundColor Gray

        foreach($file in $folder.Files) {

            # field type: users and groups
            Write-Host $file.Properties['My Cust Prop 1']
            # output: 40

            # field type: date and time
            Write-Host $file.Properties['My Cust Prop 2']
            # output: 2012-07-11T00:00:00Z

            #This does not work:
            #$file.Properties['My Cust Prop 1'] = 30
            #$file.Properties['My Cust Prop 2'] = '2012-10-25T00:00:00Z'




What am I doing wrong? How do I have to change the code to make this work?

How can I get the User ID if I only have the AD account?

1 Answer 1


This should work, you need to call Update method before Checking In

$file.Properties['My Cust Prop 1'] = 30
$file.Properties['My Cust Prop 2'] = '2012-10-25T00:00:00Z'

Or you can try

$listItem = $web.GetListItem($file.ServerRelativeUrl);
$listItem.Properties['My Cust Prop 1'] = 30
$listItem.Properties['My Cust Prop 2'] = '2012-10-25T00:00:00Z'

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.