Sam*_*abu 2 powershell powershell-2.0
我正在分享写访问权限.我正在编写一个powershell脚本来在该共享中编写日志文件.
我想在写入之前检查我是否具有对此共享的写访问权限的条件.
如何使用PowerShell检查写访问/完全控制?
我尝试过Get-ACL cmdlet.
$Sharing= GEt-ACL "\\Myshare\foldername
If ($Sharing.IsReadOnly) { "REadonly access" , you can't write" }
Run Code Online (Sandbox Code Playgroud)
它有Isreadonly属性,但有没有办法确保用户具有Fullcontrol访问权限?
这与@ Christian的C#完全相同,只是没有编译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'
Run Code Online (Sandbox Code Playgroud)
我想研究一下GetEffectiveRightsFromAclPowerShell中的实现,因为这样可以更好地回答这个问题....
| 归档时间: |
|
| 查看次数: |
5064 次 |
| 最近记录: |