Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to verify whether the share has write access?

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.

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

I have tried with Get-ACL cmdlet.

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

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

like image 719
Samselvaprabu Avatar asked Oct 11 '25 17:10

Samselvaprabu


1 Answers

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'

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