0

我的一个朋友让我制作一个脚本,但是我没有使用过 power shell。我似乎找不到任何可以告诉我为什么这个脚本没有运行的东西。任何提示表示赞赏。

该脚本旨在遍历文件夹中的所有文件,并且用户输入文档名称中给出的信息。然后将其放入文件的元数据中,然后移至下一个文件。

#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

}
}
4

0 回答 0