1
A
回答
1
我写这个剧本,它avalaible多AD林,与地方,UNC和DFS路径
<#
.SYNOPSIS
Teste les droits reel dans un dossier
.DESCRIPTION
Tente d'ecrire un fichier dans la destination specifiée en tant que NtAccountName
.PARAMETER Path
FQDN du dossier a tester
ex : '\\open.adds\RPannuzzo$\Pannuzzolk\Donnees\Scans'
.PARAMETER NtaccountName
Nom d'utilisateur complet
ex : 'contoso\JhonDoe'
.EXAMPLE
.\Test-RealAccess.ps1 -path 'D:\repertoire
.EXAMPLE
.\Test-RealAccess.ps1 '\\open.adds\Rshare$\Pathlk\Data' -ntAccountName 'contoso\JhonDoe'
le mdp vous sera demandé, une seule fois et sera enregistre dans la registry
.NOTES
Alopez 2016
[email protected] : alban.lopez ON gmail.com
#>
#requires -version 3
param(
[string[]]$paths = '\\Contoso.adds\Share$\Target\Data',
$ntAccountName = 'contoso\JhonDoe'
)
$version = '0.53/Test Read,Write,Supp.'
$source = "Script Test d'access reel (alopez)"
function Get-CredentialByRegistry ($ntAccountName) {
$regKey = "HKCU:\Software\Pass\$ntAccountName"
# voir le mdp
# [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR(((Get-ItemProperty $regKey -Name SecurePass).SecurePass | convertto-securestring)))
if(!(Get-ItemProperty $regKey -Name SecurePass -ea 0).SecurePass) {
# on demande et on enregistre le mdp
new-Item -Path "HKCU:\Software\Pass" -EA 0 | out-null
new-Item -Path "HKCU:\Software\Pass\$($ntAccountName.split('\')[0])" -EA 0 | out-null
new-Item -Path $regKey -EA 0 | out-null
$WinCredential = Get-Credential -UserName "$ntAccountName" -Message "Identifiant de connexion : $ntAccountName`nPour les tests de validation"
Set-ItemProperty -Path $regKey -name SecurePass -value ($WinCredential.GetNetworkCredential().securePassword | ConvertFrom-SecureString)
}
return new-object -typename System.Management.Automation.PSCredential -argumentlist @("$NtAccountName",((Get-ItemProperty $regKey -Name SecurePass -ea 0).SecurePass | convertto-securestring))
}
$ACL = @()
$ACL = foreach ($path in $paths) {
$access = $null
Remove-Item "$path\test-RW.txt","$path\test-ForRead.txt",'.\access.txt','.\error.txt' -Force -ea 0 | out-null
start-sleep -s 2
try{
'Readable' | Set-Content "$path\test-ForRead.txt" -Force -ea stop | out-null
write-host " Droits pour " -nonewline -fore blue -back White
write-host "$ntAccountName" -nonewline -fore darkgreen -back White
write-host " dans [" -nonewline -fore blue -back White
write-host "$path" -fore magenta -nonewline -back White
write-host '] : '.padright(80-$ntAccountName.length-$path.length) -nonewline -fore blue -back White
try{
(Start-Process -Wait -NoNewWindow -Credential (Get-CredentialByRegistry $ntAccountName -PassThru) "powershell.exe" -RedirectStandardOutput '.\access.txt' -RedirectStandardError '.\error.txt' `
-ArgumentList "
whoami | Set-Content '$path\test-RW.txt' -ea Continue;
start-sleep -s 1;
if ((get-content '$path\test-ForRead.txt' -ea Continue) -like 'Readable') {
'R';
};
if ((get-content '$path\test-RW.txt' -ea Continue) -like `$(whoami)) {
'W';
};
Remove-Item '$path\test-ForRead.txt' -ea Continue;
start-sleep -s 1;
if (!(Test-Path '$path\test-ForRead.txt' -ea Continue)) {
'S';
};
" `
-ea SilentlyContinue)
} catch {
# l'execution "en tant que" retourne toujours une erreur, meme si tout fonctionne
}
start-sleep -s 5;
$access = (get-content '.\access.txt') -join('')
if ($access -clike 'RWS') {
write-host "$access".padleft(10).padright(16) -fore Black -back Green
} elseif ($access.length -ge 1) {
write-host "$access".padleft(10).padright(16) -fore DarkGreen -back Yellow
} else {
write-host " [ ! ] " -fore White -back Red
}
} catch {
write-host "`n`tVous n'avez pas acces a [ " -fore White -back Red -nonewline
write-host "$path" -fore White -back magenta -nonewline
write-host " ] ! Impossible de faire le test !".padright(54) -fore White -back Red
}
[pscustomobject][ordered]@{
'path' = $path
'ntAccountName' = $ntAccountName
'Read' = ($access -clike '*R*')
'Write' = ($access -clike '*W*')
'Supp.' = ($access -clike '*S*')
'Access' = $access
}
Remove-Item "$path\test-RW.txt","$path\test-ForRead.txt" -Force -ea 0 | out-null
}
return $ACL
相关问题
- 1. 用户访问权限
- 2. 如何管理用户访问权限和用户权限
- 3. “会员”组用户的访问权限?
- 4. 访问用户凭证/权限
- 5. 管理数据访问/用户权限
- 6. ASP.NET MVC3 - 用户权限和访问
- 7. 授予用户权限来访问表
- 8. 权限访问
- 9. 访问权限
- 10. iOS Facebook SDK 3.1 openActiveSessionWithReadPermissions:检测用户未授予访问权限
- 11. 用户权限的实现
- 12. 春季测试。获取相关项目的测试类的访问权限?
- 13. 测试用户是否有权访问SharePoint中的项目
- 14. BOX API试图连接用户和访问权限授予框
- 15. 网站访问权限测试的替代方案
- 16. Phpunit权限测试
- 17. android-试图授权用户访问vk.com
- 18. 根据登录用户的访问权限限制PHP的文件访问
- 19. Drupal 7 - 登录用户的菜单用户访问权限?
- 20. powershell列表权限用户+文件夹
- 21. MySQL的测试权限
- 22. 权限访问sys.dm_db_index_usage_stats
- 23. 如何管理户外访问权限
- 24. PDP访问权限限制
- 25. 试图以访问权限的方式访问套接字
- 26. 使用Powershell审核Exchange 2007邮箱完全访问权限
- 27. Powershell:$ ^和$$的实际用法?
- 28. 设置IAM用户/角色的跨账户访问权限
- 29. 匿名用户:您无权访问此页面。权限确定
- 30. UILocalNotification询问用户权限