如何验证共享是否具有写权限? [英] How to verify whether the share has write access?

查看:56
本文介绍了如何验证共享是否具有写权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在共享写入权限.我正在编写一个 powershell 脚本来在该共享中写入日志文件.

I am having share with write access. I am writing a powershell script to write a log file in that share.

我想在写入之前检查我是否对该共享具有写访问权限.

I would like to check the condition whether i am having write access to this share before writing in it.

如何使用powershell检查写访问/完全控制?

How to check for write access/Full control using powershell?

我尝试过使用 Get-ACL cmdlet.

I have tried with Get-ACL cmdlet.

 $Sharing= GEt-ACL "\\Myshare\foldername
    If ($Sharing.IsReadOnly) { "REadonly access" , you can't write" }

它有 Isreadonly 属性,但是有没有办法确保用户具有 Fullcontrol 访问权限?

It has Isreadonly property, But is there any way to ensure that the user has Fullcontrol access?

推荐答案

这与 @Christian 的 C# 的作用相同,只是不编译 C#.

This does the same thing as @Christian's C# just without compiling C#.

function Test-Write {
    [CmdletBinding()]
    param (
        [parameter()] [ValidateScript({[IO.Directory]::Exists($_.FullName)})]
        [IO.DirectoryInfo] $Path
    )
    try {
        $testPath = Join-Path $Path ([IO.Path]::GetRandomFileName())
        [IO.File]::Create($testPath, 1, 'DeleteOnClose') > $null
        # Or...
        <# New-Item -Path $testPath -ItemType File -ErrorAction Stop > $null #>
        return $true
    } catch {
        return $false
    } finally {
        Remove-Item $testPath -ErrorAction SilentlyContinue
    }
}
Test-Write '\\server\share'

我想研究在 PowerShell 中实现 GetEffectiveRightsFromAcl 因为这将更好地回答这个问题......

I'd like to look into implementing GetEffectiveRightsFromAcl in PowerShell because that will better answer the question....

这篇关于如何验证共享是否具有写权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