在powershell中,我被New-Object IO.FileStream拒绝了访问权限,但我可以访问
我尝试将文件附加到SharePointlists中的ListItems。因此,我想在PowerShell中使用以下代码:
$Path = "\\server\share\folder\file.jpg"
$File = New-Object IO.FileStream($Path,[System.IO.FileMode]::Open)
收到以下错误
New-Object : Exception calling ".ctor" with "2" argument(s): "Access to the path '\\server\share\folder\file.jpg' is denied."
At line:1 char:70
+ ... US'; $var = New-Object IO.FileStream("\\server\share\folder\file.jpg ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
当我简单地键入\\ serman \ share \ folder \ file.jpg 在同一powershell中,我会 图片。我在哪里错了?还是有一些完全不同的方法?
I try to attach files to listitems in sharepointlists. Therefore I want to use the following code in the Powershell:
$Path = "\\server\share\folder\file.jpg"
$File = New-Object IO.FileStream($Path,[System.IO.FileMode]::Open)
I get the following error
New-Object : Exception calling ".ctor" with "2" argument(s): "Access to the path '\\server\share\folder\file.jpg' is denied."
At line:1 char:70
+ ... US'; $var = New-Object IO.FileStream("\\server\share\folder\file.jpg ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
When I simply type \\server\share\folder\file.jpg
in the same powershell the file will open and I see the picture. Where am I getting wrong? Or is there some completely different approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谢谢约瑟夫斯,
添加
[System.io.fileAccess] ::读取
在命令中是成功的。由于我只对共享进行了阅读,因此必须在只读模式下打开文件。代码必须如下:
Thank you JosefZ,
Adding
[System.IO.FileAccess]::Read
to the command was successfull. As I have only read-permissions to the share, the file must be opened in read-only mode.The code must be as following: