Windows_Server/bat & PowerShell 스크립트
Windows 파일 서버 전체 폴더에서 특정 사용자 검색하는 파워쉘 스크립트
프리윙즈
2023. 3. 29. 23:23
728x90
반응형
윈도우 파일서버에서 200TB 안에서 검색하고 싶은 사용자가 어떤 폴더에 권한을 부여받아서
사용하고 있는지 GUI에서 찾기가 제한되어 작성하게 된 파워쉘 스크립트 입니다.
사번 또는 이름을 검색하면 어떠한 폴더에 권한이 부여되어 있는지 출력되게 됩니다.
Active Directory에서 연동해서 사용하는 윈도우 파일서버에서도 정상적으로 작동됩니다.
# 검색할 사용자명 수기 입력
$userName = Read-Host "사번 또는 이름 입력"
$shares = Get-WmiObject -Class Win32_Share | Where-Object {$_.Type -eq 0}
foreach ($share in $shares) {
$shareName = $share.Name
$sharePath = $share.Path
# 공유 폴더의 ACL 가져오기
$acl = Get-Acl $sharePath
foreach ($access in $acl.Access) {
if ($access.IdentityReference -notlike "NT AUTHORITY\*" -and $access.IdentityReference.Value -eq $userName) {
# 권한이 부여된 사용자의 이름과 폴더명 출력
Write-Output "$userName 사용자는 '$shareName' 공유 폴더의 '$sharePath' 경로에 권한이 있습니다."
}
}
}
반응형