【问题标题】:Cannot validate argument on parameter 'Encoding' PowerShell无法验证参数“编码”PowerShell 上的参数
【发布时间】: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


【解决方案1】:
//Set the variables
$WebURL = “http://sharepoint:20000/ubt/it/”
$DocLibName = “Documents”
$FilePath = “c:\temp\users_PermisionReport2.txt”

//Get a variable that points to the folder
$Web = Get-SPWeb $WebURL
$List = $Web.GetFolder($DocLibName)
$Files = $List.Files

//Get just the name of the file from the whole path
$FileName = $FilePath.Substring($FilePath.LastIndexOf("\")+1)

//Load the file into a variable
$File= Get-ChildItem $FilePath

//Upload it to SharePoint
$Files.Add($DocLibName +"/" + $FileName,$File.OpenRead(),$false)
$web.Dispose()

我使用了这个脚本,它现在正在工作。但是,另一个仍然不知道为什么它不工作,但这个做同样的工作。

【讨论】:

    猜你喜欢
    • 2021-01-16
    • 1970-01-01
    • 1970-01-01
    • 2023-02-23
    • 2019-06-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-25
    • 2012-08-31
    相关资源
    最近更新 更多