Category: Windows Server

PS: Add delegate to Room Mailbox for booking approval

PS: Add delegate to Room Mailbox for booking approval

Hi Guys

So today whilst at work I had another Powershell challenge to add delegates to our large number of meeting rooms in the exchange estate. See the below for the approach I had taken.

Get-Mailbox -ResultSize unlimited | where {$_.resourcetype -eq "Room"} | Set-Mailbox -GrantSendOnBehalfTo @{add="EndUser@User.com"}

I started out using the below example however this shown to be problematic as this over written the current configuration and does not append permissions.

Get-Mailbox -ResultSize unlimited | where {$_.resourcetype -eq "Room"} | Set-CalendarProcessing –ResourceDelegates "EndUser@User.com"
Advertisements
PS: Connect to Exchange (EOL) With MFA

PS: Connect to Exchange (EOL) With MFA

Hi Guys

sorry for the long delay between updates but here is another snippet to save you all time. The below will allow you to stand-up on Exchange Online Powershell session without having to go through the EAC web page which we can all probably say is too slow!!

Please Note your local profile will require an initial launch of the EOL PS from the EAC just to deploy modules

Import-Module $((Get-ChildItem -Path $($env:LOCALAPPDATA+"\Apps\2.0\") -Filter Microsoft.Exchange.Management.ExoPowershellModule.dll -Recurse ).FullName|?{$_ -notmatch "_none_"}|select -First 1)
	$EXOSession = New-ExoPSSession
Import-PSSession $EXOSession
PS (Unfinished): O365 User Exporter For MaaS360

PS (Unfinished): O365 User Exporter For MaaS360

Image result for its broken meme

#############################################
## Global Varibles
#############################################
$script:SelectedPath = $null
$script:PrimaryDomain = $null
$script:PulledUserData = $null
$Script:date = Get-Date -Format ddmmyyhhmm
#############################################
## Functions
#############################################
Function EnvConfiguration () {
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -ErrorAction Stop
Add-Type -AssemblyName PresentationFramework
Add-Type -assemblyName PresentationCore
Add-Type -assemblyName WindowsBase
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
}
Function WelcomeDialouge () {
# Dialouge Box Params
$ButtonType = [Windows.MessageBoxButton]::OKCancel
$MessageIcon = [Windows.MessageBoxImage]::Information
$MessageTitle = "ASB -- O365 CSV Exported For IBM MaaS360 -- Daisy Stevens"
$MessageBody = "Welcome to the O365 Exporter Tool for`nMass User Importation into MaaS360`n `nScript Developed By: Daisy Olivia Stevens`nhttps://adminscriptbank.wordpress.com`nhttps://www.linkedin.com/in/theheroic"
# Dialouge Call
$Result = [Windows.MessageBox]::Show($MessageBody,$MessageTitle,$ButtonType,$MessageIcon)
if ($Result -eq 'OK'){ConnectO365}
}
Function ConnectO365 (){
# Obtain Creds from User input and then connect to Office 365
Connect-MsolService #-ErrorAction stop
# Move to the next function
Set-DestinationPath
}
function Set-DestinationPath {
$Message = "Please select a directory for your exported data"
$FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{SelectedPath = 'C:\'}
$FolderBrowser.Description = $Message
[void]$FolderBrowser.ShowDialog()
$FolderBrowser.SelectedPath
if ($FolderBrowser.SelectedPath -eq $null){
# Dialouge Box Params
$ButtonType = [Windows.MessageBoxButton]::OKCancel
$MessageIcon = [Windows.MessageBoxImage]::Error
$MessageTitle = "ASB -- O365 CSV Exporter For IBM MaaS360 -- Daisy Stevens"
$MessageBody = "No Path Was Selected!`nDo you wish to try again?"
# Dialouge Call
$Result = [Windows.MessageBox]::Show($MessageBody,$MessageTitle,$ButtonType,$MessageIcon)
if ($Result -eq 'OK'){Set-DestinationPath} else {exit}
}
$script:SelectedPath = $FolderBrowser.SelectedPath
PrimaryDomainSelector
}
Function PrimaryDomainSelector {
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "ASB -- O365 CSV Exported For IBM MaaS360 -- Daisy Stevens"
$objForm.Size = New-Object System.Drawing.Size(800,200)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
{$x=$objListBox.SelectedItem;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$x=$objListBox.SelectedItem;$objForm.Close();PullUserData;})
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Please Select Your Primary Domain:"
$objForm.Controls.Add($objLabel)
$objListBox = New-Object System.Windows.Forms.ListBox
$objListBox.Location = New-Object System.Drawing.Size(10,40)
$objListBox.Size = New-Object System.Drawing.Size(755,20)
$objListBox.Height = 80
Get-MsolDomain | Select-Object name | ForEach-Object {$_.Name | Add-Content -Path .\o365Domains.tmp}
ForEach($i in (Get-Content .\o365Domains.tmp))
{[void] $objListBox.Items.Add($i)}
$objForm.Controls.Add($objListBox)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
$script:PrimaryDomain = $objListBox.SelectedItem
$FileName = ".\o365Domains.tmp"
if (Test-Path $FileName)
{
Remove-Item $FileName
}
}
function PullUserData {
$script:PulledUserData = Get-MsolUser -All | Select-Object *
ComposeCSV
}
function CustomInputBox([string] $title, [string] $message, [string] $defaultText) {
[void] [Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$userForm = New-Object System.Windows.Forms.Form
$userForm.Text = "$title"
$userForm.Size = New-Object System.Drawing.Size(800,200)
$userForm.StartPosition = "CenterScreen"
$userForm.AutoSize = $False
$userForm.MinimizeBox = $False
$userForm.MaximizeBox = $False
$userForm.SizeGripStyle= "Hide"
$userForm.WindowState = "Normal"
$userForm.FormBorderStyle="Fixed3D"
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(115,80)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$value=$objTextBox.Text;$userForm.Close()})
$userForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(195,80)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$userForm.Close()})
$userForm.Controls.Add($CancelButton)
$userLabel = New-Object System.Windows.Forms.Label
$userLabel.Location = New-Object System.Drawing.Size(10,20)
$userLabel.Size = New-Object System.Drawing.Size(280,20)
$userLabel.Text = "$message"
$userForm.Controls.Add($userLabel)
$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,40)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objTextBox.Text="$defaultText"
$userForm.Controls.Add($objTextBox)
$userForm.Topmost = $True
$userForm.Opacity = 1.0
$userForm.ShowIcon = $False
$userForm.Add_Shown({$userForm.Activate()})
[void] $userForm.ShowDialog()
$value=$objTextBox.Text
return $value
}
function ComposeCSV {
$UserInputTitle = "ASB -- O365 CSV Exporter For IBM MaaS360 -- Daisy Stevens"
$userInputText = "Please enter your international country code: "
$UserInputDText = "+44"
$userInput = CustomInputBox $UserInputTitle $userInputText $UserInputDText
if ($userInput -eq $null){
$userInput = CustomInputBox $UserInputTitle $userInputText $UserInputDText
}
$Data = New-Object System.Object
$Data | Add-Member -MemberType Property -Name "Full Name" -Value $script:PulledUserData.DisplayName
$Data | Add-member -MemberType Property -Name "User Name" -Value $script:PulledUserData.Signinname
$Data | Add-Member -MemberType Property -Name "Domain" -Value $Domain
$Data | Add-Member -MemberType Property -Name "Email" -Value $script:PulledUserData.signinname
$Data | Add-Member -MemberType Property -Name "Phone Number Country" -Value $userInput
$Data | Add-Member -MemberType Property -Name "Phone Number" -Value $script:PulledUserData.PhoneNumber
$Data | Add-Member -MemberType Property
-Name "Location" -Value "London"
$Data | add-member -MemberType Property -Name "Auth Type" -Value "Local"
$Data | select * | Export-Csv -Path "$script:SelectedPath\Maas360_Export_$script:date.csv" -NoTypeInformation
CompleteMSG
}
function CompleteMSG {
# Dialouge Box Params
$ButtonType = [Windows.MessageBoxButton]::OK
$MessageIcon = [Windows.MessageBoxImage]::Information
$MessageTitle = "ASB -- O365 CSV Exported For IBM MaaS360 -- Daisy Stevens"
$MessageBody = "The Script has completed successfully"
# Dialouge Call
$Result = [Windows.MessageBox]::Show($MessageBody,$MessageTitle,$ButtonType,$MessageIcon)
if ($Result -eq 'OK'){exit}
}
#############################################
## Function Calls
#############################################
EnvConfiguration
WelcomeDialouge
PS: User Mailbox SMTP Alias Address Report

