Comandos powershell office365 Incared

Escrito por Soporte Incared

Permitir ejecución de Scripts

Get-ExecutionPolicy -List
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser ​

Instalar y conectar conectar a exchange y AZURE

Install-Module -Name ExchangeOnlineManagement
Install-Module AzureADPreview
Install-Module -Name "AzureAD"
Install-Module MSOnline
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Import-Module ExchangeOnlineManagement
Import-Module ExchangeOnlineManagement
Enable-PSRemoting
Connect-ExchangeOnline
Connect-AzureAD -Confirm
Connect-MsolService
//Conectarce con privilegios
Connect-MgGraph -Scopes "Directory.AccessAsUser.All"

Reporte ultimo logeo

##Ultimo inicio de seción de todos los buzones
## Comando "-Session (Get-PSSession)" opcional

Invoke-Command -Session (Get-PSSession) -ScriptBlock {Get-Mailbox -RecipientTypeDetails UserMailbox -Resultsize Unlimited | Get-MailboxStatistics | Select-Object DisplayName,LastLogonTime} | Export-CSV "C:\tmp\O365-ultimologeo-Info.csv" -NoTypeInformation -Encoding UTF8
##Ultimo inicio de seción de buzones 60000 a 120000
Invoke-Command -ScriptBlock {Get-Mailbox -RecipientTypeDetails UserMailbox -Resultsize Unlimited | Get-MailboxStatistics | Select-Object -Skip 1 -First 60000 DisplayName,LastLogonTime} | Export-CSV "C:\tmp\O365-LastLogon-28112022.csv" -NoTypeInformation -Encoding UTF8

### ultimo logeo de cuenta de archivo email.csv
import-Csv -Path c:\tmp\email.csv | foreach-object  {Get-MailboxStatistics -Identity $_.email | Select-Object DisplayName,LastLogonTime} | Export-CSV "C:\tmp\ultimologueo2.csv" -NoTypeInformation -Encoding UTF8

Cambiar campo FAX

import-Csv -Path c:\tmp\fax1.csv | foreach-object {Set-MsolUser -UserPrincipalName $_.email -Fax $_.fax}

Obtener propiedades y atributos de usaurio

Get-Mailbox -Identity "NOMBRE COMPLETO DE USUARIO" | Format-List *
Get-AzureADUser -ObjectId "email@incared.net" | Select-Object DisplayName,Mail

Exportar y Obtener información de atributos

## obtener atributo 01
Get-Mailbox -ResultSize Unlimited | select UserPrincipalName,CustomAttribute1 | Export-csv c:\tmp\customizado1.csv -NotypeInformation 
Get-Mailbox -ResultSize Unlimited | select UserPrincipalName,DisplayName,CustomAttribute* | Export-csv c:\tmp\customizado1.csv -NotypeInformation

Habilitar archivado de correo

Enable-Mailbox emailahabilitar@tucorreo.pe -AutoExpandingArchive
Start-ManagedFolderAssistant -Identity email@aarchivar.com

Get-MailboxFolderStatistics -Identity emailahabilitar@tucorreo.pe -Archive | Format-Table Name,FolderPath,ItemsInFolder,FolderAndSubfolderSize

Agregar correo Alternativo

import-Csv -Path c:\tmp\correoalternativo03112022.csv | foreach-object {Set-MsolUser -UserPrincipalName $_.usuario -AlternateEmailAddresses $_.emaildestino}  

Reporte de uso de Espacio de buzones

Invoke-Command -ScriptBlock {Get-Mailbox -RecipientTypeDetails UserMailbox -Resultsize Unlimited | Get-MailboxStatistics | Select-Object DisplayName,LastLogonTime,TotalItemSize, StorageLimitStatus, ItemCount} | Export-CSV "C:\tmp\buzones.csv" -NoTypeInformation -Encoding UTF8

Cambiar contraseña clave

import-Csv -Path d:\azure27092022.csv | foreach-object {Set-MsolUserPassword -UserPrincipalName $_.usuario -NewPassword $_.clave -ForceChangePassword $true} 

Ejecutar reporte con RobustCloudCommand


Install-Module -Name RobustCloudCommand

invoke-command -scriptblock {Get-mailbox -resultsize unlimited | select-object -property Displayname,PrimarySMTPAddress,Identity} -session (get-pssession) | export-csv c:\temp\recipients.csv
$recipients = import-csv c:\temp\recipients.csv
Start-RobustCloudCommand -recipients $recipients -logfile C:\temp\out.log -ScriptBlock {Get-MobileDeviceStatistics -mailbox $input.PrimarySMTPAddress.tostring() | Select-Object -Property @{Name = "PrimarySMTPAddress";Expression={$input.PrimarySMTPAddress.tostring()}},DeviceType,LastSuccessSync,FirstSyncTime | Export-Csv c:\temp\stats.csv -Append }
//OBTENER DATOS DE EMAILS
invoke-command -scriptblock {Get-mailbox -resultsize unlimited | select-object -property Displayname,PrimarySMTPAddress,Identity} -session (get-pssession) | export-csv c:\temp\recipients.csv
//IMPORTAR USUARIO
$recipients = import-csv c:\temp\recipients.csv
//SABER ESTADO DE ULTIMO LOGEO
Start-RobustCloudCommand -recipients $recipients -logfile C:\temp\out.log -ScriptBlock {Get-MailboxStatistics -Identity $input.PrimarySMTPAddress.tostring() | Select-Object -Property @{Name = "PrimarySMTPAddress";Expression={$input.PrimarySMTPAddress.tostring()}},DisplayName,LastLogonTime | Export-Csv c:\temp\statslogin.csv -Append }

Exportar usuarios de directorio activo

get-aduser -filter * -Properties * | select displayname, city, company, department, EmailAddress, telephonenumber,lastlogondate,distinguishedName ,CanonicalName| export-csv -path c:\temp\export-all.csv
//fuente : https://activedirectorypro.com/export-users-active-directory/

Agregar usuarios a grupos

import-Csv -Path d:\azure27092022.csv | foreach-object { Add-DistributionGroupMember -Identity "gprueba" -Member $_.clave}

Asignar ubicación PERU

import-Csv D:\temp\file.csv | foreach-object {Set-MsolUser -UserPrincipalName $_.usuario -UsageLocation "PE"} 
MGGRAPH:
import-Csv C:\temp\usuarios.csv | foreach-object {UPDATE-MgUser -UserId $_.email -UsageLocation 'PE'}

Asignar licencia

Set-MgUserLicense -UserId user@dominio.pe -addlicenses @{SkuId = '94763226-9b3c-4e75-a931-5c89vuyby688'} -RemoveLicenses @()

import-Csv D:\temp\usuarios.csv | foreach-object {Set-MgUserLicense -UserId $_.email -addlicenses @{SkuId = '94763226-9b3c-4e75-a931-5rrr701abe3456'} -RemoveLicenses @()}

import-Csv D:\csv\file.csv | foreach-object {Set-MsolUserLicense -UserPrincipalName $_.userPrincipalName -AddLicenses docentesminedu:STANDARDWOFFPACK_FACULTY} 

$batchSize = 10
$batchCount = 0
$pause = 5
Import-Csv –Path C:\Temp\usuarios.csv | 
    ForEach-Object { 
        if ($batchCount -eq $batchSize){
            Start-Sleep -Seconds $pause
            $batchCount = 0
        }
        Set-MsolUserLicense -UserPrincipalName $_.userPrincipalName -AddLicenses docentesminedu:STANDARDWOFFPACK_FACULTY 
        $batchCount++
    }

Tu carrito está vacío.

Volver a la tienda