Resize Ubuntu disk in VMware

After you have resized the disk in VMware, you will need to login as super user in Linux. Then check to see the size:

df -h

You should see the disk “/dev/mapper/ubuntu–vg-ubuntu–lv” as the one mapped as root, and is low on disk space.

Run the following (parted my not be needed, USE SNAPSHOTS!!!):

parted

>>resizepart
>>quit


lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv

resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

Now check:

df -h

Useful commands

lsblk /dev/sda
partprobe -s
unit s print free

Logging into Office 365 with Powershell

Make sure you have all the modules:

Install-Module -Name MSOnline
Install-Module -Name AzureAD 

Then Login

$objCred = Get-Credential
$objSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $objCred -Authentication Basic -AllowRedirection
Import-PSSession $objSession

#Add compliance center
$objSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $objCred -Authentication Basic –AllowRedirection
Import-PSSession $objSession 

Adding licenses to Office 365 users based upon AD group

Not a whole lot of documentation here, just slice and dice as you see fit.

In the environment that this was created in, all Office 365 users are in the group “SyncWithO365” (this is the sync group for Azure AD Connect). Most users receive an Exchange Online 1 license. The users that receive an E3 license are in O365E3License group. This script will take those two groups and issue Office 365 EO1 and E3 licenses accordingly.

#config

#tenant name (before the .onmicrosoft.com)
$strTenant = "awesomeCorp" 

#admin account on 365 to issue licenes with
$str365UserName = "[email protected]"
$str365Password = "password123"


$str365AllUsersGroup = "SyncWithO365"
$str365EnterpriseUsersGroup = "O365E3License"

##########################
# Do not edit below this #
##########################

#all users that were not in 365
$objFailedUsers = New-Object System.Collections.ArrayList($null)

#loggin function
function Go-Logit
{
    Param([string]$LogEntry)
    $strTime = get-date -f MM-dd-yyyy:HH:mm:ss
    write-host $strTime ":" $LogEntry
}

#set the license function
function Set-License365
{
    Param ([bool]$StandardLicense,
    [string]$User)

    #Get-MsolAccountSku
    #setup the SKU's
    $strEnterprise = $strTenant + ":" + "ENTERPRISEPACK"
    $strStandard = $strTenant + ":" + "EXCHANGESTANDARD"

    $blUserIsIn365 = $true
    #get the user license
    $objUserLic = Get-MsolUser -UserPrincipalName $User

    if($objUserLic -eq $null)
    {
        Go-Logit -LogEntry "$User isn't in 365"
        $objFailedUsers.Add($User)
        $blUserIsIn365 = $false
    }
    
    if($blUserIsIn365 -eq $true)
    {
         #if we dont have a license
        if($objUserLic.IsLicensed -eq $true)
        {
            Go-Logit -LogEntry "$User : License found"
            #we have a license, so now we need to check it its correct
            $blEntLicenseFound = $false #enterprise license
            $blStaLicenseFound = $false #standard license
            foreach($objLicense in $objUserLic.Licenses)
            {
                #$objLicense
                if($objLicense.AccountSkuId -eq $strEnterprise)
                {
                     Go-Logit -LogEntry "$User : Seems to be enterprise"
                    $blEntLicenseFound = $true
                }
                if($objLicense.AccountSkuId -eq $strStandard)
                {
                    Go-Logit -LogEntry "$User : Seems to be standard"
                    $blStaLicenseFound = $true
                }
            }
            #if this is a standard license user
            if($StandardLicense -eq $true)
            {
                #if a enterprise license was found, we need to replace it
                if($blEntLicenseFound -eq $true)
                {
                    Go-Logit -LogEntry "$User : Replacing enterprise with standard"
                    Set-MsolUserLicense -UserPrincipalName $User -AddLicenses $strStandard -RemoveLicenses $strEnterprise
                }
                else
                {
                    Go-Logit -LogEntry "$User : The correct license was found"
                }
            }
            #this must be a enterprise user
            else
            {
                #if a standard license was found, we need to replace it.
                if($blStaLicenseFound -eq $true)
                {
                    Go-Logit -LogEntry "$User : Replacing standard with enterprise"
                    Set-MsolUserLicense -UserPrincipalName $User -AddLicenses $strEnterprise -RemoveLicenses $strStandard
                }
                else
                {
                    Go-Logit -LogEntry "$User : The correct license was found"
                }
            }
        }
        else
        {
            #no license was found, need to add one
            Go-Logit -LogEntry "No license found"
            #if this is a standard license user
            if($StandardLicense -eq $true)
            {
                Go-Logit -LogEntry "$User : Setting a standaed license"
                Set-MsolUser -UsageLocation US -UserPrincipalName $User
                Set-MsolUserLicense -UserPrincipalName $User -AddLicenses $strStandard
            }
            #must be an enterprise
            else
            {
                Go-Logit -LogEntry "$User : Setting a enterprise license"
                Set-MsolUser -UsageLocation US -UserPrincipalName $User
                Set-MsolUserLicense -UserPrincipalName $User -AddLicenses $strEnterprise
            }
        }
    }
}

