o365:passwdneverexpire
- Passwd-NeverExpire.ps1
############################################################################################################################
# This script connects to Office 365 and modify password expiration
# Sviluppo: GSolone
# Utilizzo: Da funzione 3 del batch "Start.bat" (se presente), altrimenti .\Passwd-NeverExpire.ps1
# Info: http://gioxx.org/tag/o365-powershell
# Ultima modifica: 23-01-2014 (rev0)
# Modifiche: -
############################################################################################################################
$FormatEnumerationLimit = -1
$pshost = get-host
$pswindow = $pshost.ui.rawui
$newsize = $pswindow.buffersize
$newsize.height = 3000
$newsize.width = 150
$pswindow.buffersize = $newsize
$newsize = $pswindow.windowsize
$newsize.height = 50
$newsize.width = 150
$pswindow.windowsize = $newsize
#Stile export HTML
$htstyle = '<style>'
$htstyle = $htstyle + “body{font-family:segoe ui,arial;color:black; }”
$htstyle = $htstyle + “H1{ color: white; background-color:#385623; font-weight:bold;width: 795px;margin-top:35px;margin-bottom:25px;font-size: 22px;padding:5px 15px 5px 10px; }”
$htstyle = $htstyle + “table{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}”
$htstyle = $htstyle + “th{border-width: 1px;padding: 5px;border-style: solid;border-color: #d1d3d4;background-color:#0072c6 ;color:white;}”
$htstyle = $htstyle + “td{border-width: 1px;padding: 5px;border-style: solid;border-color: #d1d3d4;background-color:white}”
$htstyle = $htstyle + “</style>”
clear-host
write-host
write-host -ForegroundColor Magenta oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
write-host -ForegroundColor white "Richiesta connessione alla console Exchange, specifica le credenziali"
write-host -ForegroundColor Magenta oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
write-host
write-host
#Connessione alla console Exchange
Get-PSSession | Remove-PSSession
$cred = Get-Credential
Import-Module MSOnline
Connect-MsolService -Credential $cred
$msoExchangeURL = “https://ps.outlook.com/powershell/”
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $msoExchangeURL -Credential $cred -Authentication Basic -AllowRedirection
Import-PSSession $session
#Errore di connessione
write-host
if ($lastexitcode -eq 1)
{
write-host -ForegroundColor red "Errore nella connessione alla console Exchange"
write-host -ForegroundColor red "Esci dallo script, rilancialo e fai attenzione che:"
write-host -ForegroundColor red "1. le tue credenziali siano corrette"
write-host -ForegroundColor red "2. tutti i tools per l'amministrazione di Office 365 siano installati"
write-host -ForegroundColor red "3. l'utente utilizzato sia Global Administrator della piattaforma"
} else {
#Connessione riuscita
clear-host
write-host
write-host -ForegroundColor Magenta oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
write-host -ForegroundColor white "Operazione completata con successo"
write-host -ForegroundColor white "Ora sei connesso alla console Exchange"
write-host -ForegroundColor white --------------------------------------------------------------------
write-host -ForegroundColor white "Per attivare una funzione scegliere il numero"
write-host -ForegroundColor white "in corrispondenza della voce interessata"
write-host -ForegroundColor Magenta oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
write-host
write-host
}
$Loop = $true
While ($Loop)
{
write-host " Office 365 - Set Password to Never Expire" -ForegroundColor yellow
write-host ' --------------------------------------------------------------' -ForegroundColor green
write-host "1- Blocca la scadenza password per tutti gli utenti (BULK)"
write-host "2- Esporta lo stato di scadenza della password di tutti gli utenti su file"
write-host
write-host "3- Disconnetti la sessione Powershell (fallo prima di uscire dallo script)" -ForegroundColor Red
write-host "4- Esci dallo script" -ForegroundColor Red
write-host
$opt = Read-Host "Select an option [0-4]"
write-host $opt
switch ($opt)
{
#Menu 1: conferma password Never Expire per tutti gli utenti rilevati nel sistema
1{
clear-host
write-host
write-host
write-host -ForegroundColor Magenta oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
write-host -ForegroundColor white "ATTENZIONE"
write-host -ForegroundColor white "L'operazione potrebbe richiedere diversi minuti, tutto dipende"
write-host -ForegroundColor white "dal numero di utenti presenti nel sistema."
write-host -ForegroundColor white "---------------------------------------------------------------------------"
write-host
write-host -ForegroundColor red "NON CHIUDERE QUESTA FINESTRA E NON TERMINARE LO SCRIPT"
write-host
write-host -ForegroundColor Magenta oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
write-host
write-host
# Modificato comando, aggiunto il -All per prendere tutto il blocco utenza (in caso contrario viene mostrato a video il messaggio "Warning: More results are available. Please specify one of the All or MaxResults parameters."
Get-MsolUser -All | Set-MsolUser –PasswordNeverExpires $True
# Get-MsolUser | Set-MsolUser –PasswordNeverExpires $True
write-host
write-host
if ($lastexitcode -eq 1)
{
write-host "Operazione fallita" -ForegroundColor red
} else {
write-host -------------------------------------------------------------
write-host -ForegroundColor Yellow "Operazione completata con successo"
write-host -ForegroundColor Yellow "La password per tutti gli utenti di Office 365 ora non ha alcuna scadenza"
write-host -------------------------------------------------------------
}
write-host
write-host
Read-Host "Premere invio per continuare."
write-host
}
#Menu 2: esporta lo stato di scadenza password di tutti gli utenti
2{
clear-host
write-host
write-host -ForegroundColor Magenta oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
write-host -ForegroundColor white "ATTENZIONE"
write-host -ForegroundColor white "L'operazione potrebbe richiedere diversi minuti, tutto dipende"
write-host -ForegroundColor white "dal numero di utenti presenti nel sistema."
write-host -ForegroundColor white "---------------------------------------------------------------------------"
write-host
write-host -ForegroundColor white "I salvataggi verranno effettuati nella cartella C:\Temp\O365"
write-host
write-host -ForegroundColor Magenta oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
write-host
$B = "C:\temp\O365\"
$B1A = "C:\temp\O365\Reports"
if (!(Test-Path -path $B1A ))
{
New-Item $B1A -type directory
}
#Export su file di testo
Get-MSOLUser -all | Select UserPrincipalName, PasswordNeverExpires >$B\"Export scadenza password.txt"
#Export su file CSV
Get-MSOLUser -all | Select UserPrincipalName, PasswordNeverExpires | Export-CSV $B1A\"Export scadenza password.CSV"
#Export su file HTML
Get-MSOLUser -all | Select UserPrincipalName, PasswordNeverExpires | ConvertTo-Html -head $htstyle -Body "<H1>Office 365 - Stato scadenza password utenti</H1>" | Out-File $B1A\"Export scadenza password.html"
}
#Menu 3: disconnetti sessione PowerShell
3{
clear-host
Get-PSsession | Remove-PSsession
write-host
if ($lastexitcode -eq 1)
{
write-host "Operazione fallita" -ForegroundColor red
} else {
write-host "Operazione completata con successo" -ForegroundColor Yellow
write-host "La sessione Powershell remota è stata disconnessa" -ForegroundColor Yellow
}
}
#Menu 4: esci dallo script
4{
$Loop = $true
Exit
}
#Termine delle scelte di menu
}
#Termine del loop
}
o365/passwdneverexpire.txt · Last modified: 2014/04/22 17:33 by Giovanni