Script PowerShell: exportar los administradores y sus directos
by
eor
1 enero, 2021
Píldoras tecnológicas
0
<# .SYNOPSIS Name: Export-ManagersDirectsFromAAD.ps1 The purpose of this sample script is to build a list of managers and direct reports to use with the New-TeamsFromManagers.ps1 to create a team for each people manager and their directs. .DESCRIPTION This sample script create new Teams based on the tab delimited .txt file you provide of managers and direct reports. It assumes that DisplayName is not null. .NOTES © 2020 Microsoft Corporation. All rights reserved. This document is provided "as-is." Information and views expressed in this document, including URL and other Internet Web site references, may change without notice. .EXAMPLE Export-ManagersDirectsFromAAD.ps1 #>
#Also create a type that validated the users licenses to ease the create-team burden
#also add checks to see if the types are appropriately in place.
#region Configurable Inputs
$OutputFile = "ExportedManagersDirects.txt"
#endregion
#region Data Model
class DirectReport {
[string] $UserPrincipalName
}
class Manager {
[ValidateNotNullOrEmpty()] [string] $UserPrincipalName
[string] $DisplayName
[System.Collections.ObjectModel.Collection[DirectReport]]$DirectReports
Manager (){
$this.DirectReports = New-Object -TypeName System.Collections.ObjectModel.Collection["DirectReport"]
}
}
#endregion
#region Helper Functions
Function Get-TimeStamp {
return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
}
#endregion
#region Script Execution
#Step 1: Retrieve AAD users - attribute filtering off DirectReport cannot be applied
Write-Host -ForegroundColor Green "$(Get-Timestamp) Info: Starting to retrieve ALL Azure AD users."
$AllAADUsers = Get-AzureADUser -All $true -Filter "UserType eq 'Member' and AccountEnabled eq true"
Write-Host -ForegroundColor Green "$(Get-Timestamp) Info: Retriving Azure AD Users Complete.. `n"
#Step 2: Iterate through users, identify Managers and Directs
Write-Host -ForegroundColor Green "$(Get-Timestamp) Info: Starting to Retrieve Directs Reports"
$Managers = New-Object -TypeName System.Collections.ObjectModel.Collection["Manager"]
foreach ($user in $AllAADUsers) {
$directs = Get-AzureADUserDirectReport -ObjectId $user.UserPrincipalName
if ($null -ne $directs) {
if ($user.DisplayName -ne "") {
$manager = New-Object -TypeName Manager
$manager.UserPrincipalName = $user.UserPrincipalName
$manager.DisplayName = $user.DisplayName
foreach ($direct in $directs) {
$directReport = New-Object -TypeName DirectReport
$directReport.UserPrincipalName = $direct.UserPrincipalName
$manager.DirectReports.Add($directReport)
}
$Managers.Add($manager)
}
Write-Host "$(Get-Timestamp) Info: Added Manager: $($manager.UserPrincipalName)"
$i++
}
}
Write-Host -ForegroundColor Green "$(Get-Timestamp) Info: Retriving Direct Reports Complete.. `n"
#Step 3: Output in tab delimited .txt format
$output = New-Object -TypeName System.Collections.ObjectModel.Collection["String"]
$header = "Name`tDisplayName`tDirects"
$output.Add($header)
foreach ($manager in $Managers) {
[string] $directs = ""
foreach ($direct in $manager.DirectReports)
{
$directs += $direct.UserPrincipalName + ','
}
$directs = $directs.Substring(0,$directs.Length-1)
$row = "$($manager.UserPrincipalName)`t$($manager.DisplayName)`t$($directs)"
$output.Add($row)
}
#If Output File already exists from a previous run, it will be replaced.
$testPath = Test-Path .\$($OutputFile)
if ($testPath) {
Remove-Item .\$($OutputFile)
}
foreach ($line in $output) {
$line | Out-File -FilePath .\$($OutputFile) -Append
}
Write-Host -ForegroundColor Green "$(Get-Timestamp) Exported tab delimited output to $($OutputFile). `n"
#endregion
Cortesía de Microsoft
Etiquetado en
Related Posts
Deja una respuesta Cancelar la respuesta
Categorías
- Cloud (55)
- Colaboración (177)
- keykumo (15)
- keyPYME (21)
- Outsourcing (6)
- Píldoras tecnológicas (78)
- Presencial digital (34)
- Seguridad (106)
- yo k se tio xdxd (10)
Etiquetas
acelera pyme
acelerapyme
ayudas para pymes
azure
Business Central
ciberataque
ciberseguridad
como funciona dropbox
cumplimiento GDPR
digitalización
dropbox
dropbox business
dropbox business como funciona
dropbox como funciona
Dynamics 365
Dynamics 365 Business Central
Dynamics NAV
GDPR
glosario
IA
inteligencia artificial
keypyme
Learning Machine
microsoft
Microsoft 365
Microsoft365
Microsoft Dynamics 365 Business Central
microsoft teams
nuevo dropbox business
office365
office 365
phishing
productividad
PYME
PYMEs
píldoras tecnológicas
RGPD
seguridad
SMB
solución problemas dropbox
Teams
teletrabajo
Transformación digital
tutorial dropbox
web