-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-DiskFromGPO.ps1
54 lines (42 loc) · 1.47 KB
/
Get-DiskFromGPO.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<#
.SYNOPSIS
Find and create bat file to map disk for user
.DESCRIPTION
Find and create bat file to map disk for user
.EXAMPLE
Get-DiskFromGPO.ps1 -jsmith
.\Get-DiskFromGPO.ps1 -user jsmith
.NOTES
autor: hajdus 2018
#>
Param(
[Parameter(Mandatory = $true)] [String]$user
)
$UserExist = Get-ADUser -LDAPFilter "(sAMAccountName=$user)"
If ($UserExist -eq $Null) {
Write-Host -ForegroundColor RED "Użytkownik nie istnieje w AD!!"
Exit
}
Else {
Write-Host -ForegroundColor GREEN "Użytkownik istnieje w AD"
[xml]$xml = Get-GPOReport -Name "USR#CONF#Mapowanie_Dyskow" -ReportType XML
$grups = Get-ADPrincipalGroupMembership $user | ? name -Match "Centrala-" | select name
$FilePath = "$env:HOMEPATH\Desktop"
#Check if output file exist
if (Test-Path "$FilePath\$user.bat" -PathType Leaf) {
Remove-Item "$FilePath\$user.bat"
}
Clear-Host
Write-Host -ForegroundColor Green "Utworzono plik bat $FilePath\$user.bat"
Write-Host -ForegroundColor Yellow "Zawartość:"
$grups | % {
$name = $_.name
$xml.GPO.User.ExtensionData.Extension.DriveMapSettings.Drive |
% { if ($_.Filters.FilterGroup.name -match $name ) {
$Tekst = "net use " + $_.name + " " + $_.Properties.path + " /persistent:yes"
$Tekst | Out-File -Append -FilePath "$FilePath\$user.bat" -Encoding ascii
$Tekst
}
}
}
}