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

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

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}

Abrir chat
¿En que podemos ayudarte sobre Comandos powershell office365 ?