Powershel - ms_random_scripts.ps1

Try {
    Import-Module MsOnline -ErrorAction Stop
}
Catch {
    Write-Host "[ERROR]`t Some Module(s) couldn't be loaded. Script will stop!"
    Exit 1
}

$Uname = "[email protected]"
#read-host -assecurestring | convertfrom-securestring | out-file C:\x\securestring.txt  
$SecPass = Get-Content 'C:\x\securestring.txt' | ConvertTo-SecureString
$Credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $Uname, $SecPass
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $Credentials -Authentication Basic -AllowRedirection
Import-PSSession $Session -AllowClobber
Connect-MsolService -Credential $Credentials

#Export all users mailbox size
#get-mailbox | get-mailboxstatistics | ft displayname, totalitemsize | Out-File "C:\x\output.txt" -Append

#list all users
#Get-Recipient -ResultSize Unlimited | select DisplayName,RecipientType,EmailAddresses | Export-Csv c:\email-recipients.csv

#Get summary MailboxUsageReport
#Get-MailboxUsageReport

#Get Mailbox details
#Get-Mailbox -Identity [email protected] | fl

#In order to check which user have auditing enabled or disabled
#get-mailbox | select UserPrincipalName,auditenabled,AuditDelegate,AuditAdmin

#Blank ImmutableId
Set-MsolUser -UserPrincipalName [email protected] -ImmutableId "$null"

#Get ImmutableId
#Get-MsolUser -UserPrincipalName [email protected]


#Get Mailbox usage
#Get-Mailbox -Identity [email protected] | get-mailboxstatistics | ft displayname, totalitemsize

#Set new UPN
#Set-MsolUserPrincipalName -UserPrincipalName [email protected] -NewUserPrincipalName [email protected]

#Remove from recycle bin
#Remove-MsolUser -UserPrincipalName [email protected] -RemoveFromRecycleBin

#Remove everyone from recycle bin
#$AllDeletedUsers = Get-MsolUser -ReturnDeletedUsers
#ForEach ($DELLUser in $AllDeletedUsers){
#    Remove-MsolUser -UserPrincipalName $DELLUser.UserPrincipalName -RemoveFromRecycleBin Force
#}

#Get User details
#get-user -Identity "[email protected]" | select identity, whenCreated, whenChanged

#Update Proxy Addresses based on csv single column 'upn'
#$UTF8CSV1 = "C:\x\proxyadd.csv"
#Import-CSV $UTF8CSV1 | ForEach-Object {
#$upn = $_.upn
#$proxyadd = "SMTP:"+$upn
#$userP = ""
#$userP = Get-ADUser -Server "x.x.x.x" -Properties ProxyAddresses -Filter "UserPrincipalName -eq '$upn'"
#$userP.ProxyAddresses = $proxyadd
#Set-ADUser -instance $userP
#}

#Add user to group
#Add-ADGroupMember -Server "x.x.x.x" "Groupx" x

#Remove user from group
#Remove-ADGroupMember -Server "x.x.x.x" "Groupx" x


#Get OU Path of list of samaccountname
#$UTF8CSV1 = "C:\x\proxyadd.csv"
#Import-CSV $UTF8CSV1 | ForEach-Object {
#    $upn = $_.upn
#    $userP = ""
##    Remove-MsolUser -UserPrincipalName "$upn" -Force
#    $userP = Get-ADUser -Server "x.x.x.x" -Properties CanonicalName -Filter "samAccountName -eq '$upn'"
#    Write-Output "$userP"
#}


#Get rid of x.x.x.x secondary e-mail address for all distribution lists based on csv export from frontend
#$UTF8CSV1 = "C:\x\test.csv"
#Import-CSV $UTF8CSV1 | ForEach-Object {
#    $disp = Get-DistributionGroup -Identity $_.alias | Select-Object -ExpandProperty PrimarySMTPAddress
#    Write-Output $disp
#    Set-DistributionGroup -Identity $_.email -EmailAddresses $disp
#}

#List count of login attempts per DC
#get-aduser -filter * -Properties logoncount -server sahara | select name,logonCount | sort logoncount

Remove-PSSession $Session