复制项目失败没有错误,我确定它很简单,但我看不到它

时间:2014-12-05 15:05:54

标签: powershell copy-item

我正在编写一个PowerShell脚本,将一堆文档“编译”到一个文件夹中,这样我就可以压缩它然后分发它。该脚本将从各种特别指定的目录中提取,因此我不必搜索和查看它们,并可能错过文档和某些修订。

我正在堵塞,它正在工作,在我的过程中的某个时刻,某些东西停了下来。我无法弄清楚改变了什么,或者我是否达到了限制,或者发生了什么,因为这是我使用PowerShell的第一个脚本。我想我忽略了一些非常基本的东西或者犯了一个根本性的错误。直到我的错误或我遇到的限制,脚本运行正常并且正在复制这些文档。这些文件主要是PDF文件,一些文字文档,我认为这里有一两个电子表格。

在第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"

脚本停止复制文档,我无法弄清楚原因。我希望你们和他们一起加尔斯可以帮助我。我用Google搜索了& DuckDuck去了,直到我发现了复制项目的各种高级功能,我认为我不需要任何这些功能。我在脚本中创建目录,所以我不需要测试它们是否在那里,我知道源目录中会有文件,这就是为什么它们是源目录。

我在某个地方犯了一个根本性的错误,还是我遇到了一些我不知道的限制?我不是要复制超过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在读取/访问文件时遇到问题,因此我从该目录中删除了该文件,并且没有复制该目录中的任何内容。

我正在使用似乎是ISE v1.0的Windows 7 Pro 64位进行开发

我遇到了关于添加日志记录语句的这个帖子: 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"

1 个答案:

答案 0 :(得分:0)

事实证明,我忘了删除较新文件夹中目标路径中的子文件夹引用。它绝对是一个" duh"时刻。目标文件夹是1个文件夹太长,这就是为什么没有被复制的原因。

感谢您的帮助!