Jasparrow PowerShell Mission – Basics Concepts – Using IF / Else Statements – O365 Group Creation

Jasparrow PowerShell Mission

Hello Tech Buddies, Good to meet you all through Jasparrow PowerShell mission – Every now and then I used to support our fellow engineers and tech buddies across globe whenever there is an opportunity. Most of the time especially while working with office 365 engineers – I have noticed simple scripts are their real need of time to automate the basic or their day-to-day task.

Scripts are available everywhere so what’s new with this mission ? – Most of the time its not the lack of scripts available – rather, its actually lack of scripting knowledge. Its not only that – its also, lack of articulating the concepts, lack of understanding and converting it to their current scenario which needs a basic understanding about PowerShell scripts and its way of working. Through Jasparrow PowerShell Mission, Our vision is to contribute & invite contribution that help our community engineers across globe with PowerShell basics & concepts, explanations, simple scenarios, expressions, conditions & functions for beginners, etc., Please feel free to send your PowerShell contributions to jason.r@jasparrow.info – the articles will be published with your authoring Tag. Please make sure the scripts you contribute are well explained.

I here with start my first contribution which explains Basic Concepts of PowerShell, Usage of If – Else condition with sample scenario.

Concept :

Basics : By default when we open a PowerShell, it pre-loads inbuilt modules – meaning, PowerShell imports the Module automatically while we open it. Modules are nothing but set of commands that can be executed. In Other words, Lets say – If you wanted to run a command to create a mailbox in Exchange Server – Exchange Modules that contains the commands needs to be imported First – and in addition your PowerShell should be connected to one of the exchange servers.

Version Check : To find which version of PowerShell you have installed, start a PowerShell console (or the ISE) and type $PSVersionTable and press ENTER. Look for the PSVersion value.

Network : If the computer you are using to run PowerShell is within corporate network that is behind proxy – Make sure your connection to remote server (lets say O365 in our scenario) is set through right proxy server in PowerShell – how do you check if your proxy server IP is set correctly in PowerShell ? Simply by running the command “netsh winhttp show proxy”

Execution Policy : An execution policy is part of the PowerShell security strategy. Execution policies determine whether you can load configuration files, such as your PowerShell profile, or run scripts. And, whether scripts must be digitally signed before they are run. Make sure its set to remote signed while running O365 commands. Get-Executionpolicy is the command the check the current configuration

Scenario : O365 Group Creation When a Admin gets a request to create a O365 group he need to check if the group name is already exist or not – if the Group name does not exist the script should create the group – If it exists Admin should get a message that the Group name is already in use.

Script (Make sure the script is saved as filename.ps1)

Connect-ExchangeOnline
$Display = Read-Host “Enter the Display Name : “
$count = (Get-UnifiedGroup | Where-Object {$_.Displayname -eq $Display}).count
If ($count -eq 0)
{
New-UnifiedGroup -DisplayName $Display
}else {
write-host(“Group Found with the same Name”)
}

Executing the Script

Script Explanation

9 thoughts on “Jasparrow PowerShell Mission – Basics Concepts – Using IF / Else Statements – O365 Group Creation

  1. I’m extremely pleased to discover this website. I wanted to thank you for ones time just for this fantastic read!! I definitely enjoyed every part of it and i also have you bookmarked to see new stuff in your site.

  2. I’m extremely pleased to discover this website. I wanted to thank you for ones time just for this fantastic read!! I absolutely enjoyed every part of it and i also have you bookmarked to see new stuff in your site.

  3. I’m extremely pleased to discover this website. I wanted to thank you for ones time just for this fantastic read!! I absolutely enjoyed every part of it and i also have you bookmarked to see new stuff in your site.

  4. Thanks for the suggestions you have shared here. Something else I would like to express is that laptop or computer memory specifications generally increase along with other advances in the engineering. For instance, if new generations of processor chips are brought to the market, there is certainly usually a similar increase in the size preferences of all computer system memory and hard drive space. This is because software program operated simply by these processor chips will inevitably increase in power to take advantage of the new technology.

Leave a Reply

Your email address will not be published. Required fields are marked *