Where are the scripts in Exchange 2016?

Where are the scripts in Exchange 2016?
   Exchange has a folder with a complete suite of scripts that we use in the day-to-day managing activities or sometimes we are going to use only once, for example in a migration process if we need to migrate public folders to Exchange 2016 we need to use some scripts from this suite.

   In addition, there are scripts to put in maintenance mode the server in case that we need to stop the DAG due to reboot the server in order to complete a patching process or shutdown the server for another different reason.

   As well as exist the script to stop the DAG, as well exists the script to stop the maintenance mode or resume the mailbox databases copies.

   Other scripts are used to security and hygiene activities for example enable or disable antimalware, install or uninstall antispam agents.

   In the same suite we can find scripts to get metrics about the exchange organization, they have the capability to read information from the event logs of the servers in a DAG to gather information on databases mount, moves and failover over some range of time.

   In some cases, the script has a xml file with the same name with help information, this file is very helpful because you can see all the details related to the script execution, for example what king of parameters you need to include in the script execution; also,  what kind of information you need as output (data in the console, html or csv file, etc).

  The path of the scripts in Exchange 2016 is C:\Program Files\Microsoft\Exchange Server\V15\Scripts (in case you have installed Exchange in the C: drive) or you can use the exchange variable $exinstall who will send you to this directory:

   As well you can use the exchange variable $exscripts to go directly to the scripts folder in Exchange 2016
This is the directory where you can see all scripts into the server

Remember always test the scripts in another environment different to production.

Regards – Cheers – phir melenge – Hasta luego

Some special operators in PowerShell: $($Variable), @( ), &, S_., %, ?

There are some operators that they are not common in PowerShell and we have problems to figure out the logic when we are reading a script written by another person.

For example $($Variable) operator. This is a subexpression operator that always will evaluate first the expression contained into the parenthesis and return the value as an array, and therefore you can use this information directly. Let’s see the follow example:

$c = Aduser 430001150
The variable $C contains all the information for this Active Directory object, and therefore If I want to know only the first name and last name I can write this:

Write-Host “The firstname is: $($c.GivenName)-ForegroundColor Yellow
Write-Host “The firstname is: $($c.Surname)-ForegroundColor Yellow
And the output will be:
The first name is: Tony
The last name is: Gonzalez

@() Array expression

Returns the result of one or more statements as an array, when you have the construct @() you are creating an array without any elements at all. Otherwise, if you add elements to the array they will have an index;

$array = @()   #We declare this variable as array
$array = @(1,2,5,6,9,”Hello”,”World”)   #We are adding elements to the array, the first element has the index 0, in this case has the value 1.
If we want to know what information contains this array:

PS C:\> $array
& Call operator. We use this operator to run a command, script, or script block. For example:

PS C:\> $b = “Get-ChildItem”
If we execute this value to see the result, will be the string stored in quotes.

PS C:\> $b
But if we put the call operator & we are going to get another result

PS C:\> & $b
    Directory: C:\
Mode                LastWriteTime     Length Name                                                                                                                                                
—-                ————-     —— —-                                                                                                                                                 
d—-         12/7/2016   2:52 PM            Dell                                                                                                                                                  
% Is an Alias for the command let ForEach-Object is a loop who returns each pipeline object one after the other. Which means that you can use both in a sentence.

? Is an alias for the command let Where-Object. We use this sentence to select an object from a collection.

In both aliases we can use $_. To reference to a filed into the result. For example:

PS C:\> Get-ChildItem “C:\” | ?{$_.Name -eq “temp”}
    Directory: C:\
Mode                LastWriteTime     Length Name                                  
—-                ————-     —— —-                                  
d—-          2/1/2018  11:51 AM            temp                                   

These are only some of the operator that sometimes we do not know how they mean when we are analyzing a script that has been created by another person, but obviously, there are much more. 

I will put another post with a little more.