A friend of mine asked me to make a script however I have not worked with power shell. I can't seem to find anything that tells me why this script doesn't run. Any tips are appreciated.
The script is meant to run through all files in a folder and the user enters in information given in the document name. This then is put in the meta data of the file and it moves on to the next file.
#1. opens file or first 10 lines (if plain text)
#1.5 get old name and add it to the new name
#2.gets input from the user as follows
#b)date
#c)classification
#d)fileNum
#e)Org
#f)Lang
#3.fills metadata with some input as params
#4.sets name to YYYYMMDD-classification-fileNum-ORG-NAME-Lang
#5.print out current file name for user to change if needed and confirm
foreach($list in $web.Lists) {
#main folder, change as needed
if ($list.Title -ne "My Documents") {
continue
}
Write-Host $list.Title
foreach($folder in $list.RootFolder.SubFolders) {
#this is where we get the sub folder, change as needed
if ($folder.Name -ne "Documents to be changed") {
continue
}
Invoke-Item $file
$dateVal = Get-Date -Format "MM/dd/yyyy"
$Name = $file.BaseName
$Class = Read-Host -Prompt 'Input classification'
$fileNum = Read-Host -Prompt 'Input file number'
$Org = Read-Host -Prompt 'Input Orginization'
$Lang = Read-Host -Prompt 'Input Language e for English and f for french'
if($Lang -eq "E"){
$Lang = "EN"
} else if($Lang -eq "e"){
$Lang = "EN"
}else if($Lang -eq "F"){
$Lang = "FR"
}else{
$Lang = "FR"
}
$file.CheckOut();
$file.Properties['Classifictation'] = $Class
$file.Properties['FileNumber'] = $fileNum
$file.Properties['Orginization'] = $Org
$file.Properties['Language'] = $Lang
$file.Properties['Old Name'] = $Name
$file.Update();
$file.CheckIn('Updated file');
Write-Host "Current name is: '$dateVal'-'$Class'-'$dateVal'-'$fileNum'-'$Org'-'$Name'-'$Lang' "
$Correct = Read-Host -Prompt 'enter y if correct, n if incorrect'
if($Correct -eq "y"){
Rename-Item $file -NewName "'$dateVal'-'$Class'-'$dateVal'-'$fileNum'-'$Org'-'$Name'-'$Lang' "
}else{
$Corrected = Read-Host -Prompt 'Please enter the corrected name'
Rename-Item $file -NewName "'$Corrected'"
}
Get-SmbOpenFile | Where { $_.path -match $file}| Close-SmbOpenFile -Force
}
}