什么阻止了此Powershell脚本运行

问题描述

我的一个朋友要我编写脚本,但是我没有使用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

}
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)