#get Exchange Online E1 users 
$obj365UsersArr = @(Get-ADGroupMember -identity $str365AllUsersGroup -Recursive | get-aduser | select -Expand UserPrincipalName)
$obj365Users = New-Object System.Collections.ArrayList(,$obj365UsersArr)

#get E3 users
$obj365e3UsersArr = @(Get-ADGroupMember -identity $str365EnterpriseUsersGroup -Recursive | get-aduser | select -Expand UserPrincipalName)
$obj365e3Users = New-Object System.Collections.ArrayList(,$obj365e3UsersArr)

#enumerate through all E3 users and remove them from the group that contains all users
#the result,  $obj365Users will only have people not in the e3 group
foreach($objE3User in $obj365e3UsersArr)
{
    $obj365Users.Remove($objE3User)
}

#create credentials to speak with office 365
$objPassword = $str365Password | ConvertTo-SecureString -asPlainText -Force
$objCredential = New-Object System.Management.Automation.PSCredential($str365UserName,$objPassword)
Import-Module MSOnline
Connect-MsolService -Credential $objCredential

Go-Logit -LogEntry "----------------------Pushing licenses for Standard users"
#standard users
foreach($objUserTemp in $obj365Users)
{
    Set-License365 -User $objUserTemp -StandardLicense $true

}

Go-Logit -LogEntry "----------------------Pushing licenses for Enterprise users"
#Enterprise users
foreach($objUserTemp in $obj365e3Users)
{
    Set-License365 -User $objUserTemp -StandardLicense $false

}

Go-Logit -LogEntry "----------------------Listing all users that were not in 365"
#log the users that were not in 365
foreach($objUserTemp in $objFailedUsers)
{
    Go-Logit -LogEntry "$objUserTemp was not found in 365, check group membership"

}

Adding Send-As permissions to a contact in Office 365

First, make sure you have the contact in 365. Get the contact identity.

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
Get-Recipient

The identity is the name column.

Add-RecipientPermission "" -AccessRights SendAs -Trustee ""

User being the person that needs to SendAs.

Add new user to AD with random password, and DFS home

It most companies I always setup DFS as the home server structure. This allows me to have the same home folder/server location for all users regardless of where data resides. The nightmare of this scenario is the many steps it takes to create all of this. Below is a starter script I have written to automate the process. This script doesn’t take into account existing user accounts or data, so some sanity checks are needed.

#config variables
$strDomainName = "@domain.local" #your suffix for all AD users "@domain.local" (UPN Suffix)
$strUserPath = "OU=Users,DC=domain,DC=local" #DN for users OU "OU=Path,OU=To,OU=Users,DC=domain,DC=local"
$strFileServer = "SERVERNT01" #The server that hosts the files for DFS (Hostname)
$strFileServerRootPath = "E:\Users\" #the local folder on the file server that contains the user folders
$strDFSRootPath = "\\domain.local\Home\" #The root of the home folder path for DFS \\server\root or domain based \\domain.local\root

