0

I'd like to be able to update some files propreties via Powershell, so here the script I tried:

[System.Array]$Words = 'Project Overview','Project from pervious Years'
foreach($folder in $list.RootFolder.SubFolders) {
    if ($folder.Name -ne "Reports") {
        foreach($file in $folder.Files) 
            if ($Words –contains $file.Name) {
                $file.CheckOut();
                $file.Properties['Status'] = "9. Old"
                $file.Properties.Update();
                $file.CheckIn('Test'); 
            }
        }
   }
}

the files I want to modify are stored in my Reports folder, so once I'm in this folder I loop all files until I find a files whose the name is included in my array, I update the files and then I continue I don't know why but my code doesn't work and as it's the first I tried to do something via powershell, maybe something is wrong in my code Thank you

  • Are you using Server Side Object Model or Client site object model to connect Sharepoint? Also What I see in your code that you missing { on second for loop – Bharat Khunti Jul 22 at 6:51
  • Your IF condition is wrong. It is looking for folder names not equal to Reports. – SharePoint Badger Jul 25 at 4:09
1

The following PowerShell script for your reference.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get the Web
$web=Get-SPWeb "http://sp2013/sites/team"
#Get the List/Library
$list=$web.Lists.TryGetList("Library")

[System.Array]$Words = 'Project Overview','Project from pervious Years'

foreach($folder in $list.RootFolder.SubFolders) {
    if ($folder.Name -eq "Reports") {
        foreach($file in $folder.Files){
            if ($Words –contains $file.Name.split('.')[0]) {                
                $file.CheckOut()
                $file.Properties["Status"] = "9. Old"
                $file.Update()
                $file.CheckIn('Test')
            }
        }
    }
}   

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.