首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法验证参数“编码”PowerShell上的参数参数

无法验证参数“编码”PowerShell上的参数参数
EN

Stack Overflow用户
提问于 2018-11-15 16:37:14
回答 1查看 2.8K关注 0票数 0

嗨,我正在使用这个脚本上传一个文件到共享点上的库,但是我得到了这个错误,任何帮助都是非常感谢的。

代码语言:javascript
运行
复制
 $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()

这是一个错误:

代码语言:javascript
运行
复制
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

我正在使用共享点服务器管理shell。谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-16 14:52:37

代码语言:javascript
运行
复制
//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()

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53324020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档