##########################
# Do not edit below this #
##########################

#promt for info
$strUserFirst = read-host "Please enter the first name: "
$strUserLast = read-host "Please enter the last name: "
$strUserName = read-host "Please enter the username: "

#random password
$objRandom = New-Object System.Random
$NewPassword=[char]$objRandom.next(65,72) #random capitol letter A through G
1..6 | ForEach { $NewPassword = $NewPassword + [char]$objRandom.next(97,122) } #random lowercase a through z
$NewPassword = $NewPassword + [char]$objRandom.next(48,57) #Random number 0 throu 9
$SecurePassword = ConvertTo-SecureString $NewPassword -AsPlainText -Force

#setup some variables
$strUPN = ($strUserName + $strDomainName)
$strHomeFolder = ($strFileServerRootPath + $strUserName)
$strShare = ($strUserName + "$")
$strFileServerShareRootPath = ("\\" + $strFileServer + "\")

#create the account
New-ADUser -Name ($strUserFirst + " " + $strUserLast) -GivenName $strUserFirst -Surname $strUserLast -SamAccountName $strUserName -UserPrincipalName $strUPN -AccountPassword $SecurePassword -Path $strUserPath -PassThru | Enable-ADAccount

#replicate AD
repadmin /syncall /A /P /e /d > $null

#Create the folder
Invoke-Command -ComputerName $strFileServer -Scriptblock {
#create the folder
New-Item $Using:strHomeFolder -ItemType directory -Force > $null
#set the ACL
$objACL = Get-Acl $Using:strHomeFolder
$objPermission = $Using:strUPN,"Modify",”ContainerInherit,ObjectInherit”,”None”,”Allow”
$objAccessRule = new-object System.Security.AccessControl.FileSystemAccessRule $objPermission
$objACL.SetAccessRule($objAccessRule)
$objACL | Set-Acl $Using:strHomeFolder > $null
#share it out
New-SmbShare -name $Using:strShare -path $Using:strHomeFolder -FullAccess Everyone > $null
}
#create the DFS link
New-DfsnFolder -path ($strDFSRootPath + $strUserName) -TargetPath ($strFileServerShareRootPath + $strShare) > $null
#output the user and password
Write-Host "Created user $strUPN with password: $NewPassword"

Getting a mailbox report from Exchange

The following will generate a CSV file that will allow you to perform analytics on the mailboxes in your environment.

In Powershell;
Get-Mailbox | Get-MailboxStatistics | Select-Object DisplayName, TotalItemSize, ServerName, Database | Export-Csv C:\ExchangeReport.csv

Or, if you have more than 1000 accounts;
Get-Mailbox -resultsize 10000 | Get-MailboxStatistics | Select-Object DisplayName, TotalItemSize, ServerName, Database | Export-Csv C:\ExchangeReport.csv

This will give you the mailbox sizes for your entire organization. Import the data into Excel as a CSV and you should get something like this;

Play with the “Text to column” and you should have something like this;

I used this formula to make the Megs column;
=C2/(1024*1024)

With a pivot table, you should get something like this;

Outlook holding onto old mailboxes that you had full permissions to

Sometimes you give yourself full permissions to a mailbox for testing. After you remove your access, the mailbox hangs around your Outlook. Attempts to remove the mailbox give you the error

This group of folders is associated with an e-mail account. To remove the account, click the File Tab, and on the Info tab, click Account Settings. Select the e-mail account, and then click Remove.

The fix for this is to add yourself back to the mailbox with Powershell while using the -Automapping flag, then remove your access again.

Add-MailboxPermission -Identity TARGETACCOUNT -User YOURACCOUNT -AccessRights FullAccess -InheritanceType All -Automapping $false
Remove-MailboxPermission -Identity TARGETACCOUNT -User YOURACCOUNT -InheritanceType All -AccessRights FullAccess