PS: User Mailbox SMTP Alias Address Report

Hi Everyone,

Here is a quick and dirty script that will produce a table within your terminal session showing you each user mailbox along with any additional SMTP addresses that are associated to each of the mailbox’s

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
# Collect Data from exchange and store into varible
$box = Get-Mailbox | Where {$_.name -NotLike ‘*DiscoverySearchMailbox*’} | Where-Object -Property RecipientType -eq -Value UserMailbox | select primarysmtpaddress,name,@{Name=”EmailAddresses”;Expression={ ($_.EmailAddresses | Where-Object {$_ -cmatch “s mtp:*”} | ForEach-Object {$_ -replace 'smtp:' }) -join ',' }}
# Perform Count of records in varible
$count = $box | measure
# Count Output
Write-Host "Result Count: " -NoNewline -ForegroundColor Green $count.Count
# Result Table Output
$box | ft -autosize

 


Old Code

$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-Mailbox | Where {$_.name -NotLike ‘*DiscoverySearchMailbox*’} | Where-Object -Property RecipientType -eq -Value UserMailbox | select primarysmtpaddress,name,@{Name=”EmailAddresses”;Expression={ ($_.EmailAddresses | Where-Object {$_ -cmatch “s mtp:*”} | ForEach-Object {$_ -replace ‘smtp:’ }) -join ‘,’ }} | ft -AutoSize

PS: Windows Update

PS: Windows Update

Needing to run Windows Updates on your machine from PowerShell this is the module for you.

https://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc

Download and extract the folder a place it in the following directory

%WINDIR%\System32\WindowsPowerShell\v1.0\Modules

Import the module into your PowerShell session

Import-Module PSWindowsUpdate

To download and install windows updates run the following

Get-WUInstall

Screenshot of Module In action

powershell-windows-update-screenshot