#PowerShell Basics: Comparison Operators and Conditional Logic
Explore tagged Tumblr posts
dotnet-helpers-blog · 7 years ago
Text
PowerShell Basics: Comparison Operators and Conditional Logic
Comparison Operators and Conditional Logic Comparison operators let you specify conditions for comparing values and finding values that match specified patterns. To use a comparison operator, specify the values that you want to compare together with an operator that separates these values. Equality Operators  Description -eq equals -ne not equals -gt greater than -ge greater than or equal -lt

View On WordPress
0 notes
mbaljeetsingh · 8 years ago
Text
Scripting with PowerShell
Advertise here with BSA
Scripting is always a preferred choice for IT, businesses, server administrators, DBAs and professionals who aim to automate or schedule their routine tasks with flexibility and control. It not only makes you more productive but also improves your daily tasks.
The lack of task automation makes an emerging business lose most of its time and effort on managing its administrative tasks. You may have done tons of things to advertise your business, including creating a blog but when it comes managing your tasks you probably need something that makes your life a lot.
Introduction
Windows PowerShell is one of the powerful command line tools available for scripting. If you are familiar with Unix, DOS or any other command based tools, you would easily get expertise over PowerShell.
Your first script
A simple script in PowerShell can be written in a notepad. it is a sequence of commands called cmdletsthat will be executed one at a time.
Open notepad
Type a string: ‘Printing current date time..’
Type a cmdlet in next line: get-Date
Save file: MyFirstScript.ps1
Right click on the file and click ‘Run with PowerShell’
You can see the current date time printed on PowerShell Console
Whatever you type in double quotes, is displayed on the console and cmdlets gets executed.
Getting PowerShell on your machine
There is no need of additional installation for the tool, it is a part of Windows 7 and above by default. For earlier versions, it can be downloaded from Microsoft Scripting Center.
Just type windows or powershell in search area after pressing windows logo and you will find two PowerShell menus
Windows PowerShell is for plain console while ISE is Integrated Scripting Environment to write, test and execute scripts in the same window.
Building Blocks
Let us quickly get acquainted with the terminology to start coding. Here are the basic terms used –
Cmdlets
Commands written in PowerShell are named cmdlets(pronounced as ‘command lets’)which are the foundation of scripting. You can write a series of cmdlets to achieve your tasks. It is written as a verb-noun pair which is easy to remember and self-explanatory.
If we execute following cmdlet, it lists down all the childs from current location –
PS C:\> Get-Childitem
(Get – verb, Childitem – Noun)
Each cmdlet has an associated help file to know about its syntax – Description and parameters required to invoke it correctly. You can use cmdlet ‘Get-Help’ for same.
Aliases
Let us observe the following commands –
The cmdlet Get-childitem returns the list of files/folders in current directory in this case – C drive.
If you look at other two commands – dir and ls, both return the same result. Does that mean there are duplicate commands to solve the same problem?
No, these both are aliases to ‘Get-childitem’. You can create handy aliases of your important commands and use it. This is the reason why your DOS and Unix commands work seamlessly with PowerShell.
Following command sets alias for Set-Location cmdlet
PS C:\> New-Alias Goto Set-Location
You can find out existing aliases by command type – ‘Alias’ on your machine
PS C:\> Get-Command –Name *
Pipeline
You can use output of one cmdlet in another using pipe character (|). As an example you want to collect some data and then copy the output to a file, you can simply do it with one-line syntax
PS C:\> Get-Childitem | Export-Csv out.csv
Redirection
Two Redirection operators used are > and >>.
These enable you to send particular output types to files and output stream
Code
Message Type
*
All output
1
Success
2
Error
3
Warning
4
Verbose
5
Debug
Following command writes the out to a file instead of console
PS C:\> Get-Childitem * > out.txt
Operators
Like any other scripting language, PowerShell also provides an exhaustive list of operators to write powerful scripts. Some of the basic operators are listed for your reference here:
Operator
Symbol
Definition
Assignment
“=,+=,-=,*=,/=,%=,++,–“
Assigns one or more values to a variable
Comparison
“-eq, -ne”
Equal, Not equal
“-gt,-ge”
Greater than, Greater than or equal to
“-lt,-le”
Less than, Less than or equal to
“-replace”
Changes specified element in a value
“-match, -notmatch”
Regular expression matching
“-like, -notlike”
Matching wildcards
“-contains,-notcontains”
Returns TRUE if the value on its right is contained in the array on its left
“-in, -notin”
Returns TRUE only when given value exactly matches at least one of the reference values.
Logical
“-and, -or, -xor, -not, !”
Connect expressions and statements, allowing you to test for multiple conditions
Bitwise
“-band”
Bitwise AND
“-bor”
Bitwise OR (inclusive)
“-bxor”
Bitwise OR (exlcusive)
“-bnot”
Bitwise NOT
String
“-Split”
splits a string
“-join”
joins multiple strings
Execution Policy
Powershell executes cmdlets as per set execution policy of the machine or server. Sometimes it becomes necessary to explicitly set the policy on the scripts before executing on different machines.
The Set-ExecutionPolicy cmdlet is used for the purpose which has four options to choose from –
Policy
Definition
Restricted
No scripts can be run. PowerShell can be used only in interactive mode
AllSigned
Only scripts signed by a trusted publisher can be run
RemoteSigned
Downloaded scripts must be signed by a trusted publisher before they can be run
Unrestricted
No restrictions – all scripts can be run
Useful Commands
There are more than two hundred in-built cmdlets for use and developers can built complex ones by using the core commands. Some of the useful commands are listed below:
Cmdlet
Syntax
Output
Usage
Get-Date
Get-Date
Sunday, March 26, 2017 6:12:40 PM
Gets current date and time
(Get-Date).AddMinutes
(Get-Date).AddMinutes(60)
Sunday, March 26, 2017 7:12:40 PM
Adds 1 hour to current date and time
Copy-Item
Copy-Item c:\source.txt d:\destination
Copy source.txt to destination folder
Copying files and folders
Clear-Eventlog
Clear-Eventlog -LogName
Clears all enteries from specified event log
Restart-Service
Restart-Service -Servicename
Restarts service
Get-ChildItem
Get-ChildItem
Gets all files and folders
Some parameters make his more useful – force – to run without user confirmation on special folders include – to include certain files or folders exclude – to exclude certain files path – specified path instead of current directory
Set-Content
Set-Content C:\textFile.txt “Text being added here from PowerShell”
Saves text to a file
Remove-Item
Remove-Item C:\test -Recurse
Removes all contents from a folder
User will not be prompted before deletion
(Get-WmiObject -Class Win32_OperatingSystem -ComputerName .).Win32Shutdown(2)
(Get-WmiObject -Class Win32_OperatingSystem -ComputerName .).Win32Shutdown(2)
Restart current computer
Real-world Scenario
Let’s see how PowerShell made the life of a server administrator easy!
John Bell, one of the system administrator of an MNC is catering to some 2000 users and update patches on their desktops remotely through Windows Server 2010 and MS System Center Configuration Manager, SCCM. Now, when one or more patches get scheduled to run during night hours, often they failed on couple of machines due to disk space scarcity and lots of manual intervention and rework is required to close the current job. One of his colleagues suggested to take a proactive approach and get a list of machines with details of what is being stored on C drive, a day before patch execution job, so John decided to create a powershell script to get executed through SCCM on client machines automatically and send give a detailed report in a csv file to review the data usage and bottle necks.
Here is what he wrote (added inline comments for clarity) –
## Initiate source and destination $filePath="C:\" $outFile="D:\output.csv" ## Get last logged in username $strName=$env:username get-Date-formatr ## Get computer name $compName=$env:computername ## get total size and free space of c drive of selected computer $disk=Get-WmiObjectWin32_LogicalDisk-ComputerName$compName-Filter"DeviceID='C:'"| Select-ObjectSize,FreeSpace $TotalSpace= ($disk.Size/1gb) $FreeSpace= ($disk.FreeSpace/1gb) ## initiating two arrays for getting a list $arr= @() $finalObj= @() $object=$null ## Include Hidden Files $arr=Get-ChildItem$filePath-Force|where {$_.PSIsContainer -eq$False} |Select-ObjectName,FullName,CreationTimeUtc,LastWriteTimeUtc,length "Gathering information of files completed. Folder scan started..." ## Include Hidden Folder $arr=Get-ChildItem$filePath-Force|where {$_.PSIsContainer -eq$True} |Select-ObjectName,FullName,CreationTimeUtc,LastWriteTimeUtc #Loop for folders foreach($itemin$arr) { $FType="Folder" $FSize=0 $PerHDD=0 $item.FullName ## Include Hidden Files $FSize= (Get-ChildItem$item.FullName -Force-recurse-ErrorActionSilentlyContinue|Measure-Object-propertylength-sum).Sum $FSize=[math]::round($FSize/1gb,2) $PerHDD=[math]::Round($FSize/$TotalSpace*100,2) switch ($item.name ) { $PLogs {break} ;$MSOCache {break} ; $Recovery {break} ; $SystemVolumeInformation {break} default {$own=Get-Acl$item.FullName} } $object=New-Object-TypeNamePSObject $object|Add-Member-Name'CompName'-MemberTypeNoteproperty-Value$compName $object|Add-Member-Name'TotalSpace'-MemberTypeNoteproperty-Value$TotalSpace $object|Add-Member-Name'FreeSpace'-MemberTypeNoteproperty-Value$FreeSpace $object|Add-Member-Name'Name'-MemberTypeNoteproperty-Value$item.Name $object|Add-Member-Name'FilePath'-MemberTypeNoteproperty-Value$item.FullName $object|Add-Member-Name'Type'-MemberTypeNoteproperty-Value$FType $object|Add-Member-Name'Size'-MemberTypeNoteproperty-Value$FSize $object|Add-Member-Name'In'-MemberTypeNoteproperty-Value'GB' $object|Add-Member-Name'% of HDD'-MemberTypeNoteproperty-Value$PerHDD $finalObj+=$object } "Folder scan completed." $finalObj|Export-Csv$outFile "Job Completed! File created successfully"
Output is a csv file –
CompName
TotalSpace
FreeSpace
Name
Size
In
% of HDD
<compName>
99.99999619
29.15378189
Program Files
2.12
GB
2.12
Conclusion
PowerShell is extremely powerful and handy when comes to manage server and database tasks and can quickly automate tasks for you. Give it a try! Happy Coding!
via http://ift.tt/2o1U0Z9
0 notes
o365info-blog · 8 years ago
Text
New Post has been published on o365info.com
New Post has been published on http://o365info.com/searching-for-email-addresses-using-powershell-where-filter-office-365-part-9-13/
Searching for an Email addresses using PowerShell | Where Filter | Office 365 | Part 9#13
The current article we review the PowerShell command syntax, that we use for “constructing” a query, for searching specific E-mail address using the PowerShell WhereFilter.
Manage Email addresses | Article Series table of content | Click to expand
Manage Email addresses using PowerShell | Office 365 | Article Series
01 Manage Email addresses using PowerShell | Office 365 | Command reference | Part 1#13 02 Manage Email addresses using PowerShell | Office 365 | Command reference | Part 2#13 03 Adding Email addresses using PowerShell | Office 365 | Part 3#13 04 Adding Email addresses using PowerShell – Bulk mode | Office 365 | Part 4#13 05 Adding Email addresses using PowerShell – Import from CSV file | Bulk mode | Office 365 | Part 5#13 06 Export and display information about Email addresses using PowerShell | Office 365 | Part 6#13 07 Display information about E-mail Addresses using PowerShell | Customizing the output using Hash Table and Custom expressions | Office 365 | Part 7#13 08 Introduction to the various type of Exchange Online recipients | PowerShell cmdlets | Office 365 | Part 8#13 09 Searching for an Email addresses using PowerShell | Where Filter | Office 365 | Part 9#13 10 Searching Email addresses with a specific domain name suffix Using PowerShell | Office 365 | Part 10#13 11 Searching “hidden” Email addresses Using PowerShell | Office 365 | Part 11#13 12 Remove Email addresses using PowerShell | Office 365 | Part 12#13 13 How to use the PowerShell script – manage Email addresses in Office 365 | Part 13#13
The thing that we need to know before we start the search for E-mail address
In this section, I would like to briefly review the main points that relate to the task of performing a search for E-mail addresses in an Office 365 environment.
1. Where to perform the search? As mentioned, in an Office 365 environment is a “mesh” of different environment that constructs the logical term “Office 365.”
The information that we look for can be associated with Office 365 users who are located in the Azure Active Directory or, associated with Exchange Online recipients that are hosted at the Exchange Online infrastructure.
So, the first question that we need to answer is “where” we want to perform the search?
2. Exchange Online | What are the “recipients type” that we want to query? Exchange Online includes a substantial number of different recipient’s type.
In a utopian world, we could use one “magical” PowerShell cmdlet, that will help us to scan and fetch information about all the existing Exchange Online recipients. The reality is a little more complicated because, unfortunately, there is no such command.
To be able to address all the available Exchange Online recipient, we will need to use a “Mixture” of PowerShell cmdlets that will address different types of Exchange Online recipients.
3. The term “E-mail address” In the Office 365 environment, the term “E-mail address,” can be translated to a wide range of “address,” that use an identical naming structure as the “SMTP E-mail address.”
For example,
Office 365 user login name (UPN) is based on the naming structure of smtp E-mail addresses.
SIP address (Skype for business users) uses the same naming structure of smtp E-mail addresses.
What PowerShell syntax to use for performing the search?
In the current article, we will use the PowerShell “Where statement” as a tool for performing a query, that will scan existing Office 365 objects (Office 365 user account and Exchange Online recipient), and “fetch” for us the object that answers specific criteria.
The E-mail address as a “Text string.”
PowerShell offers many methods for implementing the task of – looking for a specific “text string.” In our scenario, the “text string” that we look for is an “E-mail address.” When we say that we are looking for an E-mail address, the term “E-mail address” can be realized as:
The “Left part” of an E-mail address. This is that part that includes the recipient Alias name. We relate to the “left part” of the E-mail address when we look for information about specific Alias name\s.
The “Right part” of an E-mail address. This is the part that includes the domain name suffix. We relate to the “Right part” of E-mail address when we look for information about E-mail address with a specific domain name.
The “right part” + the “left part.” We relate to the booth of the E-mail address parts, in a scenario in which we search for a specific E-mail address.
Using PowerShell for searching a specific E-mail address using the Where statement
In the following diagram, we can see a basic structure of a PowerShell command, in which we look for E-mail addresses that have a specific domain name suffix.
The “PowerShell query” is created by using the Where filter.
The different “parts” of the PowerShell command syntax
Part 1#4 – Exchange Online recipient object
The first part is the part in which we select the specific Exchange Online recipient. In our example, the Exchange recipient “type” is Exchange mailbox.
Part 2#4 – The Where filter
In this part, we use the PowerShell “Where” statement + the definition of the “query filter” or in other words- the “search condition.”
The PowerShell Where statement, include the following parts:
To perform the required search, that defines a condition in which we search only for E-mail address that has a specific character such as – specific domain name suffix, we use the PowerShell statement – “Where”
The PowerShell query “resides” between the curly brackets.
In our scenario, we query the Azure Active Directory infrastructure + Exchange Online infrastructure.
When we query Exchange Online infrastructure, we “address” the Exchange Online recipient property named – “EmailAddresses”.
When we query Azure Active Directory infrastructure, we “address” the Office 365 user property named – “UserPrincipalName” and the property “ProxyAddresses“.
The PowerShell operator whom we use.
In a scenario in which we look for a specific E-mail address, we can choose a couple of options of the “PowerShell operators” that we use.
For example, we can use the PowerShell operator – “eq” (equal) or the PowerShell operator “like.”
The PowerShell operator “Like” as the name implies, we search for E-mail addresses that are “like” the E-mail address that we provide.
In our specific scenario, an Exchange Online recipient could “use” the specific E-mail address as an “SMTP E-mail address” or “SIP address.”
For example, when using the PowerShell operator “like,” looking for the following E-mail addresses [email protected], the PowerShell command display result if she finds SMTP E-mail address that includes that “search string” or SIP address that includes the “search string.”
In case that we use the Comparison Operators “like,” we must use the asterisk character (*)
To be able to define a condition, in which we want to find a text string that “begin” with defined characters, but we don’t know how it “end,” we will add the asterisk character (*) at the end of the text string that we “provide” to the PowerShell command.
To be able to define a condition, in which we want to find a text string that “end” with defined characters, but we don’t know how it “begin,” we will add the asterisk character (*) at the begging of the text string that we “provide” to the PowerShell command.
As we can see in the picture, the PowerShell operator “Like” and the asterisk character (*) are good friends.
Another example of PowerShell operator whom we can use is the operator – “eq” (equal).
When we want to “tell” PowerShell that we want to perform a search that looks for a “perfect match,” we use the operator – “eq” (equal).
For example, in case that we want to look for the following E-mail – [email protected] but display information only if the address is an smtp address, we will use the following PowerShell syntax:
Note – if you fill “overloaded” from all the information and the various searches that we need to perform, I have created a PowerShell menu based script named – Manage E-mail address.ps1, that will simplify the task of searching for an E-mail address with a specific domain name suffix.
Additional reading
About Comparison Operators
Part 3#4 –  the displayed object properties “fields”
Each of the recipient objects such as – Exchange Online mailbox have many properties.
After the Where filter gets the required information, (in our case, an Exchange recipient who answers a specific condition), the “PowerShell output” displays recipient or a recipient list.
Each of the recipients will be displayed + using “predefined object properties.”
Most of the time, we would like to change this “default,” and “inform” PowerShell, what are the specific recipient properties (attributes) that are relevant for us.
For example, in a scenario in which we look for recipients who have a specific E-mail address, the main properties that are relevant for us are:
The recipient name such as – Display name.
The type of the recipient (Recipienttype) such as mailbox user or contact.
The E-mail addresses that are associated with the specific recipient.
To “inform” the PowerShell command, what are the specific properties that we wish to display (or export), we use PowerShell parameters such as – Select, FL (Format List) or FT (Format Table).
Each of the “properties” that we wish to display, will be separated by a comma character.
Part 4#4 – Export the results.
By default, the results from the PowerShell query displayed on the PowerShell console.
Regarding the task of – getting information about Exchange Online recipients E-mail address (or Office 365 UPN name), in many scenarios, we will need to export the information to files.”
Storing the information in files, enable us to “manipulate” the data by using filters, specific views and in addition, edit and manage the data.
To export the information about E-mail address, the was created from the PowerShell Where filter, we will need to provide the specific file type that we need such as – CSV, TXT or HTML.
For your convenience, I have “Wrapped” all the PowerShell commands that were reviewed in the article, in a “Menu Based” PowerShell Script. You are welcome to download the PowerShell script and use it.
Manage E-mail address using PowerShell script
Download Now!2 Downloads
In case that you need instructions about – how to use the Manage E-mail address PowerShell script menu, you can read the fowling Article.
The next article in the current article series
Searching Email addresses with a specific domain name suffix Using PowerShell | Office 365 | Part 10#13
Now it’s Your Turn! It is important for us to know your opinion on this article
Restore Exchange Online mailbox | Article series index
Related Post
Export and display information about Email address...
Disable Clutter by using OWA client
What is the hostname of my Office 365 MX records?
Why our mail system is exposed to Spoof and Phishi...
Exchange Public infrastructure | Public versus non...
.yuzo_related_post imgwidth:120px !important; height:110px !important; .yuzo_related_post .relatedthumbline-height:15px;background: !important;color:!important; .yuzo_related_post .relatedthumb:hoverbackground:#fcfcf4 !important; -webkit-transition: background 0.2s linear; -moz-transition: background 0.2s linear; -o-transition: background 0.2s linear; transition: background 0.2s linear;;color:!important; .yuzo_related_post .relatedthumb acolor:!important; .yuzo_related_post .relatedthumb a:hover color:!important;} .yuzo_related_post .relatedthumb:hover a color:!important; .yuzo_related_post .yuzo_text color:!important; .yuzo_related_post .relatedthumb:hover .yuzo_text color:!important; .yuzo_related_post .relatedthumb margin: 0px 0px 0px 0px; padding: 5px 5px 5px 5px; jQuery(document).ready(function( $ ) //jQuery('.yuzo_related_post').equalizer( overflow : 'relatedthumb' ); jQuery('.yuzo_related_post .yuzo_wraps').equalizer( columns : '> div' ); )
0 notes
o365info-blog · 8 years ago
Text
New Post has been published on o365info.com
New Post has been published on http://o365info.com/searching-for-email-addresses-using-powershell-where-filter-office-365-part-9-13/
Searching for an Email addresses using PowerShell | Where Filter | Office 365 | Part 9#13
The current article we review the PowerShell command syntax, that we use for “constructing” a query, for searching specific E-mail address using the PowerShell WhereFilter.
Manage Email addresses | Article Series table of content | Click to expand
Manage Email addresses using PowerShell | Office 365 | Article Series
01 Manage Email addresses using PowerShell | Office 365 | Command reference | Part 1#13 02 Manage Email addresses using PowerShell | Office 365 | Command reference | Part 2#13 03 Adding Email addresses using PowerShell | Office 365 | Part 3#13 04 Adding Email addresses using PowerShell – Bulk mode | Office 365 | Part 4#13 05 Adding Email addresses using PowerShell – Import from CSV file | Bulk mode | Office 365 | Part 5#13 06 Export and display information about Email addresses using PowerShell | Office 365 | Part 6#13 07 Display information about E-mail Addresses using PowerShell | Customizing the output using Hash Table and Custom expressions | Office 365 | Part 7#13 08 Introduction to the various type of Exchange Online recipients | PowerShell cmdlets | Office 365 | Part 8#13 09 Searching for an Email addresses using PowerShell | Where Filter | Office 365 | Part 9#13 10 Searching Email addresses with a specific domain name suffix Using PowerShell | Office 365 | Part 10#13 11 Searching “hidden” Email addresses Using PowerShell | Office 365 | Part 11#13 12 Remove Email addresses using PowerShell | Office 365 | Part 12#13 13 How to use the PowerShell script – manage Email addresses in Office 365 | Part 13#13
The thing that we need to know before we start the search for E-mail address
In this section, I would like to briefly review the main points that relate to the task of performing a search for E-mail addresses in an Office 365 environment.
1. Where to perform the search? As mentioned, in an Office 365 environment is a “mesh” of different environment that constructs the logical term “Office 365.”
The information that we look for can be associated with Office 365 users who are located in the Azure Active Directory or, associated with Exchange Online recipients that are hosted at the Exchange Online infrastructure.
So, the first question that we need to answer is “where” we want to perform the search?
2. Exchange Online | What are the “recipients type” that we want to query? Exchange Online includes a substantial number of different recipient’s type.
In a utopian world, we could use one “magical” PowerShell cmdlet, that will help us to scan and fetch information about all the existing Exchange Online recipients. The reality is a little more complicated because, unfortunately, there is no such command.
To be able to address all the available Exchange Online recipient, we will need to use a “Mixture” of PowerShell cmdlets that will address different types of Exchange Online recipients.
3. The term “E-mail address” In the Office 365 environment, the term “E-mail address,” can be translated to a wide range of “address,” that use an identical naming structure as the “SMTP E-mail address.”
For example,
Office 365 user login name (UPN) is based on the naming structure of smtp E-mail addresses.
SIP address (Skype for business users) uses the same naming structure of smtp E-mail addresses.
What PowerShell syntax to use for performing the search?
In the current article, we will use the PowerShell “Where statement” as a tool for performing a query, that will scan existing Office 365 objects (Office 365 user account and Exchange Online recipient), and “fetch” for us the object that answers specific criteria.
The E-mail address as a “Text string.”
PowerShell offers many methods for implementing the task of – looking for a specific “text string.” In our scenario, the “text string” that we look for is an “E-mail address.” When we say that we are looking for an E-mail address, the term “E-mail address” can be realized as:
The “Left part” of an E-mail address. This is that part that includes the recipient Alias name. We relate to the “left part” of the E-mail address when we look for information about specific Alias name\s.
The “Right part” of an E-mail address. This is the part that includes the domain name suffix. We relate to the “Right part” of E-mail address when we look for information about E-mail address with a specific domain name.
The “right part” + the “left part.” We relate to the booth of the E-mail address parts, in a scenario in which we search for a specific E-mail address.
Using PowerShell for searching a specific E-mail address using the Where statement
In the following diagram, we can see a basic structure of a PowerShell command, in which we look for E-mail addresses that have a specific domain name suffix.
The “PowerShell query” is created by using the Where filter.
The different “parts” of the PowerShell command syntax
Part 1#4 – Exchange Online recipient object
The first part is the part in which we select the specific Exchange Online recipient. In our example, the Exchange recipient “type” is Exchange mailbox.
Part 2#4 – The Where filter
In this part, we use the PowerShell “Where” statement + the definition of the “query filter” or in other words- the “search condition.”
The PowerShell Where statement, include the following parts:
To perform the required search, that defines a condition in which we search only for E-mail address that has a specific character such as – specific domain name suffix, we use the PowerShell statement – “Where”
The PowerShell query “resides” between the curly brackets.
In our scenario, we query the Azure Active Directory infrastructure + Exchange Online infrastructure.
When we query Exchange Online infrastructure, we “address” the Exchange Online recipient property named – “EmailAddresses”.
When we query Azure Active Directory infrastructure, we “address” the Office 365 user property named – “UserPrincipalName” and the property “ProxyAddresses“.
The PowerShell operator whom we use.
In a scenario in which we look for a specific E-mail address, we can choose a couple of options of the “PowerShell operators” that we use.
For example, we can use the PowerShell operator – “eq” (equal) or the PowerShell operator “like.”
The PowerShell operator “Like” as the name implies, we search for E-mail addresses that are “like” the E-mail address that we provide.
In our specific scenario, an Exchange Online recipient could “use” the specific E-mail address as an “SMTP E-mail address” or “SIP address.”
For example, when using the PowerShell operator “like,” looking for the following E-mail addresses [email protected], the PowerShell command display result if she finds SMTP E-mail address that includes that “search string” or SIP address that includes the “search string.”
In case that we use the Comparison Operators “like,” we must use the asterisk character (*)
To be able to define a condition, in which we want to find a text string that “begin” with defined characters, but we don’t know how it “end,” we will add the asterisk character (*) at the end of the text string that we “provide” to the PowerShell command.
To be able to define a condition, in which we want to find a text string that “end” with defined characters, but we don’t know how it “begin,” we will add the asterisk character (*) at the begging of the text string that we “provide” to the PowerShell command.
As we can see in the picture, the PowerShell operator “Like” and the asterisk character (*) are good friends.
Another example of PowerShell operator whom we can use is the operator – “eq” (equal).
When we want to “tell” PowerShell that we want to perform a search that looks for a “perfect match,” we use the operator – “eq” (equal).
For example, in case that we want to look for the following E-mail – [email protected] but display information only if the address is an smtp address, we will use the following PowerShell syntax:
Note – if you fill “overloaded” from all the information and the various searches that we need to perform, I have created a PowerShell menu based script named – Manage E-mail address.ps1, that will simplify the task of searching for an E-mail address with a specific domain name suffix.
Additional reading
About Comparison Operators
Part 3#4 –  the displayed object properties “fields”
Each of the recipient objects such as – Exchange Online mailbox have many properties.
After the Where filter gets the required information, (in our case, an Exchange recipient who answers a specific condition), the “PowerShell output” displays recipient or a recipient list.
Each of the recipients will be displayed + using “predefined object properties.”
Most of the time, we would like to change this “default,” and “inform” PowerShell, what are the specific recipient properties (attributes) that are relevant for us.
For example, in a scenario in which we look for recipients who have a specific E-mail address, the main properties that are relevant for us are:
The recipient name such as – Display name.
The type of the recipient (Recipienttype) such as mailbox user or contact.
The E-mail addresses that are associated with the specific recipient.
To “inform” the PowerShell command, what are the specific properties that we wish to display (or export), we use PowerShell parameters such as – Select, FL (Format List) or FT (Format Table).
Each of the “properties” that we wish to display, will be separated by a comma character.
Part 4#4 – Export the results.
By default, the results from the PowerShell query displayed on the PowerShell console.
Regarding the task of – getting information about Exchange Online recipients E-mail address (or Office 365 UPN name), in many scenarios, we will need to export the information to files.”
Storing the information in files, enable us to “manipulate” the data by using filters, specific views and in addition, edit and manage the data.
To export the information about E-mail address, the was created from the PowerShell Where filter, we will need to provide the specific file type that we need such as – CSV, TXT or HTML.
For your convenience, I have “Wrapped” all the PowerShell commands that were reviewed in the article, in a “Menu Based” PowerShell Script. You are welcome to download the PowerShell script and use it.
Manage E-mail address using PowerShell script
Download Now!2 Downloads
In case that you need instructions about – how to use the Manage E-mail address PowerShell script menu, you can read the fowling Article.
The next article in the current article series
Searching Email addresses with a specific domain name suffix Using PowerShell | Office 365 | Part 10#13
Now it’s Your Turn! It is important for us to know your opinion on this article
Restore Exchange Online mailbox | Article series index
Related Post
The checklist for preparing your Exchange 2007 inf...
Directory synchronization – Links and Resou...
Connecting to Office 365 with Remote PowerShell – ...
Dealing with SPAM Mail in Office 365 | Part 1/2
Adding Email addresses using PowerShell | Office 3...
.yuzo_related_post imgwidth:120px !important; height:110px !important; .yuzo_related_post .relatedthumbline-height:15px;background: !important;color:!important; .yuzo_related_post .relatedthumb:hoverbackground:#fcfcf4 !important; -webkit-transition: background 0.2s linear; -moz-transition: background 0.2s linear; -o-transition: background 0.2s linear; transition: background 0.2s linear;;color:!important; .yuzo_related_post .relatedthumb acolor:!important; .yuzo_related_post .relatedthumb a:hover color:!important;} .yuzo_related_post .relatedthumb:hover a color:!important; .yuzo_related_post .yuzo_text color:!important; .yuzo_related_post .relatedthumb:hover .yuzo_text color:!important; .yuzo_related_post .relatedthumb margin: 0px 0px 0px 0px; padding: 5px 5px 5px 5px; jQuery(document).ready(function( $ ) //jQuery('.yuzo_related_post').equalizer( overflow : 'relatedthumb' ); jQuery('.yuzo_related_post .yuzo_wraps').equalizer( columns : '> div' ); )
0 notes
o365info-blog · 8 years ago
Text
New Post has been published on o365info.com
New Post has been published on http://o365info.com/searching-for-email-addresses-using-powershell-where-filter-office-365-part-9-13/
Searching for an Email addresses using PowerShell | Where Filter | Office 365 | Part 9#13
The current article we review the PowerShell command syntax, that we use for “constructing” a query, for searching specific E-mail address using the PowerShell WhereFilter.
Manage Email addresses | Article Series table of content | Click to expand
Manage Email addresses using PowerShell | Office 365 | Article Series
01 Manage Email addresses using PowerShell | Office 365 | Command reference | Part 1#13 02 Manage Email addresses using PowerShell | Office 365 | Command reference | Part 2#13 03 Adding Email addresses using PowerShell | Office 365 | Part 3#13 04 Adding Email addresses using PowerShell – Bulk mode | Office 365 | Part 4#13 05 Adding Email addresses using PowerShell – Import from CSV file | Bulk mode | Office 365 | Part 5#13 06 Export and display information about Email addresses using PowerShell | Office 365 | Part 6#13 07 Display information about E-mail Addresses using PowerShell | Customizing the output using Hash Table and Custom expressions | Office 365 | Part 7#13 08 Introduction to the various type of Exchange Online recipients | PowerShell cmdlets | Office 365 | Part 8#13 09 Searching for an Email addresses using PowerShell | Where Filter | Office 365 | Part 9#13 10 Searching Email addresses with a specific domain name suffix Using PowerShell | Office 365 | Part 10#13 11 Searching “hidden” Email addresses Using PowerShell | Office 365 | Part 11#13 12 Remove Email addresses using PowerShell | Office 365 | Part 12#13 13 How to use the PowerShell script – manage Email addresses in Office 365 | Part 13#13
The thing that we need to know before we start the search for E-mail address
In this section, I would like to briefly review the main points that relate to the task of performing a search for E-mail addresses in an Office 365 environment.
1. Where to perform the search? As mentioned, in an Office 365 environment is a “mesh” of different environment that constructs the logical term “Office 365.”
The information that we look for can be associated with Office 365 users who are located in the Azure Active Directory or, associated with Exchange Online recipients that are hosted at the Exchange Online infrastructure.
So, the first question that we need to answer is “where” we want to perform the search?
2. Exchange Online | What are the “recipients type” that we want to query? Exchange Online includes a substantial number of different recipient’s type.
In a utopian world, we could use one “magical” PowerShell cmdlet, that will help us to scan and fetch information about all the existing Exchange Online recipients. The reality is a little more complicated because, unfortunately, there is no such command.
To be able to address all the available Exchange Online recipient, we will need to use a “Mixture” of PowerShell cmdlets that will address different types of Exchange Online recipients.
3. The term “E-mail address” In the Office 365 environment, the term “E-mail address,” can be translated to a wide range of “address,” that use an identical naming structure as the “SMTP E-mail address.”
For example,
Office 365 user login name (UPN) is based on the naming structure of smtp E-mail addresses.
SIP address (Skype for business users) uses the same naming structure of smtp E-mail addresses.
What PowerShell syntax to use for performing the search?
In the current article, we will use the PowerShell “Where statement” as a tool for performing a query, that will scan existing Office 365 objects (Office 365 user account and Exchange Online recipient), and “fetch” for us the object that answers specific criteria.
The E-mail address as a “Text string.”
PowerShell offers many methods for implementing the task of – looking for a specific “text string.” In our scenario, the “text string” that we look for is an “E-mail address.” When we say that we are looking for an E-mail address, the term “E-mail address” can be realized as:
The “Left part” of an E-mail address. This is that part that includes the recipient Alias name. We relate to the “left part” of the E-mail address when we look for information about specific Alias name\s.
The “Right part” of an E-mail address. This is the part that includes the domain name suffix. We relate to the “Right part” of E-mail address when we look for information about E-mail address with a specific domain name.
The “right part” + the “left part.” We relate to the booth of the E-mail address parts, in a scenario in which we search for a specific E-mail address.
Using PowerShell for searching a specific E-mail address using the Where statement
In the following diagram, we can see a basic structure of a PowerShell command, in which we look for E-mail addresses that have a specific domain name suffix.
The “PowerShell query” is created by using the Where filter.
The different “parts” of the PowerShell command syntax
Part 1#4 – Exchange Online recipient object
The first part is the part in which we select the specific Exchange Online recipient. In our example, the Exchange recipient “type” is Exchange mailbox.
Part 2#4 – The Where filter
In this part, we use the PowerShell “Where” statement + the definition of the “query filter” or in other words- the “search condition.”
The PowerShell Where statement, include the following parts:
To perform the required search, that defines a condition in which we search only for E-mail address that has a specific character such as – specific domain name suffix, we use the PowerShell statement – “Where”
The PowerShell query “resides” between the curly brackets.
In our scenario, we query the Azure Active Directory infrastructure + Exchange Online infrastructure.
When we query Exchange Online infrastructure, we “address” the Exchange Online recipient property named – “EmailAddresses”.
When we query Azure Active Directory infrastructure, we “address” the Office 365 user property named – “UserPrincipalName” and the property “ProxyAddresses“.
The PowerShell operator whom we use.
In a scenario in which we look for a specific E-mail address, we can choose a couple of options of the “PowerShell operators” that we use.
For example, we can use the PowerShell operator – “eq” (equal) or the PowerShell operator “like.”
The PowerShell operator “Like” as the name implies, we search for E-mail addresses that are “like” the E-mail address that we provide.
In our specific scenario, an Exchange Online recipient could “use” the specific E-mail address as an “SMTP E-mail address” or “SIP address.”
For example, when using the PowerShell operator “like,” looking for the following E-mail addresses [email protected], the PowerShell command display result if she finds SMTP E-mail address that includes that “search string” or SIP address that includes the “search string.”
In case that we use the Comparison Operators “like,” we must use the asterisk character (*)
To be able to define a condition, in which we want to find a text string that “begin” with defined characters, but we don’t know how it “end,” we will add the asterisk character (*) at the end of the text string that we “provide” to the PowerShell command.
To be able to define a condition, in which we want to find a text string that “end” with defined characters, but we don’t know how it “begin,” we will add the asterisk character (*) at the begging of the text string that we “provide” to the PowerShell command.
As we can see in the picture, the PowerShell operator “Like” and the asterisk character (*) are good friends.
Another example of PowerShell operator whom we can use is the operator – “eq” (equal).
When we want to “tell” PowerShell that we want to perform a search that looks for a “perfect match,” we use the operator – “eq” (equal).
For example, in case that we want to look for the following E-mail – [email protected] but display information only if the address is an smtp address, we will use the following PowerShell syntax:
Note – if you fill “overloaded” from all the information and the various searches that we need to perform, I have created a PowerShell menu based script named – Manage E-mail address.ps1, that will simplify the task of searching for an E-mail address with a specific domain name suffix.
Additional reading
About Comparison Operators
Part 3#4 –  the displayed object properties “fields”
Each of the recipient objects such as – Exchange Online mailbox have many properties.
After the Where filter gets the required information, (in our case, an Exchange recipient who answers a specific condition), the “PowerShell output” displays recipient or a recipient list.
Each of the recipients will be displayed + using “predefined object properties.”
Most of the time, we would like to change this “default,” and “inform” PowerShell, what are the specific recipient properties (attributes) that are relevant for us.
For example, in a scenario in which we look for recipients who have a specific E-mail address, the main properties that are relevant for us are:
The recipient name such as – Display name.
The type of the recipient (Recipienttype) such as mailbox user or contact.
The E-mail addresses that are associated with the specific recipient.
To “inform” the PowerShell command, what are the specific properties that we wish to display (or export), we use PowerShell parameters such as – Select, FL (Format List) or FT (Format Table).
Each of the “properties” that we wish to display, will be separated by a comma character.
Part 4#4 – Export the results.
By default, the results from the PowerShell query displayed on the PowerShell console.
Regarding the task of – getting information about Exchange Online recipients E-mail address (or Office 365 UPN name), in many scenarios, we will need to export the information to files.”
Storing the information in files, enable us to “manipulate” the data by using filters, specific views and in addition, edit and manage the data.
To export the information about E-mail address, the was created from the PowerShell Where filter, we will need to provide the specific file type that we need such as – CSV, TXT or HTML.
For your convenience, I have “Wrapped” all the PowerShell commands that were reviewed in the article, in a “Menu Based” PowerShell Script. You are welcome to download the PowerShell script and use it.
Manage E-mail address using PowerShell script
Download Now!2 Downloads
In case that you need instructions about – how to use the Manage E-mail address PowerShell script menu, you can read the fowling Article.
The next article in the current article series
Searching Email addresses with a specific domain name suffix Using PowerShell | Office 365 | Part 10#13
Now it’s Your Turn! It is important for us to know your opinion on this article
Restore Exchange Online mailbox | Article series index
Related Post
Detect spoof E-mail and send an incident report us...
Mail Migration to Office 365 | Measure and estimat...
Disable Access to Service (protocol ) by using Po...
Send E-mail to office 365 using PowerShell script ...
Commercial E-mail – Using the right tools | ...
.yuzo_related_post imgwidth:120px !important; height:110px !important; .yuzo_related_post .relatedthumbline-height:15px;background: !important;color:!important; .yuzo_related_post .relatedthumb:hoverbackground:#fcfcf4 !important; -webkit-transition: background 0.2s linear; -moz-transition: background 0.2s linear; -o-transition: background 0.2s linear; transition: background 0.2s linear;;color:!important; .yuzo_related_post .relatedthumb acolor:!important; .yuzo_related_post .relatedthumb a:hover color:!important;} .yuzo_related_post .relatedthumb:hover a color:!important; .yuzo_related_post .yuzo_text color:!important; .yuzo_related_post .relatedthumb:hover .yuzo_text color:!important; .yuzo_related_post .relatedthumb margin: 0px 0px 0px 0px; padding: 5px 5px 5px 5px; jQuery(document).ready(function( $ ) //jQuery('.yuzo_related_post').equalizer( overflow : 'relatedthumb' ); jQuery('.yuzo_related_post .yuzo_wraps').equalizer( columns : '> div' ); )
0 notes
o365info-blog · 8 years ago
Text
New Post has been published on o365info.com
New Post has been published on http://o365info.com/searching-for-email-addresses-using-powershell-where-filter-office-365-part-9-13/
Searching for an Email addresses using PowerShell | Where Filter | Office 365 | Part 9#13
The current article we review the PowerShell command syntax, that we use for “constructing” a query, for searching specific E-mail address using the PowerShell WhereFilter.
Manage Email addresses | Article Series table of content | Click to expand
Manage Email addresses using PowerShell | Office 365 | Article Series
01 Manage Email addresses using PowerShell | Office 365 | Command reference | Part 1#13 02 Manage Email addresses using PowerShell | Office 365 | Command reference | Part 2#13 03 Adding Email addresses using PowerShell | Office 365 | Part 3#13 04 Adding Email addresses using PowerShell – Bulk mode | Office 365 | Part 4#13 05 Adding Email addresses using PowerShell – Import from CSV file | Bulk mode | Office 365 | Part 5#13 06 Export and display information about Email addresses using PowerShell | Office 365 | Part 6#13 07 Display information about E-mail Addresses using PowerShell | Customizing the output using Hash Table and Custom expressions | Office 365 | Part 7#13 08 Introduction to the various type of Exchange Online recipients | PowerShell cmdlets | Office 365 | Part 8#13 09 Searching for an Email addresses using PowerShell | Where Filter | Office 365 | Part 9#13 10 Searching Email addresses with a specific domain name suffix Using PowerShell | Office 365 | Part 10#13 11 Searching “hidden” Email addresses Using PowerShell | Office 365 | Part 11#13 12 Remove Email addresses using PowerShell | Office 365 | Part 12#13 13 How to use the PowerShell script – manage Email addresses in Office 365 | Part 13#13
The thing that we need to know before we start the search for E-mail address
In this section, I would like to briefly review the main points that relate to the task of performing a search for E-mail addresses in an Office 365 environment.
1. Where to perform the search? As mentioned, in an Office 365 environment is a “mesh” of different environment that constructs the logical term “Office 365.”
The information that we look for can be associated with Office 365 users who are located in the Azure Active Directory or, associated with Exchange Online recipients that are hosted at the Exchange Online infrastructure.
So, the first question that we need to answer is “where” we want to perform the search?
2. Exchange Online | What are the “recipients type” that we want to query? Exchange Online includes a substantial number of different recipient’s type.
In a utopian world, we could use one “magical” PowerShell cmdlet, that will help us to scan and fetch information about all the existing Exchange Online recipients. The reality is a little more complicated because, unfortunately, there is no such command.
To be able to address all the available Exchange Online recipient, we will need to use a “Mixture” of PowerShell cmdlets that will address different types of Exchange Online recipients.
3. The term “E-mail address” In the Office 365 environment, the term “E-mail address,” can be translated to a wide range of “address,” that use an identical naming structure as the “SMTP E-mail address.”
For example,
Office 365 user login name (UPN) is based on the naming structure of smtp E-mail addresses.
SIP address (Skype for business users) uses the same naming structure of smtp E-mail addresses.
What PowerShell syntax to use for performing the search?
In the current article, we will use the PowerShell “Where statement” as a tool for performing a query, that will scan existing Office 365 objects (Office 365 user account and Exchange Online recipient), and “fetch” for us the object that answers specific criteria.
The E-mail address as a “Text string.”
PowerShell offers many methods for implementing the task of – looking for a specific “text string.” In our scenario, the “text string” that we look for is an “E-mail address.” When we say that we are looking for an E-mail address, the term “E-mail address” can be realized as:
The “Left part” of an E-mail address. This is that part that includes the recipient Alias name. We relate to the “left part” of the E-mail address when we look for information about specific Alias name\s.
The “Right part” of an E-mail address. This is the part that includes the domain name suffix. We relate to the “Right part” of E-mail address when we look for information about E-mail address with a specific domain name.
The “right part” + the “left part.” We relate to the booth of the E-mail address parts, in a scenario in which we search for a specific E-mail address.
Using PowerShell for searching a specific E-mail address using the Where statement
In the following diagram, we can see a basic structure of a PowerShell command, in which we look for E-mail addresses that have a specific domain name suffix.
The “PowerShell query” is created by using the Where filter.
The different “parts” of the PowerShell command syntax
Part 1#4 – Exchange Online recipient object
The first part is the part in which we select the specific Exchange Online recipient. In our example, the Exchange recipient “type” is Exchange mailbox.
Part 2#4 – The Where filter
In this part, we use the PowerShell “Where” statement + the definition of the “query filter” or in other words- the “search condition.”
The PowerShell Where statement, include the following parts:
To perform the required search, that defines a condition in which we search only for E-mail address that has a specific character such as – specific domain name suffix, we use the PowerShell statement – “Where”
The PowerShell query “resides” between the curly brackets.
In our scenario, we query the Azure Active Directory infrastructure + Exchange Online infrastructure.
When we query Exchange Online infrastructure, we “address” the Exchange Online recipient property named – “EmailAddresses”.
When we query Azure Active Directory infrastructure, we “address” the Office 365 user property named – “UserPrincipalName” and the property “ProxyAddresses“.
The PowerShell operator whom we use.
In a scenario in which we look for a specific E-mail address, we can choose a couple of options of the “PowerShell operators” that we use.
For example, we can use the PowerShell operator – “eq” (equal) or the PowerShell operator “like.”
The PowerShell operator “Like” as the name implies, we search for E-mail addresses that are “like” the E-mail address that we provide.
In our specific scenario, an Exchange Online recipient could “use” the specific E-mail address as an “SMTP E-mail address” or “SIP address.”
For example, when using the PowerShell operator “like,” looking for the following E-mail addresses [email protected], the PowerShell command display result if she finds SMTP E-mail address that includes that “search string” or SIP address that includes the “search string.”
In case that we use the Comparison Operators “like,” we must use the asterisk character (*)
To be able to define a condition, in which we want to find a text string that “begin” with defined characters, but we don’t know how it “end,” we will add the asterisk character (*) at the end of the text string that we “provide” to the PowerShell command.
To be able to define a condition, in which we want to find a text string that “end” with defined characters, but we don’t know how it “begin,” we will add the asterisk character (*) at the begging of the text string that we “provide” to the PowerShell command.
As we can see in the picture, the PowerShell operator “Like” and the asterisk character (*) are good friends.
Another example of PowerShell operator whom we can use is the operator – “eq” (equal).
When we want to “tell” PowerShell that we want to perform a search that looks for a “perfect match,” we use the operator – “eq” (equal).
For example, in case that we want to look for the following E-mail – [email protected] but display information only if the address is an smtp address, we will use the following PowerShell syntax:
Note – if you fill “overloaded” from all the information and the various searches that we need to perform, I have created a PowerShell menu based script named – Manage E-mail address.ps1, that will simplify the task of searching for an E-mail address with a specific domain name suffix.
Additional reading
About Comparison Operators
Part 3#4 –  the displayed object properties “fields”
Each of the recipient objects such as – Exchange Online mailbox have many properties.
After the Where filter gets the required information, (in our case, an Exchange recipient who answers a specific condition), the “PowerShell output” displays recipient or a recipient list.
Each of the recipients will be displayed + using “predefined object properties.”
Most of the time, we would like to change this “default,” and “inform” PowerShell, what are the specific recipient properties (attributes) that are relevant for us.
For example, in a scenario in which we look for recipients who have a specific E-mail address, the main properties that are relevant for us are:
The recipient name such as – Display name.
The type of the recipient (Recipienttype) such as mailbox user or contact.
The E-mail addresses that are associated with the specific recipient.
To “inform” the PowerShell command, what are the specific properties that we wish to display (or export), we use PowerShell parameters such as – Select, FL (Format List) or FT (Format Table).
Each of the “properties” that we wish to display, will be separated by a comma character.
Part 4#4 – Export the results.
By default, the results from the PowerShell query displayed on the PowerShell console.
Regarding the task of – getting information about Exchange Online recipients E-mail address (or Office 365 UPN name), in many scenarios, we will need to export the information to files.”
Storing the information in files, enable us to “manipulate” the data by using filters, specific views and in addition, edit and manage the data.
To export the information about E-mail address, the was created from the PowerShell Where filter, we will need to provide the specific file type that we need such as – CSV, TXT or HTML.
For your convenience, I have “Wrapped” all the PowerShell commands that were reviewed in the article, in a “Menu Based” PowerShell Script. You are welcome to download the PowerShell script and use it.
Manage E-mail address using PowerShell script
Download Now!2 Downloads
In case that you need instructions about – how to use the Manage E-mail address PowerShell script menu, you can read the fowling Article.
The next article in the current article series
Searching Email addresses with a specific domain name suffix Using PowerShell | Office 365 | Part 10#13
Now it’s Your Turn! It is important for us to know your opinion on this article
Restore Exchange Online mailbox | Article series index
Related Post
Implementing SPF Fail policy using Exchange Online...
Autodiscover flow in an Exchange Hybrid environmen...
Cutover Migration – Links and Resources
Manage Distribution Group using PowerShell in Offi...
Configure your WordPress site to send E-mail via E...
.yuzo_related_post imgwidth:120px !important; height:110px !important; .yuzo_related_post .relatedthumbline-height:15px;background: !important;color:!important; .yuzo_related_post .relatedthumb:hoverbackground:#fcfcf4 !important; -webkit-transition: background 0.2s linear; -moz-transition: background 0.2s linear; -o-transition: background 0.2s linear; transition: background 0.2s linear;;color:!important; .yuzo_related_post .relatedthumb acolor:!important; .yuzo_related_post .relatedthumb a:hover color:!important;} .yuzo_related_post .relatedthumb:hover a color:!important; .yuzo_related_post .yuzo_text color:!important; .yuzo_related_post .relatedthumb:hover .yuzo_text color:!important; .yuzo_related_post .relatedthumb margin: 0px 0px 0px 0px; padding: 5px 5px 5px 5px; jQuery(document).ready(function( $ ) //jQuery('.yuzo_related_post').equalizer( overflow : 'relatedthumb' ); jQuery('.yuzo_related_post .yuzo_wraps').equalizer( columns : '> div' ); )
0 notes
o365info-blog · 8 years ago
Text
New Post has been published on o365info.com
New Post has been published on http://o365info.com/searching-for-email-addresses-using-powershell-where-filter-office-365-part-9-13/
Searching for an Email addresses using PowerShell | Where Filter | Office 365 | Part 9#13
The current article we review the PowerShell command syntax, that we use for “constructing” a query, for searching specific E-mail address using the PowerShell WhereFilter.
Manage Email addresses | Article Series table of content | Click to expand
Manage Email addresses using PowerShell | Office 365 | Article Series
01 Manage Email addresses using PowerShell | Office 365 | Command reference | Part 1#13 02 Manage Email addresses using PowerShell | Office 365 | Command reference | Part 2#13 03 Adding Email addresses using PowerShell | Office 365 | Part 3#13 04 Adding Email addresses using PowerShell – Bulk mode | Office 365 | Part 4#13 05 Adding Email addresses using PowerShell – Import from CSV file | Bulk mode | Office 365 | Part 5#13 06 Export and display information about Email addresses using PowerShell | Office 365 | Part 6#13 07 Display information about E-mail Addresses using PowerShell | Customizing the output using Hash Table and Custom expressions | Office 365 | Part 7#13 08 Introduction to the various type of Exchange Online recipients | PowerShell cmdlets | Office 365 | Part 8#13 09 Searching for an Email addresses using PowerShell | Where Filter | Office 365 | Part 9#13 10 Searching Email addresses with a specific domain name suffix Using PowerShell | Office 365 | Part 10#13 11 Searching “hidden” Email addresses Using PowerShell | Office 365 | Part 11#13 12 Remove Email addresses using PowerShell | Office 365 | Part 12#13 13 How to use the PowerShell script – manage Email addresses in Office 365 | Part 13#13
The thing that we need to know before we start the search for E-mail address
In this section, I would like to briefly review the main points that relate to the task of performing a search for E-mail addresses in an Office 365 environment.
1. Where to perform the search? As mentioned, in an Office 365 environment is a “mesh” of different environment that constructs the logical term “Office 365.”
The information that we look for can be associated with Office 365 users who are located in the Azure Active Directory or, associated with Exchange Online recipients that are hosted at the Exchange Online infrastructure.
So, the first question that we need to answer is “where” we want to perform the search?
2. Exchange Online | What are the “recipients type” that we want to query? Exchange Online includes a substantial number of different recipient’s type.
In a utopian world, we could use one “magical” PowerShell cmdlet, that will help us to scan and fetch information about all the existing Exchange Online recipients. The reality is a little more complicated because, unfortunately, there is no such command.
To be able to address all the available Exchange Online recipient, we will need to use a “Mixture” of PowerShell cmdlets that will address different types of Exchange Online recipients.
3. The term “E-mail address” In the Office 365 environment, the term “E-mail address,” can be translated to a wide range of “address,” that use an identical naming structure as the “SMTP E-mail address.”
For example,
Office 365 user login name (UPN) is based on the naming structure of smtp E-mail addresses.
SIP address (Skype for business users) uses the same naming structure of smtp E-mail addresses.
What PowerShell syntax to use for performing the search?
In the current article, we will use the PowerShell “Where statement” as a tool for performing a query, that will scan existing Office 365 objects (Office 365 user account and Exchange Online recipient), and “fetch” for us the object that answers specific criteria.
The E-mail address as a “Text string.”
PowerShell offers many methods for implementing the task of – looking for a specific “text string.” In our scenario, the “text string” that we look for is an “E-mail address.” When we say that we are looking for an E-mail address, the term “E-mail address” can be realized as:
The “Left part” of an E-mail address. This is that part that includes the recipient Alias name. We relate to the “left part” of the E-mail address when we look for information about specific Alias name\s.
The “Right part” of an E-mail address. This is the part that includes the domain name suffix. We relate to the “Right part” of E-mail address when we look for information about E-mail address with a specific domain name.
The “right part” + the “left part.” We relate to the booth of the E-mail address parts, in a scenario in which we search for a specific E-mail address.
Using PowerShell for searching a specific E-mail address using the Where statement
In the following diagram, we can see a basic structure of a PowerShell command, in which we look for E-mail addresses that have a specific domain name suffix.
The “PowerShell query” is created by using the Where filter.
The different “parts” of the PowerShell command syntax
Part 1#4 – Exchange Online recipient object
The first part is the part in which we select the specific Exchange Online recipient. In our example, the Exchange recipient “type” is Exchange mailbox.
Part 2#4 – The Where filter
In this part, we use the PowerShell “Where” statement + the definition of the “query filter” or in other words- the “search condition.”
The PowerShell Where statement, include the following parts:
To perform the required search, that defines a condition in which we search only for E-mail address that has a specific character such as – specific domain name suffix, we use the PowerShell statement – “Where”
The PowerShell query “resides” between the curly brackets.
In our scenario, we query the Azure Active Directory infrastructure + Exchange Online infrastructure.
When we query Exchange Online infrastructure, we “address” the Exchange Online recipient property named – “EmailAddresses”.
When we query Azure Active Directory infrastructure, we “address” the Office 365 user property named – “UserPrincipalName” and the property “ProxyAddresses“.
The PowerShell operator whom we use.
In a scenario in which we look for a specific E-mail address, we can choose a couple of options of the “PowerShell operators” that we use.
For example, we can use the PowerShell operator – “eq” (equal) or the PowerShell operator “like.”
The PowerShell operator “Like” as the name implies, we search for E-mail addresses that are “like” the E-mail address that we provide.
In our specific scenario, an Exchange Online recipient could “use” the specific E-mail address as an “SMTP E-mail address” or “SIP address.”
For example, when using the PowerShell operator “like,” looking for the following E-mail addresses [email protected], the PowerShell command display result if she finds SMTP E-mail address that includes that “search string” or SIP address that includes the “search string.”
In case that we use the Comparison Operators “like,” we must use the asterisk character (*)
To be able to define a condition, in which we want to find a text string that “begin” with defined characters, but we don’t know how it “end,” we will add the asterisk character (*) at the end of the text string that we “provide” to the PowerShell command.
To be able to define a condition, in which we want to find a text string that “end” with defined characters, but we don’t know how it “begin,” we will add the asterisk character (*) at the begging of the text string that we “provide” to the PowerShell command.
As we can see in the picture, the PowerShell operator “Like” and the asterisk character (*) are good friends.
Another example of PowerShell operator whom we can use is the operator – “eq” (equal).
When we want to “tell” PowerShell that we want to perform a search that looks for a “perfect match,” we use the operator – “eq” (equal).
For example, in case that we want to look for the following E-mail – [email protected] but display information only if the address is an smtp address, we will use the following PowerShell syntax:
Note – if you fill “overloaded” from all the information and the various searches that we need to perform, I have created a PowerShell menu based script named – Manage E-mail address.ps1, that will simplify the task of searching for an E-mail address with a specific domain name suffix.
Additional reading
About Comparison Operators
Part 3#4 –  the displayed object properties “fields”
Each of the recipient objects such as – Exchange Online mailbox have many properties.
After the Where filter gets the required information, (in our case, an Exchange recipient who answers a specific condition), the “PowerShell output” displays recipient or a recipient list.
Each of the recipients will be displayed + using “predefined object properties.”
Most of the time, we would like to change this “default,” and “inform” PowerShell, what are the specific recipient properties (attributes) that are relevant for us.
For example, in a scenario in which we look for recipients who have a specific E-mail address, the main properties that are relevant for us are:
The recipient name such as – Display name.
The type of the recipient (Recipienttype) such as mailbox user or contact.
The E-mail addresses that are associated with the specific recipient.
To “inform” the PowerShell command, what are the specific properties that we wish to display (or export), we use PowerShell parameters such as – Select, FL (Format List) or FT (Format Table).
Each of the “properties” that we wish to display, will be separated by a comma character.
Part 4#4 – Export the results.
By default, the results from the PowerShell query displayed on the PowerShell console.
Regarding the task of – getting information about Exchange Online recipients E-mail address (or Office 365 UPN name), in many scenarios, we will need to export the information to files.”
Storing the information in files, enable us to “manipulate” the data by using filters, specific views and in addition, edit and manage the data.
To export the information about E-mail address, the was created from the PowerShell Where filter, we will need to provide the specific file type that we need such as – CSV, TXT or HTML.
For your convenience, I have “Wrapped” all the PowerShell commands that were reviewed in the article, in a “Menu Based” PowerShell Script. You are welcome to download the PowerShell script and use it.
Manage E-mail address using PowerShell script
Download Now!2 Downloads
In case that you need instructions about – how to use the Manage E-mail address PowerShell script menu, you can read the fowling Article.
The next article in the current article series
Searching Email addresses with a specific domain name suffix Using PowerShell | Office 365 | Part 10#13
Now it’s Your Turn! It is important for us to know your opinion on this article
Restore Exchange Online mailbox | Article series index
Related Post
What is SPF record good for? | Part 7#17
Exchange Force TLS | Troubleshooting and verifying...
Setting up an Automatic Reply in Office 365 using ...
Restore Exchange Online Shared mailbox | Cloud onl...
Autodiscover flow in an Office 365 environment | P...
.yuzo_related_post imgwidth:120px !important; height:110px !important; .yuzo_related_post .relatedthumbline-height:15px;background: !important;color:!important; .yuzo_related_post .relatedthumb:hoverbackground:#fcfcf4 !important; -webkit-transition: background 0.2s linear; -moz-transition: background 0.2s linear; -o-transition: background 0.2s linear; transition: background 0.2s linear;;color:!important; .yuzo_related_post .relatedthumb acolor:!important; .yuzo_related_post .relatedthumb a:hover color:!important;} .yuzo_related_post .relatedthumb:hover a color:!important; .yuzo_related_post .yuzo_text color:!important; .yuzo_related_post .relatedthumb:hover .yuzo_text color:!important; .yuzo_related_post .relatedthumb margin: 0px 0px 0px 0px; padding: 5px 5px 5px 5px; jQuery(document).ready(function( $ ) //jQuery('.yuzo_related_post').equalizer( overflow : 'relatedthumb' ); jQuery('.yuzo_related_post .yuzo_wraps').equalizer( columns : '> div' ); )
0 notes