Saturday, August 12, 2017


PowerShell Check if Server is alive

Use the script below to check if a server is alive # replace the server name to make it fit into your needs.

$server = “dc1.smtp25.org”

If (Test-Connection $server -count 1 -quiet) {
  Write-host  “The $server responded” -f yellow
}
else{

Write-host  “No connection to $server -f red
  Write-host “Script will stop” -f red
   Break
}



Oz Casey, Dedeal
Systems Engineer
http://smtp25.blogspot.com/ (Blog)
http://telnet25.wordpress.com/ (Blog)
https://twitter.com/Message_Talk (Twitter)


Thursday, August 10, 2017




Using PowerShell Test-Connection


#(1)_.Check if  Machine is responding

Clear-host
Write-host $null
#(a)_Capture Server name
$server = Read-host “_Provide Server Name to Test”

#(b)_. Test Connection
If (Test-Connection $server -count 1 -quiet) {
  Write-host "The $server responded" -f yellow
}
else{

Write-host  "No connection to $server" -f red
  Write-host "Script will stop" -f red
   Break;
}



Oz Casey, Dedeal
Systems Engineer
http://smtp25.blogspot.com/ (Blog)
http://telnet25.wordpress.com/ (Blog)
https://twitter.com/Message_Talk (Twitter)


Wednesday, August 9, 2017

Connect Remote Exchange Server Function



You can use below function to make connection to remote PS in Exchange 2016.
You will need to change following string $server ="EXC01.smtp25.org" to make it work for you environment.


# Connect Remote PS Exchange 2016 Server, Specify Server to connect.

# Change the server FQDN with server name you desire.
Function Connect_E16 {
    param(
        [Parameter( Mandatory=$false)]
        [string]$server ="EXC01.smtp25.org"
)
        $session = New-PSSession -ConfigurationName Microsoft.Exchange `
        -ConnectionUri http://$srv/PowerShell/ `
        -Authentication Kerberos
         Import-PSSession $session -AllowClobber
}

Clear-host
write-host $null
Write-host "_Connecting Exchange 2016 Servers"
$Connect_E16

Oz Casey, Dedeal
Systems Engineer
http://smtp25.blogspot.com/ (Blog)
http://telnet25.wordpress.com/ (Blog)
https://twitter.com/Message_Talk (Twitter)

Exchange 2016 OU Picker is not Showing Organizational Units.

Issue: Exchange 2016 CU5 , OU Picker is not showing Users within EAC ( Exchange Admin Center)

Cause: Web.config file needs to be modified “GetListDefaultResultSize” needs to be added with > number of existing OU ( Organizational Units) within the environment.

Notes: Web.config file is located on default exchange install directory under ECp folder “Program Files\Microsoft\Exchange Server\V15\ClientAccess\ecp”

It needs to be added with notepad ( opened with administrator privileges)

Each CU install will wipe these settings, therefore web.config file needs to be saved each time prior installing CU on Exchange 2016 Servers.

I have added few simple scripts to help you to develop baselines to implement in your environment

Web.config file is not server dependent, single file can be modified/saved and moved around Exchange 2016 servers, if desired.

  • Log onto Exchange 2016 Server, via RDP (Remote Desktop Protocol)
  • Provide your credentials at the logon.
  • Click windows tile and select PS (PowerShell)
  • Select to open PowerShell with administrator privileges
  • Type following press enter (note the installed directory)

$exinstall\ClientAccess\ecp

  • Type notepad on the PowerShell (Open notepad with administrator privileges)
  • Click file and select Open on the administrative notepad
  • Drill down to ECP directory under Installed directory ;
  • Program Files\Microsoft\Exchange Server\V15\ClientAccess\ecp
  • Locate web.config ( make sure on the bottom change to all files to locate the web.config)
  • Open web.config file

Press CTRL + F to bring up find menu and type “</appSettings>”

  • Locate the section
  • Add this line ( it does not exist in Exchange 2016 )

# below line must be edited above “</appSettings>” Section within the Web.Config File

<add key=”GetListDefaultResultSize” value="1500" />

  • Comments Added ( same line with comments)

<!-- Each CU Install will Wipe This File. -->

<!-- Save a backup copy of web.config file -->

<!-- After CU install you can copy and paste backup web.config file -->

<add key="GetListDefaultResultSize" value="1500" />

  • Open another PS window and copy and paste one line to get the number of OU’s in your environment and note the settings.

# You can easily get your current OU count with simple one liner

# Getting OU count

(Get-OrganizationalUnit).count

  • Close web config
  • From PowerShell Type

Restart-WebAppPool MSExchangeECPAppPool

  • Perform same task on Each Exchange 2016 Server listed below

