-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateGroupsAttributes.ps1
More file actions
67 lines (56 loc) · 2.72 KB
/
UpdateGroupsAttributes.ps1
File metadata and controls
67 lines (56 loc) · 2.72 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
# Import active directory module for running AD cmdlets
Import-Module ActiveDirectory
# Store the data from .csv in the $File variable
$File = Import-Csv E:\Scripts\ActualizarAttibutesGroups\XXXX.csv -Delimiter ","
$ErrorPath = "E:\Scripts\ActualizarAttibutesGroups\ErrorXXXX.txt"
"Name" + ";" + "Description" + ";" + "ManageBy" + ";" + "Info" + ";" + "error" + ";" + "Fecha" | Set-Content $ErrorPath
# Loop through each row containing user details in the CSV file
foreach ($line in $File) {
Try
{
# Try to add / Descriptio, ManagedBy, Co - dueno (active roles), info (Notas, info)
try
{
Set-ADGroup -Identity ($line.Name) -Description ($line.Description) -Passthru
}
catch
{
write-host "Description is in blank, is not posible update atributo description, ($line.Description)"
$Errortry = ($line.Name + ";" + ($line.Description) + ";" + ($line.Managedby) + ";" + ($line.Info) + ";" + $_ + ";Fecha: " + (Get-Date))
Add-Content ($ErrorPath) -value ($Errortry)
}
try
{
#Check if the user exist.
if (($line.Managedby.Length) -gt 1) {
Set-ADGroup -Identity ($line.Name) -ManagedBy ($line.Managedby) -Passthru
}else {
$Errortry = ($line.Name + ";" + ($line.Description) + ";" + "Sin Manager" + ";" + ($line.Info) + ";" + "Falta Definir el Manager" + ";Fecha: " + (Get-Date))
Add-Content ($ErrorPath) -value ($Errortry)
}
}
catch
{
write-host "User is not in AD, is not posible update atributo Manageby, ($line.Managedby)"
$Errortry = ($line.Name + ";" + ($line.Description) + ";" + ($line.Managedby) + ";" + ($line.Info) + ";" + $_ + ";Fecha: " + (Get-Date))
Add-Content ($ErrorPath) -value ($Errortry)
}
try
{
Set-ADGroup -Identity ($line.Name) -Replace @{info=($line.Info)} -Passthru
}
catch
{
write-host "info is in blank, is not posible update atributo info, ($line.Info)"
$Errortry = ($line.Name + ";" + ($line.Description) + ";" + ($line.Managedby) + ";" + ($line.Info) + ";" + $_ + ";Fecha: " + (Get-Date))
Add-Content ($ErrorPath) -value ($Errortry)
}
}
Catch
{
# Catch any error
Write-Host "Group updated failed, ($line.Name)"
$Errortry = ($line.Name + ";" + ($line.Description) + ";" + ($line.Managedby) + ";" + ($line.Info) + ";" + $_ + ";Fecha: " + (Get-Date))
Add-Content ($ErrorPath) -value ($Errortry)
}
}