在powershell中,我被New-Object IO.FileStream拒绝了访问权限,但我可以访问

发布于 2025-01-24 11:45:03 字数 849 浏览 1 评论 0原文

我尝试将文件附加到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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱冒险 2025-01-31 11:45:03

谢谢约瑟夫斯,
添加[System.io.fileAccess] ::读取在命令中是成功的。由于我只对共享进行了阅读,因此必须在只读模式下打开文件。

代码必须如下:

$Path = "\\server\share\folder\file.jpg"
$File = New-Object IO.FileStream($Path,[System.IO.FileMode]::Open,[System.IO.FileAccess]::Read)

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:

$Path = "\\server\share\folder\file.jpg"
$File = New-Object IO.FileStream($Path,[System.IO.FileMode]::Open,[System.IO.FileAccess]::Read)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文