
我的 Copy-Item PowerShell 命令產生一個錯誤,我找不到任何參考。
使用 PowerShell 4.x,我嘗試將檔案從本機磁碟機複製到遠端伺服器(同一網路/網域)。遠端路徑存在且為空。
該腳本中的以下Copy-Item
命令會在(據我所知)複製的每個文件上產生以下錯誤:
$SessionTarget = New-PSSession -ComputerName "MYSERVER1"
Copy-Item -Path "C:\Websites\XXX\*" -Destination "C:\Websites\XXX\" -ToSession $SessionTarget -Recurse
錯誤:
Copy-Item : Exception setting "Attributes": "Cannot convert value "1179648" to type "System.IO.FileAttributes" due to enumeration values that are not valid. Specify one of the following enumeration values and try again. The possible enumeration values are "ReadOnly, Hidden, System, Directory, Archive, Device, Normal, Temporary, SparseFile, ReparsePoint, Compressed, Offline, NotContentIndexed, Encrypted, IntegrityStream, NoScrubData"."
At C:\Websites\XXX_Deployment\Deploy.ps1:6 char:1
+ Copy-Item -Path "C:\Websites\XXX\*" -Destination "C:\Websites\XXX ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Copy-Item], SetValueInvocationException
+ FullyQualifiedErrorId : ExceptionWhenSetting
好消息是這些文件似乎可以複製。
關於這個錯誤的原因有什麼想法嗎?
謝謝你!
答案1
正如下面我的 Keith Miller 所指出的(謝謝!),這些值與「新」檔案屬性相關。
我找到了一個出現錯誤的文件,檢查了它的當前屬性,發現它具有“(U)”屬性:
'屬性.\MyFile.txt'
(U) 0x100000 已取消固定(OneDrive「僅限線上檔案」)
然後我刪除了此屬性並能夠使用該Copy-Item
命令而不會出現錯誤:
屬性 .\MyFile.txt -U
這篇文章列出了所有屬性及其位值:
答案2
1179648 = 0x00120000
這些對應於「較新」的屬性:
Unpinned = 0x00100000
NoScrubData = 0x00020000