Verification

  • Open web browser and type following URL press enter, replace the server name with proper server name that is applicable for your environment

https://EX101/ecp/default.aspx

  • Provide your credentials
  • Click Recipients
  • Click New, User Mailbox
  • Select new user
  • Click Browse
  • Make sure Under “Select an Organizational Unit” Section populates the OU Structure

clip_image002

clip_image004

clip_image006

  • You will be able to see the OU’s
  • PS scripts to

# Connect Remote Exchange 2016 Server, Specify Server to connect.

# Change the server FQDN with server name you have.

Function Connect_E16 {

param(

[Parameter( Mandatory=$false)]

[string]$srv ="EXC01.smtp25.org"

)

$session = New-PSSession -ConfigurationName Microsoft.Exchange `

-ConnectionUri http://$srv/PowerShell/ `

-Authentication Kerberos

Import-PSSession $session -AllowClobber

}

Clear-host

write-host $null

Write-host "_Connecting Exchange 2016 Servers"

$Connect_E16

# Re-start MSExcangeECPAppPool Service on each Exchange Server

# (1)_.Exchange 2016 Array

foreach ($Server in $Servers)

{

$Servers = (Get-MailboxServer | ? {$_.AdminDisplayVersion -Match "^Version 15" }).name

Write-host "_Processing $Server"

Invoke-Command -ComputerName $server{

Write-host "()_Re-Starting MSExchangeECPAppPool Service "

Restart-WebAppPool MSExchangeECPAppPool

Write-host "_()Done" -f yellow

Write-host $Null

}}

# Check Server Health

<#

.NOTES

#=============================================

# Script : Health_Check_Required_Services.ps1

# Created : ISE 3.0

# Author(s) : casey.dedeal

# Date : 08/09/2017 09:23:23

# Org : ETC Solutions

# File Name :

# Comments :

# Assumptions :

#

#==============================================

SYNOPSIS :

DESCRIPTION :

Acknowledgements :

Limitations :

Known issues :

.EXAMPLE

.\Health_Check_Required_Services.ps1 .ps1

Description

-----------

Runs the script to perform health check on Exchange 2016 Servers

#>

clear-host

write-host $null

#(a)_.Re-start MSExchangeECPAppPool Service On all Exchange Servers

$Servers = (Get-MailboxServer | ? {$_.AdminDisplayVersion -Match "^Version 15" }).name

#(b)_.Foreloop

$Foreloop = foreach ($Server in $Servers)

{

Write-host "_Checking $Server Health" -f yellow

Test-ServiceHealth | select Role,RequiredServicesRunning,ServicesRunning,ServicesNotRunning

}

#Out-Grid Results

$Foreloop | Out-GridView

Make backup for Web.Config File

<#

.NOTES

#=============================================

# Script : Copy_Web_Config_V1.ps1

# Created : ISE 3.0

# Author(s) : casey.dedeal

# Date : 08/09/2017 09:31:30

# Org : ETC Solutions

# File Name :

# Comments :

# Assumptions :

#

#==============================================

SYNOPSIS :

DESCRIPTION :

Acknowledgements :

Limitations :

Known issues :

.EXAMPLE

.\Get-Sample.ps1

Description

-----------

Runs the script to make copy of Web Config file

Specify Exchange 2016 Server Name

After each RU install you need to put the file back

#>

#(a)_.Variables

$user = $env:UserName

$dom = $env:UserDomain

$comp = $env:ComputerName

$date = get-date -Format yyyy-mm-dd

#(b)_.Source & Dest

$Source = "\\EXC01\d$\Program Files\Microsoft\Exchange Server\V15\ClientAccess\ecp\web.config"

$Dest = "C:\users\$user\Desktop\"

$file = "Web_Config_backup"

$Folder = $dest + $file + "_" + $date

$collec = $Source

write-host $null

write-host "--------$dom----------"

write-host "$user"

write-host "$comp"

Write-host "Copying Exchange 2016 Short-cuts" -f yellow

write-host "-------------------------"

#(c)_. Running foreach

foreach ($item in $collec)

{

If (Test-Path $source){

Write-host -fore yellow "Located $file "

New-Item -ItemType directory -Path $Folder

Copy-Item -Recurse $item -destination $Folder -Force

}Else{

write-host -fore red "Source File cannot be located"

write-host -fore yellow " Script Will Stop in 5 seconds"

Start-Sleep -Seconds 5

break

}}

Oz Casey, Dedeal
Systems Engineer
http://smtp25.blogspot.com/ (Blog)
http://telnet25.wordpress.com/ (Blog)
https://twitter.com/Message_Talk (Twitter)