Archive

Posts Tagged ‘powershell’

Managing Office 365 and Exchange Online with Windows PowerShell

February 17, 2016 Leave a comment

Get a list of Office365 users with License attached, Primary SMTP address and Aliases


To get an list of all users that has an Office365 license assigned and with Displayname, Primary SMTP address and all other adresses registrated on the users use this one-liner in PowerShell! 🙂

get-mailbox | Where-Object {$_.SKUAssigned -eq “TRUE”} | Select-Object Displayname, PrimarySMTPAddress, EmailAddresses | Export-Csv c:\temp\noah2.csv -Encoding UTF8

Allow external senders in Public folder – Office365


Public folders are set to NOT allow external senders to public folders in Office 365. This can be fixed using the following receipt:

Conncect to the Windows Azure Active Directory Module for Windows PowerShell using the following commands.
Create a placeholder for your credentials:
$LiveCred = Get-Credential

Popup box will ask for your Office 365 Global Administrator credentials.

Create a placeholder for your Powershell Session towards Exchange Online.
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection

Import your Powershell Session to connect to Exchange Online.
Import-PSSession $Session

Run this command to allow all scripts:
set-executionpolicy unrestricted

Then the public folder part
Add-PublicFolderClientPermission \(Path of the Public folder name) -User Anonymous -AccessRights CreateItems

Change Default emailadress on Public folder in Office365


The problem:
A public folder in Office 365 Hosted Exchange will be assigned a @onmicrosoft.com address by default. And there is of cource no way of changing this to your primary domain.

Solution:
Conncect to the Windows Azure Active Directory Module for Windows PowerShell using the following commands.
Create a placeholder for your credentials:
$LiveCred = Get-Credential

Popup box will ask for your Office 365 Global Administrator credentials.

Create a placeholder for your Powershell Session towards Exchange Online.
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection

Import your Powershell Session to connect to Exchange Online.
Import-PSSession $Session

Run this command to allow all scripts:
set-executionpolicy unrestricted

Then run the following command to disable the Policy for assigning email Adresses in public folders.
Set-MailPublicFolder -Identity “\” -EmailAddressPolicyEnabled $False

Now, in your Office 365 tennant web admin go to Exchange – Public Folders – Highlight the public folder (email enabled) – Click the pencil (edit) – Click on Email Address – highlight the address you want to use as default – Click pencil – Check the default email address checkbox.
Save, close and test.

Find unlinked GPOs in your domain


Have you ever wondered if your domain has any GPO without a link and which GPO that would be? This is how you find out with Powershell with output to the screen.


$unlinkedGPOs = (Get-GPO -all | where {([xml]($_ | Get-GPOReport -ReportType XML)).gpo.LinksTo.Length -eq 0})
Write-Host "The following GPO has no link:"
$unlinkedGPOs| ft DisplayName -HideTableHeaders
Write-Host "Total: $($unlinkedGPOs.Count)"

Prevent write-output to perform linebreak

November 20, 2014 Leave a comment

Sometimes you want to output some text and append an variable. Problem is that write-output usually performs a linebrak when appending.


$text = "some text."
Write-Output "this is " $text

Output will be:
this is
some text.

There are two ways you can solve this. One is to append the text to the variable before doing write-output. Second is to put the variable inside the quotation marks.


#Example 1
$text = "some text."
$textmessage = "This is " + $text
Write-Output $textmessage

#Example 2
$text = "some text."
Write-Output "this is $($text)"

Find domain admins with password never expires


Do you know how many domain admins you have in your domain? Do you know which domain admins are running with “password never expires” enabled? Thanks to Powershell it is easy to find out.


# Variables below
#
$domainadmins=(Get-ADGroupMember -Identity "Domain admins" | Get-ADUser -Properties PasswordNeverexpires, lastlogondate)
#*********************************************************************************************
# Output to screen
$domainadmins | Sort -Descending -Property PasswordNeverexpires | Select-Object Name, Samaccountname, lastlogondate, Enabled, PasswordNeverExpires | ft -autosize
#

This will display on your screen all members in “Domain Admins” with the last logon time, if the account is enabled and if the “password never expires” is set.

If you want a file export you can use this line instead of output to screen:


# Output to file
$domainadmins | Sort -Descending -Property PasswordNeverexpires | Select-Object Name, Samaccountname, lastlogondate, Enabled, PasswordNeverExpires | Export-Csv C:\Temp\domainadmins.csv -Encoding UTF8 -Delimiter ","

%d bloggers like this: