【发布时间】:2018-11-17 02:49:50
【问题描述】:
您好,我正在使用此脚本将文件上传到共享点上的库,但我收到此错误,感谢您的帮助。
$Output = "c:\temp\users_PermisionReport.txt"
$WebURL = "http://url"
$ListName = "Documents"
//Create something to upload, in this case a list of all sites
Get-SPSite | Out-File -FilePath "url" $Output
//Upload the results to SharePoint
$File = Get-Item $Output
$Stream = $File.OpenRead()
$Web = Get-SPWeb $WebURL
$List = $Web.Lists["$ListName"]
$FileCollection = $List.RootFolder.Files
$FileCollection.Add($File.Name,$Stream,$true)
$Stream.Close()
$File.Delete()
这是错误:
Out-File : Cannot validate argument on parameter 'Encoding'. The argument
"c:\temp\users_PermisionReport.txt" does not
belong to the set
"unknown,string,unicode,bigendianunicode,utf8,utf7,utf32,ascii,default,oem"
specified by the
ValidateSet attribute. Supply an argument that is in the set and then try
the command again.
At C:\Users\balaji.chode\Desktop\UpDoc.ps1:6 char:59
+ Get-SPSite | Out-File -FilePath "url" $Output
+ ~~~~~~~
+ CategoryInfo : InvalidData: (:) [Out-File],
ParameterBindingValidationException
+ FullyQualifiedErrorId :
ParameterArgumentValidationError,Microsoft.PowerShell.Commands.OutFileCommand
我正在使用共享点服务器管理外壳。谢谢
【问题讨论】:
-
您是手工编写帖子中的代码还是从实际脚本中复制粘贴?很可能有一些不可见或扩展的 unicode 字符,PowerShell 不会将其视为空格,因此认为应作为参数参数
-
-Encoding参数在位置 1 被识别。因此,Get-SPSite | Out-File -FilePath "url" $Output与(假设错误)Get-SPSite | Out-File -FilePath "url" -Encoding $Output相同。
标签: powershell sharepoint