├── .github └── ISSUE_TEMPLATE │ └── feature_request.md ├── ActiveDirectory.ps1 ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md └── SECURITY.md /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /ActiveDirectory.ps1: -------------------------------------------------------------------------------- 1 | # Definir codificação UTF-8 para entrada e saída 2 | [Console]::InputEncoding = [System.Text.Encoding]::UTF8 3 | [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 4 | 5 | # Script de gerenciamento do Active Directory 6 | Import-Module ActiveDirectory 7 | 8 | # Configuração do domínio 9 | 10 | $domain = "" # Dominio do local 11 | $baseDN = "" # Domínio base para construção dos caminhos 12 | 13 | # Verifica se o script já está rodando como administrador 14 | if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { 15 | Write-Host "Este script requer privilégios de administrador. Solicitando elevação..." -ForegroundColor Yellow 16 | Start-Process powershell.exe -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" -WindowStyle Normal" 17 | Exit 18 | } 19 | 20 | # Função para aplicar customizações ao console 21 | function Set-ConsoleCustomization { 22 | $Host.UI.RawUI.ForegroundColor = "White" 23 | $Host.UI.RawUI.BackgroundColor = "Black" 24 | Clear-Host 25 | } 26 | 27 | # Aplica as customizações ao iniciar 28 | Set-ConsoleCustomization 29 | 30 | function Show-Menu { 31 | Clear-Host 32 | Write-Host "==============================================" -ForegroundColor Cyan 33 | Write-Host " MENU DE GERENCIAMENTO AD " -ForegroundColor Yellow 34 | Write-Host "==============================================" -ForegroundColor Cyan 35 | Write-Host " Domínio: $domain" -ForegroundColor Green 36 | Write-Host "--------------------------------------------------------------" 37 | Write-Host "1 - Criar usuário no AD" -ForegroundColor White 38 | Write-Host "2 - Inativar usuário no AD" -ForegroundColor White 39 | Write-Host "3 - Reativar usuário no AD" -ForegroundColor White 40 | Write-Host "4 - Deletar usuário" -ForegroundColor White 41 | Write-Host "5 - Resetar a senha" -ForegroundColor White 42 | Write-Host "6 - Desbloquear usuário" -ForegroundColor White 43 | Write-Host "7 - Associar computador no AD" -ForegroundColor White 44 | Write-Host "8 - Desassociar computador" -ForegroundColor White 45 | Write-Host "9 - Deletar computador" -ForegroundColor White 46 | Write-Host "10 - Alterar ramal" -ForegroundColor White 47 | Write-Host "11 - Sincronizar AD" -ForegroundColor White 48 | Write-Host "12 - Listar usuários" -ForegroundColor White 49 | Write-Host "13 - Listar computadores" -ForegroundColor White 50 | Write-Host "14 - Mover objeto para outra OU" -ForegroundColor White 51 | Write-Host "15 - Adicionar usuário a um grupo" -ForegroundColor White 52 | Write-Host "16 - Remover usuário de um grupo" -ForegroundColor White 53 | Write-Host "17 - Verificar membros de um grupo" -ForegroundColor White 54 | Write-Host "18 - Alterar atributos de um usuário" -ForegroundColor White 55 | Write-Host "19 - Exportar relatório de usuários" -ForegroundColor White 56 | Write-Host "20 - Exportar relatório de computadores" -ForegroundColor White 57 | Write-Host "21 - Exportar relatório de grupos" -ForegroundColor White 58 | Write-Host "0 - Sair do script" -ForegroundColor Red 59 | Write-Host "==============================================" -ForegroundColor Cyan 60 | } 61 | 62 | function Get-FullOUPath { 63 | param ( 64 | [string]$baseOUChoice, 65 | [string]$subOUName 66 | ) 67 | switch ($baseOUChoice) { 68 | "1" { # Departamentos 69 | return "OU=$subOUName,OU=Departamentos,$baseDN" 70 | } 71 | "2" { # Consultoria 72 | return "OU=$subOUName,OU=Consultoria,$baseDN" 73 | } 74 | "3" { # Filiais 75 | return "OU=Usuarios,OU=$subOUName,OU=Filiais,$baseDN" 76 | } 77 | "4" { # Usuários de Serviços de TI 78 | return "OU=$subOUName,OU=Usuarios de Serviços de TI,$baseDN" 79 | } 80 | default { 81 | Write-Host "Opção de OU base inválida." -ForegroundColor Red 82 | return $null 83 | } 84 | } 85 | } 86 | 87 | function Create-User { 88 | $firstName = Read-Host "Digite o primeiro nome do usuário: " 89 | $lastName = Read-Host "Digite o sobrenome do usuário: " 90 | $matricula = Read-Host "Digite a matrícula Vilma: " 91 | $centroCusto = Read-Host "Digite o centro de custo: " 92 | $cargo = Read-Host "Digite o cargo na Vilma: " 93 | $ramal = Read-Host "Digite o ramal: " 94 | $email = Read-Host "Digite o e-mail Vilma: " 95 | $username = Read-Host "Digite o nome de usuário (login): " 96 | $password = Read-Host "Digite a senha: " -AsSecureString 97 | $description = Read-Host "Digite a descrição (cargo do colaborador): " 98 | 99 | # Escolha da OU base 100 | Write-Host "Escolha a OU base para o usuário:" -ForegroundColor Cyan 101 | Write-Host "1 - Departamentos" -ForegroundColor White 102 | Write-Host "2 - Consultoria" -ForegroundColor White 103 | Write-Host "3 - Filiais" -ForegroundColor White 104 | Write-Host "4 - Usuários de Serviços de TI" -ForegroundColor White 105 | $baseOUChoice = Read-Host "Digite o número correspondente: " 106 | 107 | # Solicitar a sub-OU com base na escolha 108 | if ($baseOUChoice -eq "1") { 109 | $subOUName = Read-Host "Digite o setor (ex: T.I, RH, Financeiro): " 110 | } elseif ($baseOUChoice -eq "2") { 111 | $subOUName = Read-Host "Digite o nome da empresa (ex: EmpresaX, EmpresaY): " 112 | } elseif ($baseOUChoice -eq "3") { 113 | $subOUName = Read-Host "Digite o nome da filial (ex: Bahia, Betim, Cambé): " 114 | } elseif ($baseOUChoice -eq "4") { 115 | $subOUName = Read-Host "Digite o nome da sub-OU (ex: BI, Conceito, SAP, RM): " 116 | } else { 117 | Write-Host "Opção inválida. Usuário não será criado." -ForegroundColor Red 118 | return 119 | } 120 | 121 | # Obter o caminho completo da OU 122 | $ouPath = Get-FullOUPath -baseOUChoice $baseOUChoice -subOUName $subOUName 123 | 124 | if ($ouPath) { 125 | try { 126 | New-ADUser -Name "$firstName $lastName" ` 127 | -DisplayName "$firstName $lastName" ` 128 | -GivenName $firstName ` 129 | -Surname $lastName ` 130 | -Initials $matricula ` 131 | -Office $centroCusto ` 132 | -Title $cargo ` 133 | -Description $description ` 134 | -Company "DOCI" ` 135 | -OfficePhone $ramal ` 136 | -EmailAddress $email ` 137 | -SamAccountName $username ` 138 | -UserPrincipalName "$username@$domain" ` 139 | -AccountPassword $password ` 140 | -Enabled $true ` 141 | -Path $ouPath ` 142 | -ErrorAction Stop 143 | Write-Host "Usuário $username criado com sucesso em $ouPath." -ForegroundColor Green 144 | } catch { 145 | Write-Host "Erro ao criar usuário: $_" -ForegroundColor Red 146 | } 147 | } 148 | } 149 | 150 | function Disable-User { 151 | $username = Read-Host "Digite o nome do usuário para inativar: " 152 | try { 153 | Disable-ADAccount -Identity $username -ErrorAction Stop 154 | Write-Host "Usuário $username inativado com sucesso." -ForegroundColor Green 155 | } catch { 156 | Write-Host "Erro ao inativar usuário: $_" -ForegroundColor Red 157 | } 158 | } 159 | 160 | function Enable-User { 161 | $username = Read-Host "Digite o nome do usuário para reativar: " 162 | try { 163 | Enable-ADAccount -Identity $username -ErrorAction Stop 164 | Write-Host "Usuário $username reativado com sucesso." -ForegroundColor Green 165 | } catch { 166 | Write-Host "Erro ao reativar usuário: $_" -ForegroundColor Red 167 | } 168 | } 169 | 170 | function Remove-User { 171 | $username = Read-Host "Digite o nome do usuário para deletar: " 172 | try { 173 | Remove-ADUser -Identity $username -Confirm:$false -ErrorAction Stop 174 | Write-Host "Usuário $username deletado com sucesso." -ForegroundColor Green 175 | } catch { 176 | Write-Host "Erro ao deletar usuário: $_" -ForegroundColor Red 177 | } 178 | } 179 | 180 | function Reset-Password { 181 | $username = Read-Host "Digite o nome do usuário para resetar a senha: " 182 | $newPassword = Read-Host "Digite a nova senha: " -AsSecureString 183 | try { 184 | Set-ADAccountPassword -Identity $username -NewPassword $newPassword -Reset -ErrorAction Stop 185 | Write-Host "Senha do usuário $username resetada com sucesso." -ForegroundColor Green 186 | } catch { 187 | Write-Host "Erro ao resetar senha: $_" -ForegroundColor Red 188 | } 189 | } 190 | 191 | function Unlock-User { 192 | $username = Read-Host "Digite o nome do usuário para desbloquear: " 193 | try { 194 | Unlock-ADAccount -Identity $username -ErrorAction Stop 195 | Write-Host "Usuário $username desbloqueado com sucesso." -ForegroundColor Green 196 | } catch { 197 | Write-Host "Erro ao desbloquear usuário: $_" -ForegroundColor Red 198 | } 199 | } 200 | 201 | function Add-Computer { 202 | $computername = Read-Host "Digite o nome do computador: " 203 | Write-Host "Escolha a OU base para o computador:" -ForegroundColor Cyan 204 | Write-Host "1 - Departamentos" -ForegroundColor White 205 | Write-Host "2 - Consultoria" -ForegroundColor White 206 | Write-Host "3 - Filiais" -ForegroundColor White 207 | Write-Host "4 - Usuários de Serviços de TI" -ForegroundColor White 208 | $baseOUChoice = Read-Host "Digite o número correspondente: " 209 | 210 | if ($baseOUChoice -eq "1") { 211 | $subOUName = Read-Host "Digite o setor (ex: T.I, RH, Financeiro): " 212 | } elseif ($baseOUChoice -eq "2") { 213 | $subOUName = Read-Host "Digite o nome da empresa (ex: EmpresaX, EmpresaY): " 214 | } elseif ($baseOUChoice -eq "3") { 215 | $subOUName = Read-Host "Digite o nome da filial (ex: Bahia, Betim, Cambé): " 216 | } elseif ($baseOUChoice -eq "4") { 217 | $subOUName = Read-Host "Digite o nome da sub-OU (ex: BI, Conceito, SAP, RM): " 218 | } else { 219 | Write-Host "Opção inválida. Computador não será associado." -ForegroundColor Red 220 | return 221 | } 222 | 223 | $ouPath = Get-FullOUPath -baseOUChoice $baseOUChoice -subOUName $subOUName 224 | 225 | if ($ouPath) { 226 | try { 227 | New-ADComputer -Name $computername -Path $ouPath -ErrorAction Stop 228 | Write-Host "Computador $computername associado com sucesso em $ouPath." -ForegroundColor Green 229 | } catch { 230 | Write-Host "Erro ao associar computador: $_" -ForegroundColor Red 231 | } 232 | } 233 | } 234 | 235 | function Remove-Computer { 236 | $computername = Read-Host "Digite o nome do computador para desassociar: " 237 | try { 238 | Remove-ADComputer -Identity $computername -Confirm:$false -ErrorAction Stop 239 | Write-Host "Computador $computername desassociado com sucesso." -ForegroundColor Green 240 | } catch { 241 | Write-Host "Erro ao desassociar computador: $_" -ForegroundColor Red 242 | } 243 | } 244 | 245 | function Delete-Computer { 246 | $computername = Read-Host "Digite o nome do computador para deletar: " 247 | try { 248 | Remove-ADComputer -Identity $computername -Confirm:$false -ErrorAction Stop 249 | Write-Host "Computador $computername deletado com sucesso." -ForegroundColor Green 250 | } catch { 251 | Write-Host "Erro ao deletar computador: $_" -ForegroundColor Red 252 | } 253 | } 254 | 255 | function Change-Extension { 256 | $username = Read-Host "Digite o nome do usuário: " 257 | $extension = Read-Host "Digite o novo ramal: " 258 | try { 259 | Set-ADUser -Identity $username -OfficePhone $extension -ErrorAction Stop 260 | Write-Host "Ramal do usuário $username alterado para $extension." -ForegroundColor Green 261 | } catch { 262 | Write-Host "Erro ao alterar ramal: $_" -ForegroundColor Red 263 | } 264 | } 265 | 266 | function Sync-AD { 267 | param ( 268 | [string]$ComputerName = "SRVAD01" 269 | ) 270 | $credential = Get-Credential -Message "Digite suas credenciais para sincronizar o AD (ex: dominio\usuario)" 271 | Write-Host "Sincronizando AD..." -ForegroundColor Yellow 272 | try { 273 | Invoke-Command -ComputerName $ComputerName -Credential $credential -ScriptBlock { 274 | Import-Module ADSync -ErrorAction Stop 275 | Start-ADSyncSyncCycle -PolicyType Delta -ErrorAction Stop 276 | } -ErrorAction Stop 277 | Write-Host "Sincronização concluída." -ForegroundColor Green 278 | } catch { 279 | Write-Host "Erro ao sincronizar AD: $_" -ForegroundColor Red 280 | } 281 | } 282 | 283 | function List-Users { 284 | Write-Host "Escolha a OU base para listar usuários:" -ForegroundColor Cyan 285 | Write-Host "1 - Departamentos" -ForegroundColor White 286 | Write-Host "2 - Consultoria" -ForegroundColor White 287 | Write-Host "3 - Filiais" -ForegroundColor White 288 | Write-Host "4 - Usuários de Serviços de TI" -ForegroundColor White 289 | $baseOUChoice = Read-Host "Digite o número correspondente: " 290 | 291 | if ($baseOUChoice -eq "1") { 292 | $subOUName = Read-Host "Digite o setor (ex: T.I, RH, Financeiro): " 293 | } elseif ($baseOUChoice -eq "2") { 294 | $subOUName = Read-Host "Digite o nome da empresa (ex: EmpresaX, EmpresaY): " 295 | } elseif ($baseOUChoice -eq "3") { 296 | $subOUName = Read-Host "Digite o nome da filial (ex: Bahia, Betim, Cambé): " 297 | } elseif ($baseOUChoice -eq "4") { 298 | $subOUName = Read-Host "Digite o nome da sub-OU (ex: BI, Conceito, SAP, RM): " 299 | } else { 300 | Write-Host "Opção inválida." -ForegroundColor Red 301 | return 302 | } 303 | 304 | $ouPath = Get-FullOUPath -baseOUChoice $baseOUChoice -subOUName $subOUName 305 | 306 | if ($ouPath) { 307 | try { 308 | Get-ADUser -Filter * -SearchBase $ouPath -ErrorAction Stop | Select-Object Name, SamAccountName, Enabled | Format-Table -AutoSize 309 | } catch { 310 | Write-Host "Erro ao listar usuários: $_" -ForegroundColor Red 311 | } 312 | } 313 | } 314 | 315 | function List-Computers { 316 | Write-Host "Escolha a OU base para listar computadores:" -ForegroundColor Cyan 317 | Write-Host "1 - Departamentos" -ForegroundColor White 318 | Write-Host "2 - Consultoria" -ForegroundColor White 319 | Write-Host "3 - Filiais" -ForegroundColor White 320 | Write-Host "4 - Usuários de Serviços de TI" -ForegroundColor White 321 | $baseOUChoice = Read-Host "Digite o número correspondente: " 322 | 323 | if ($baseOUChoice -eq "1") { 324 | $subOUName = Read-Host "Digite o setor (ex: T.I, RH, Financeiro): " 325 | } elseif ($baseOUChoice -eq "2") { 326 | $subOUName = Read-Host "Digite o nome da empresa (ex: EmpresaX, EmpresaY): " 327 | } elseif ($baseOUChoice -eq "3") { 328 | $subOUName = Read-Host "Digite o nome da filial (ex: Bahia, Betim, Cambé): " 329 | } elseif ($baseOUChoice -eq "4") { 330 | $subOUName = Read-Host "Digite o nome da sub-OU (ex: BI, Conceito, SAP, RM): " 331 | } else { 332 | Write-Host "Opção inválida." -ForegroundColor Red 333 | return 334 | } 335 | 336 | $ouPath = Get-FullOUPath -baseOUChoice $baseOUChoice -subOUName $subOUName 337 | 338 | if ($ouPath) { 339 | try { 340 | Get-ADComputer -Filter * -SearchBase $ouPath -ErrorAction Stop | Select-Object Name, Enabled | Format-Table -AutoSize 341 | } catch { 342 | Write-Host "Erro ao listar computadores: $_" -ForegroundColor Red 343 | } 344 | } 345 | } 346 | 347 | function Move-Object { 348 | $object = Read-Host "Digite o nome do usuário ou computador: " 349 | Write-Host "Escolha a OU base de destino:" -ForegroundColor Cyan 350 | Write-Host "1 - Departamentos" -ForegroundColor White 351 | Write-Host "2 - Consultoria" -ForegroundColor White 352 | Write-Host "3 - Filiais" -ForegroundColor White 353 | Write-Host "4 - Usuários de Serviços de TI" -ForegroundColor White 354 | $baseOUChoice = Read-Host "Digite o número correspondente: " 355 | 356 | if ($baseOUChoice -eq "1") { 357 | $subOUName = Read-Host "Digite o setor (ex: T.I, RH, Financeiro): " 358 | } elseif ($baseOUChoice -eq "2") { 359 | $subOUName = Read-Host "Digite o nome da empresa (ex: EmpresaX, EmpresaY): " 360 | } elseif ($baseOUChoice -eq "3") { 361 | $subOUName = Read-Host "Digite o nome da filial (ex: Bahia, Betim, Cambé): " 362 | } elseif ($baseOUChoice -eq "4") { 363 | $subOUName = Read-Host "Digite o nome da sub-OU (ex: BI, Conceito, SAP, RM): " 364 | } else { 365 | Write-Host "Opção inválida." -ForegroundColor Red 366 | return 367 | } 368 | 369 | $newOU = Get-FullOUPath -baseOUChoice $baseOUChoice -subOUName $subOUName 370 | 371 | if ($newOU) { 372 | try { 373 | Get-ADObject -Filter { Name -eq $object } -ErrorAction Stop | Move-ADObject -TargetPath $newOU -ErrorAction Stop 374 | Write-Host "Objeto $object movido para $newOU com sucesso." -ForegroundColor Green 375 | } catch { 376 | Write-Host "Erro ao mover objeto: $_" -ForegroundColor Red 377 | } 378 | } 379 | } 380 | 381 | function Add-UserToGroup { 382 | $username = Read-Host "Digite o nome do usuário: " 383 | $group = Read-Host "Digite o nome do grupo: " 384 | try { 385 | $user = Get-ADUser -Identity $username -ErrorAction Stop 386 | $groupObj = Get-ADGroup -Identity $group -ErrorAction Stop 387 | Add-ADGroupMember -Identity $group -Members $username -ErrorAction Stop 388 | Write-Host "Usuário $username adicionado ao grupo $group com sucesso." -ForegroundColor Green 389 | } catch { 390 | Write-Host "Erro ao adicionar usuário ao grupo: $_" -ForegroundColor Red 391 | } 392 | } 393 | 394 | function Remove-UserFromGroup { 395 | $username = Read-Host "Digite o nome do usuário: " 396 | $group = Read-Host "Digite o nome do grupo: " 397 | try { 398 | Remove-ADGroupMember -Identity $group -Members $username -Confirm:$false -ErrorAction Stop 399 | Write-Host "Usuário $username removido do grupo $group com sucesso." -ForegroundColor Green 400 | } catch { 401 | Write-Host "Erro ao remover usuário do grupo: $_" -ForegroundColor Red 402 | } 403 | } 404 | 405 | function Get-GroupMembers { 406 | $group = Read-Host "Digite o nome do grupo: " 407 | try { 408 | Get-ADGroupMember -Identity $group -ErrorAction Stop | Select-Object Name, SamAccountName | Format-Table -AutoSize 409 | } catch { 410 | Write-Host "Erro ao listar membros do grupo: $_" -ForegroundColor Red 411 | } 412 | } 413 | 414 | function Set-UserAttributes { 415 | $username = Read-Host "Digite o nome do usuário: " 416 | $attribute = Read-Host "Digite o atributo a ser alterado (ex: Title, Department): " 417 | $value = Read-Host "Digite o novo valor: " 418 | try { 419 | Set-ADUser -Identity $username -Replace @{ $attribute = $value } -ErrorAction Stop 420 | Write-Host "Atributo $attribute do usuário $username alterado para $value com sucesso." -ForegroundColor Green 421 | } catch { 422 | Write-Host "Erro ao alterar atributo: $_" -ForegroundColor Red 423 | } 424 | } 425 | 426 | function Export-UserReport { 427 | Write-Host "Escolha a OU base para exportar usuários:" -ForegroundColor Cyan 428 | Write-Host "1 - Departamentos" -ForegroundColor White 429 | Write-Host "2 - Consultoria" -ForegroundColor White 430 | Write-Host "3 - Filiais" -ForegroundColor White 431 | Write-Host "4 - Usuários de Serviços de TI" -ForegroundColor White 432 | $baseOUChoice = Read-Host "Digite o número correspondente: " 433 | 434 | if ($baseOUChoice -eq "1") { 435 | $subOUName = Read-Host "Digite o setor (ex: T.I, RH, Financeiro): " 436 | } elseif ($baseOUChoice -eq "2") { 437 | $subOUName = Read-Host "Digite o nome da empresa (ex: EmpresaX, EmpresaY): " 438 | } elseif ($baseOUChoice -eq "3") { 439 | $subOUName = Read-Host "Digite o nome da filial (ex: Bahia, Betim, Cambé): " 440 | } elseif ($baseOUChoice -eq "4") { 441 | $subOUName = Read-Host "Digite o nome da sub-OU (ex: BI, Conceito, SAP, RM): " 442 | } else { 443 | Write-Host "Opção inválida." -ForegroundColor Red 444 | return 445 | } 446 | 447 | $ouPath = Get-FullOUPath -baseOUChoice $baseOUChoice -subOUName $subOUName 448 | $outputFile = Read-Host "Digite o nome do arquivo de saída (ex: usuários.csv): " 449 | 450 | if ($ouPath) { 451 | try { 452 | Get-ADUser -Filter * -SearchBase $ouPath -ErrorAction Stop | Select-Object Name, SamAccountName, Enabled | Export-Csv -Path $outputFile -NoTypeInformation -ErrorAction Stop 453 | Write-Host "Relatório de usuários exportado para $outputFile com sucesso." -ForegroundColor Green 454 | } catch { 455 | Write-Host "Erro ao exportar relatório: $_" -ForegroundColor Red 456 | } 457 | } 458 | } 459 | 460 | function Export-ComputerReport { 461 | Write-Host "Escolha a OU base para exportar computadores:" -ForegroundColor Cyan 462 | Write-Host "1 - Departamentos" -ForegroundColor White 463 | Write-Host "2 - Consultoria" -ForegroundColor White 464 | Write-Host "3 - Filiais" -ForegroundColor White 465 | Write-Host "4 - Usuários de Serviços de TI" -ForegroundColor White 466 | $baseOUChoice = Read-Host "Digite o número correspondente: " 467 | 468 | if ($baseOUChoice -eq "1") { 469 | $subOUName = Read-Host "Digite o setor (ex: T.I, RH, Financeiro): " 470 | } elseif ($baseOUChoice -eq "2") { 471 | $subOUName = Read-Host "Digite o nome da empresa (ex: EmpresaX, EmpresaY): " 472 | } elseif ($baseOUChoice -eq "3") { 473 | $subOUName = Read-Host "Digite o nome da filial (ex: Bahia, Betim, Cambé): " 474 | } elseif ($baseOUChoice -eq "4") { 475 | $subOUName = Read-Host "Digite o nome da sub-OU (ex: BI, Conceito, SAP, RM): " 476 | } else { 477 | Write-Host "Opção inválida." -ForegroundColor Red 478 | return 479 | } 480 | 481 | $ouPath = Get-FullOUPath -baseOUChoice $baseOUChoice -subOUName $subOUName 482 | $outputFile = Read-Host "Digite o nome do arquivo de saída (ex: computadores.csv): " 483 | 484 | if ($ouPath) { 485 | try { 486 | Get-ADComputer -Filter * -SearchBase $ouPath -ErrorAction Stop | Select-Object Name, Enabled, LastLogonDate | Export-Csv -Path $outputFile -NoTypeInformation -ErrorAction Stop 487 | Write-Host "Relatório de computadores exportado para $outputFile com sucesso." -ForegroundColor Green 488 | } catch { 489 | Write-Host "Erro ao exportar relatório: $_" -ForegroundColor Red 490 | } 491 | } 492 | } 493 | 494 | function Export-GroupReport { 495 | $setor = Read-Host "Digite o setor (ex: T.I, RH, Financeiro): " 496 | $ouPath = "OU=Grupos,OU=$setor,OU=Departamentos,$baseDN" 497 | $outputFile = Read-Host "Digite o nome do arquivo de saída (ex: grupos.csv): " 498 | try { 499 | Get-ADGroup -Filter * -SearchBase $ouPath -ErrorAction Stop | 500 | Select-Object Name, SamAccountName, GroupCategory, GroupScope | 501 | Export-Csv -Path $outputFile -NoTypeInformation -ErrorAction Stop 502 | Write-Host "Relatório de grupos exportado para $outputFile com sucesso." -ForegroundColor Green 503 | } catch { 504 | Write-Host "Erro ao exportar relatório de grupos: $_" -ForegroundColor Red 505 | } 506 | } 507 | 508 | # Loop do menu 509 | do { 510 | Show-Menu 511 | $input = Read-Host "Digite o número correspondente à opção desejada: " 512 | switch ($input) { 513 | '1' { Create-User } 514 | '2' { Disable-User } 515 | '3' { Enable-User } 516 | '4' { Remove-User } 517 | '5' { Reset-Password } 518 | '6' { Unlock-User } 519 | '7' { Add-Computer } 520 | '8' { Remove-Computer } 521 | '9' { Delete-Computer } 522 | '10' { Change-Extension } 523 | '11' { Sync-AD } 524 | '12' { List-Users } 525 | '13' { List-Computers } 526 | '14' { Move-Object } 527 | '15' { Add-UserToGroup } 528 | '16' { Remove-UserFromGroup } 529 | '17' { Get-GroupMembers } 530 | '18' { Set-UserAttributes } 531 | '19' { Export-UserReport } 532 | '20' { Export-ComputerReport } 533 | '21' { Export-GroupReport } 534 | '0' { Write-Host "Saindo do script..." -ForegroundColor Red } 535 | default { Write-Host "Opção inválida, tente novamente." -ForegroundColor Red } 536 | } 537 | if ($input -ne '0') { 538 | Write-Host "Pressione Enter para continuar..." -ForegroundColor Gray 539 | $null = Read-Host 540 | } 541 | } until ($input -eq '0') 542 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | . 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Caso queiram contribuir 2 | 3 | pix vocurca@pm.me 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Gerenciamento de Active Directory com PowerShell 2 | 3 | Automatize e simplifique a administração do Active Directory. Crie usuários, gerencie permissões, resete senhas e sincronize alterações em tempo real com eficiência e precisão. 4 | 5 | ### Por que usar? 6 | - **Automatização**: Elimine tarefas repetitivas e ganhe tempo. 7 | - **Precisão**: Reduza erros com processos consistentes. 8 | - **Eficiência**: Execute ações complexas em segundos. 9 | - **Centralização**: Controle usuários e dispositivos em um só lugar. 10 | - **Escalabilidade**: Adapte-se a redes de qualquer tamanho. 11 | 12 | --- 13 | 14 | ## Funcionalidades 15 | 16 | - Criação de usuários em massa (CSV/TXT) 17 | - Ativação/inativação de contas 18 | - Reset e desbloqueio de senhas 19 | - Associação de computadores ao domínio 20 | - Movimentação de objetos entre OUs 21 | - Relatórios em CSV 22 | - Gerenciamento de grupos 23 | - Sincronização do AD 24 | 25 | --- 26 | 27 | ## Como Usar 28 | 29 | ### Pré-requisitos 30 | - PowerShell 5.1+ 31 | - Módulo ActiveDirectory: 32 | ```powershell 33 | Install-WindowsFeature -Name RSAT-AD-PowerShell 34 | ``` 35 | 36 | ### Instalação 37 | 1. Clone o repositório: 38 | ```bash 39 | git clone https://github.com/danielfrade/ad 40 | ``` 41 | 2. Execute como administrador: 42 | ```powershell 43 | .\ActiveDirectory.ps1 44 | ``` 45 | 3. Use o menu interativo para navegar. 46 | 47 | --- 48 | 49 | ## Estrutura 50 | - `ActiveDirectory.ps1`: Script principal 51 | - `README.md`: Documentação 52 | 53 | --- 54 | 55 | ## Exemplos 56 | - **Criar usuário**: Selecione a opção e insira os dados. 57 | - **Inativar conta**: Escolha a opção e informe o usuário. 58 | 59 | --- 60 | 61 | ## Contribuições 62 | Quer ajudar? Faça um fork, crie uma branch (`git checkout -b feature/nova-ideia`), commit suas mudanças e envie um Pull Request! 63 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | Use this section to tell people about which versions of your project are 6 | currently being supported with security updates. 7 | 8 | | Version | Supported | 9 | | ------- | ------------------ | 10 | | 5.1.x | :white_check_mark: | 11 | | 5.0.x | :x: | 12 | | 4.0.x | :white_check_mark: | 13 | | < 4.0 | :x: | 14 | 15 | ## Reporting a Vulnerability 16 | 17 | Use this section to tell people how to report a vulnerability. 18 | 19 | Tell them where to go, how often they can expect to get an update on a 20 | reported vulnerability, what to expect if the vulnerability is accepted or 21 | declined, etc. 22 | --------------------------------------------------------------------------------