我正在编写一个PowerShell脚本,将一堆文档“编译”到一个文件夹中,这样我就可以将它压缩起来,然后分发它。脚本将从各种特别指定的目录中提取,所以我不需要搜索和啄食它们,并且可能会错过文档和某些修订。
我正在拔掉它,它正在工作,在我的过程中的某个时刻,有东西停止了。我不知道是什么改变了,或者我是否达到了极限,或者发生了什么,因为这是我使用PowerShell的第一个脚本。我想我忽略了一些非常基本的东西或者犯了一个根本的错误。直到我的错误,或我碰到的限制,脚本运行良好,这些文档正在被复制。这些文档主要是PDF,一些word文档,我认为在某个地方有一两个电子表格。
在完成第176行时:
#to Windows Authentication to Fusion RV
Copy-item -Path $FSG\$SW\0.RoomView.Notes\"windows auth"\*.* -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"Windows Authentication to Fusion RV"脚本停止复制文档,我不知道为什么。我希望你们能帮我。我一直在谷歌上搜索&DuckDuckGo,直到我找到了复制项目的各种高级功能,我认为我不需要任何这些功能。我在脚本中创建目录,所以我不需要测试它们是否存在,而且我知道源目录中会有文件,这就是为什么它们是源目录。
我在某个地方犯了一个根本的错误,还是遇到了一些我不知道的极限?我不想复制超过255个字符的文件。最后一个文件夹中最长的是192。
脚本仍在向前推进,超过了第176行;我在第188行时得到了一个错误。
#to RoomView Connected Displays
Copy-item -Path $FSG\$HW\"RoomView Connected Displays.Packet"\*.* -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"RoomView Connected Displays"其中PowerShell在读取/访问文件时遇到问题,因此我从该目录中删除了该文件,而该目录中没有任何内容被复制。
我正在Windows 7 Pro 64位上开发,似乎是ISE v1.0
我遇到了一个关于添加日志语句的帖子:Powershell Copy-Item caching,但我不知道如何为此集成它。
下面是整个脚本:
# Prompts for quick or full compile
# quick compile does not include the web help, because it takes a while to copy a few thousand files
# sample code for this prompt from http://technet.microsoft.com/en-us/library/ff730939.aspx
[bool]$quickCompile=$true
$title = "Quick compile?"
$message = "Do you want to include the web help files in this compile?"
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
"Copies the web help files."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `
"Does not copy the web help files."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice($title, $message, $options, 1)
#switch ($result)
# {
# 0 {"You selected Yes." $quickCompile=false }
# 1 {"You selected No." $quickCompile=true}
# }
if(!$result){
$quickCompile=$false
}
# Compiles the Fusion packet for distribution
###############################
###########Variables###########
###############################
#folder structure
$FSG = "F:\FSG"
$containerFolder = "Packet.0"
#Fusion for IT and AV Professionals
$rootFolder = "Fusion for IT and AV pros $(Get-Date -format “MM-dd-yyyy”)"
$subRoot1 = "Fusion Server"
$subRoot2 = "Scheduling Enhancement and Panels"
$subRoot2sub1 = "Scheduling Panels"
$subRoot3 = "SQL Server"
#source folders
$HW = "0.Hardware"
$3SMDoc = "0.Hardware\TPMC-3SM.Documentation"
$4SMDoc = "0.Hardware\TPMC-4SM.Documentation"
$4SMDDoc = "0.Hardware\TPMC-4SM-FD.Documentation"
$730Doc = "0.Hardware\TSW-730.Documentation"
$730OLH = "0.Hardware\TSW-730.OLH"
$CENRVS = "0.Hardware\CEN-RVS.Notes"
$ProjMgmt = "0.Project Management"
$SW = "0.Software"
$RVLicensing = "0.Software\0.RoomView.License"
$RVNotes = "0.Software\0.RoomView.Notes"
$SQLLicensing = "0.Software\database.SQL.Licensing"
$SQLNotes = "0.Software\database.SQL.Notes"
$FRVMarketing = "0.Software\Fusion RV.Marketing"
$FRVNetworking = "0.Software\Fusion RV.Networking"
$FRVNotes = "0.Software\Fusion RV.Notes"
###############################
#create the directory structure
###############################
md -Path $FSG\$containerFolder -Name $rootFolder
cd $FSG\$containerFolder\$rootFolder
md "eControl and xPanels"
md "Fusion Server" #$subRoot1
md "Getting Started as a User"
md "Project Management"
md "RoomView Connected Displays"
md "Scheduling Enhancement and Panels" #$subRoot2
md "SQL Server" #$subRoot3
cd $FSG\$containerFolder\$rootFolder\$subRoot1
md "CEN-RVS"
md "Fusion RV Web Help"
md "Licensing Information"
md "Networking"
md "Official Documentation"
md "Prerequisites, including powerShell script"
md "Product Info"
md "Requirements, Architechture, and Design"
md "Tech Info"
md "Windows Authentication to Fusion RV"
cd $FSG\$containerFolder\$rootFolder\$subRoot2
md "Outlook Add-in"
md "Scheduling Panels" #$subRoot2sub1
cd $FSG\$containerFolder\$rootFolder\$subRoot2\$subRoot2sub1
md "TPMC-3SM"
md "TPMC-4SM"
md "TPMC-4SM-FD"
md "TSW-730"
cd $FSG\$containerFolder\$rootFolder\$subRoot3
md "Multi-database model only"
md "SQL Licensing"
cd $FSG\$containerFolder
#reset current folder
###############################
#copy the files
###############################
##### NOTE: ` is the escape character used below and from the same key as the ~, right next to 1 on a standard QWERTY keyboard. ` and ' are different. ' is a single quote
#Copy-Item -Path C:\fso\20110314.log -Destination c:\fsox\mylog.log
#To the root
Copy-item -Path $FSG\$ProjMgmt\starter\"Fusion Support Group Contact info*.pdf" -Destination $FSG\$containerFolder\$rootFolder
Copy-item -Path $FSG\$containerFolder\"Fusion for IT and AV professionals release notes.txt" -Destination $FSG\$containerFolder\$rootFolder
#to eControl and xPanels
Copy-item -Path $FSG\$SW\xpanel.Notes\starter\*.* -Destination $FSG\$containerFolder\$rootFolder\"eControl and xPanels"
#to Fusion Server
Copy-item -Path $FSG\$SW\0.RoomView.Notes\starter\'``[RoomView``] Versions explained*.pdf' -Destination $FSG\$containerFolder\$rootFolder\"Fusion Server"
#to Fusion Server\CEN-RVS
Copy-item -Path $FSG\0.Hardware\"CEN-RVS.Notes"\starter\*.* -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"CEN-RVS"
#Copy the web help
if(!$quickCompile){
Copy-item -Path $FSG\$SW\"Fusion RV.Web Help"\starter\*.* -recurse -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"Fusion RV Web Help"
}
#to Fusion Server\License
Copy-item -Path $FSG\$SW\0.RoomView.License\starter\*.* -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"Licensing Information"
#to Fusion Server\Networking
Copy-item -Path $FSG\$SW\"Fusion RV.Networking"\starter\*.* -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\Networking
Copy-item -Path $FSG\$SW\0.RoomView.Notes\networking\*.* -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\Networking
Copy-item -Path $FSG\$SW\0.Crestron.documentation\starter\"rg_ip_considerations_guide.pdf" -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\Networking
#to Fusion Server\Official Documentation
Copy-item -Path $FSG\$SW\"Fusion RV.Documentation"\starter\* -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"Official Documentation"
#to Fusion Server\"Prerequisites, including powerShell script"
Copy-item -Path $FSG\$SW\"Fusion RV.Documentation"\starter\"The order to install the requirements and the softwares.txt" -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"Prerequisites, including powerShell script"
Copy-item -Path $FSG\$FRVNotes\prereqs\* -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"Prerequisites, including powerShell script"
#to Fusion Server\"Product Info"
Copy-item -Path $FSG\$SW\0.RoomView.Notes\product\*.* -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"Product Info"
Copy-item -Path $FSG\$SW\"Fusion RV.Marketing"\starter\*.* -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"Product Info"
Copy-item -Path $FSG\$SW\"Fusion RV.Documentation"\starter\'``[Fusion``] Spec sheet.pdf' -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"Product Info"
Copy-item -Path $FSG\$SW\"Fusion RV.API.Notes"\starter\*.* -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"Product Info"
#to Requirements, Architechture, and Design
Copy-item -Path $FSG\$SW\"Fusion RV.Notes"\"requirements and design"\*.* -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"Requirements, Architechture, and Design"
#to Tech Info
Copy-item -Path $FSG\$SW\"Fusion RV.Notes"\"tech info"\*.* -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"Tech Info"
Copy-item -Path $FSG\$SW\0.RoomView.Notes\"tech info"\*.* -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"Tech Info"
#to Windows Authentication to Fusion RV
Copy-item -Path $FSG\$SW\0.RoomView.Notes\"windows auth"\*.* -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"Windows Authentication to Fusion RV"
#to Getting Started as a User
Copy-item -Path $FSG\$SW\"Fusion RV.User guides"\starter\*.* -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"Getting Started as a User"
Copy-item -Path $FSG\$SW\"Fusion RV.Notes"\user\*.* -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"Getting Started as a User"
Copy-item -Path $FSG\$SW\0.RoomView.License\starter\*.* -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"Getting Started as a User"
#to Project Management
Copy-item -Path $FSG\$ProjMgmt\starter\*.* -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"Project Management"
#to RoomView Connected Displays
Copy-item -Path $FSG\$HW\"RoomView Connected Displays.Packet"\*.* -Destination $FSG\$containerFolder\$rootFolder\$subRoot1\"RoomView Connected Displays"发布于 2014-12-05 15:58:03
结果,我忘了删除较新文件夹中目标路径中的子文件夹引用。这绝对是个“该死”的时刻。目标文件夹太长了一个文件夹,所以没有任何东西被复制。
谢谢你的帮助!
https://stackoverflow.com/questions/27318836
复制相似问题