Archive
[PS] Restart Exchange Services (GUI) using out-gridview
Synopsis:
Enumerates all Exchange Services, UI allows selection for restarting selected services, and reloads UI to ensure services are back running.
Change Log 1.00:
3/17/2019 – Inital pre-flight version
3/18/2019 – Added GUI, selection process, and progress bar
[NET] Capture Network Trace
Capturing Network Trace
- Open elevated CMD
- Run: netsh trace start persistent=yes capture=yes tracefile=c:\temp\nettrace-boot.etl”
- Reproduce the issue
- Open elevated CMD
- Run: netsh trace stop
Note: For boot issues, run step 1-2, reboot* and then continue.
Converting ETL to Wireshark (.CAP)
- Download and install Microsoft Network Analyzer
- Open the ETL file
- Select Save as .CAP
[PS] Writing errors and output to a text file
1 |
.\MyScript.ps1 2>&1 | tee -filePath c:\results.txt |
Explained:
tee (tee-object) cmdlet redirects output into two directions, stores in a file or var and sends down the pipeline. In our use, it sends to a file and also displays on console.
2>&1 construct, (stderr) 2> redirects the standard and appends the &1 (stderr to stdout) to a filename of results.txt.
Other constructs.
stdin – Standard input = 0
stdout – Standard output = 1
stderr – Standard error = 2
> – Redirect pipeline output to a file,overwriting the current contents.
>> – Redirect pipeline output to a file,appending to the existing content.
2>> – Redirect error output to a file,appending to the current contents.
2> – Redirect error output to a file,overwriting the current contents.
2>&1 – The error messages are writtento the output pipe instead of theerror pipe.
Supports PS 1.0,2.0
Supports PS 3.0+; captures only standard output
References:
[PS] Passing a string into a powershell script
1 2 3 4 5 6 7 |
#call out the paramenter and data type, in our case [string]. param( [string]$arg1 ) if ($arg1 -eq "revert") { 'do this' }else { 'do that' } write-host $arg1 #shows the string |
Usage example:
test.ps1 revert
[EXO] Enabling Mailbox on Exchange Online Hybrid Configuration (ADFS)
Enabling/Creating a Mailbox on Exchange Online in a Hybrid Configuration (ADFS)
Considerations:
- Retention policy must be applied on the Exchange Online instead of against the on-premises AD object.
Use the New-RemoteMailbox cmdlet to create a mail user in the on-premises AD and also create an associated mailbox in Exchange Online.
Enable-Remote Mailbox is for an existing AD user.
- remoteRoutingAddress needs to be specified to point to cloud
- Forwarding would be set on the cloud mailbox using the cloud connection
References:
[PS] Parameter with validation
Master powershell’s extensibility’s use of functions is key real life application of PS scripts. Parameters are primarily known as input functions, where information can be passed and validated. Below is an example of how of passing a parameter and setting static validation sets:
1 2 3 4 5 |
Param( [parameter(Mandatory=$true)] [ValidateSet("Low", "Average", "High")] [String[]]$Detail ) |
Reference: https://ss64.com/ps/syntax-args.html