Advanced Windows PowerShell Scripting Video Training

Advanced Windows PowerShell Scripting Video Training
Advanced Windows PowerShell Scripting Video Training

Thursday, May 14, 2015

How to Hide a Mailbox from Exchange’s Global Address List

Good thing I fired up an Exchange server this week’s for my PowerShell class.  Here is a quick answer to a problem one of the my class attendees had.  How to hide someone from the Global Address List (GAL) using PowerShell.  In the Exchange Admin Center, you can configure this in the user’s mailbox general properties.

image

We had a discussion about what is in the GUI and what is in PowerShell. The direction that Microsoft is moving is a GUI free environment, at least on the servers.  PowerShell is designed to do what the GUI can, and cannot do.  We simply need to find the path.  Fortunately, the path to success on this one was simple.

1

2

Get-Mailbox -Identity jyoder |

Set-Mailbox -HiddenFromAddressListsEnabled $True

Line 1 will get the mailbox object of the user in question and pipe the object to line 2.

Line 2 uses the Set-Mailbox cmdlet and it’s HiddenFromAddressListEnabled property.  When set to $True, the address is hidden.  Let’s take a look at the results in Outlook.

Before executing this code, you can see that I was able to successfully find my email address in the GAL.

image

And this is the result after.

image

If you try to set the property to a setting that it already has, you will receive this message:

WARNING: The command completed successfully but no settings of 'Adatum.com/Users/Jason A. Yoder' have been modified.

 

Wednesday, May 13, 2015

Listing Public Folder Permissions with PowerShell

We started off class this morning in a Q&A session.  One of the questions was how to get the public folder permissions on an Exchange Server.  In this example, Exchange Server 2013 is being used.

1

2

Get-PublicFolder -Recurse |

    Get-PublicFolderClientPermission

Line 1 Gathers all of the Public folder objects, including subfolders.

Line 2 Gathers the user rights on each public folder and then displays them

FolderName           User                 AccessRights                                                     

----------           ----                 ------------                                                     

IPM_SUBTREE          Default              {Author}                                                         

IPM_SUBTREE          Anonymous            {None}                                                           

Folder1              Default              {Author}                                                         

Folder1              Anonymous            {None}                                                           

Folder2              Default              {Author}                                                         

Folder2              Anonymous            {None}                                                           

FolderA              Default              {Author}                                                         

FolderA              Anonymous            {None}                                                           

Folder1A             Default              {Author}                                                         

Folder1A             Anonymous            {None}                                                           

Folder2A             Default              {Author}                                                         

Folder2A             Anonymous            {None}                                                           

FolderB              Default              {Author}                                                         

FolderB              Anonymous            {None}       

 

According to the Add-PublicFolderClientPermissions cmdlet help file, here are the access rights that can be assigned.

Access Right Description
ReadItems The user has the right to read items within the specified public folder.
CreateItems The user has the right to create items within the specified public folder.
EditOwnedItems

The user has the right to edit the items that the user owns in the specified public folder.

DeleteOwnedItems

The user has the right to delete items that the user owns in the specified public folder.

EditAllItems The user has the right to edit all items in the specified public folder.
DeleteAllItems The user has the right to delete all items in the specified public folder.
CreateSubfolders The user has the right to create subfolders in the specified public folder.
FolderOwner The user is the owner of the specified public folder. The user has the right to view and move the public folder and create subfolders. The user can't read items, edit items, delete items, or create items.
FolderContact The user is the contact for the specified public folder.
FolderVisible The user can view the specified public folder, but can't read or edit items within the specified public folder.

 

You can also create rights based on roles.

Role Access Rights
None FolderVisible
Owner CreateItems, ReadItems, CreateSubfolders, FolderOwner, FolderContact, FolderVisible, EditOwnedItems, EditAllItems, DeleteOwnedItems, DeleteAllItems
PublishingEditor CreateItems, ReadItems, CreateSubfolders, FolderVisible, EditOwnedItems, EditAllItems, DeleteOwnedItems, DeleteAllItems
Editor CreateItems, ReadItems, FolderVisible, EditOwnedItems, EditAllItems, DeleteOwnedItems, DeleteAllItems
PublishingAuthor CreateItems, ReadItems, CreateSubfolders, FolderVisible, EditOwnedItems, DeleteOwnedItems
Author CreateItems, ReadItems, FolderVisible, EditOwnedItems, DeleteOwnedItems
NonEditingAuthor CreateItems, ReadItems, FolderVisible
Reviewer ReadItems, FolderVisible
Contributor CreateItems, FolderVisible

Tuesday, May 12, 2015

Accuracy problem with System.Double and System.Single

So, what do I do while my class is working on labs?  Well, if I’m not answer emails from the Navy, I’m working on some side projects.  Right now, I’m working on a project to grab meta data via geographical coordinates. When I develop code, I brake the objective down into manageable parts.  I then look at each part and ask myself if I know how to do it.  For each part that I do not know how, I start writing code to discover the path to success.

Well, while working on a bit of code, I needed to increment my value for latitude by .05.  Something odd happened so I wrote out a small bit of code to focus in on the issue.  Here is the code.

$Increment = .05

$Start = 0

$Value2 = $Start

 

While ($Value2 -lt 10)

{

    Write-host $Value2

    $Value2 += $Increment

}

The data type of $Value2 is Double.  Everything starts out fine.

0

0.05

0.1

0.15

0.2

Until…

3.45

3.5

3.55

3.6

3.65

3.69999999999999

3.74999999999999

3.79999999999999

3.84999999999999

 

Why System.Double start incrementing in .049999999999999 and then back to .05 later on, I do not know.  OK, let’s force the variable to be System.Single

0

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

0.45

0.5000001

0.5500001

0.6000001

0.6500001

 

OK, now it increments by 0.050001 and then back to .05. 

Luckily, I found a data type that does not loose it’s accuracy under these conditions, System.Decimal.

$Increment = .05

$Start = 0

[Decimal]$Value4 = $Start

 

While ($Value4 -lt 10)

{

    Write-host $Value4

    $Value4 += $Increment

 

 

}

$Value4 | GM

 

Below is a sample of the desired output.

0

0.05

0.10

0.15

0.20

0.25

0.30

0.35

0.40

0.45

0.50

0.55

0.60

0.65

0.70

0.75

0.80

 

I took a look at System.Double on MSDN. According to Microsoft, System.Double coheres to the standard for binary floating-point arithmetic. (See the Remarks section).  Since some fractional values cannot be represented precisely.  Look at System.Decimal.  In the Remarks section, you will see that it dose not have a round off error.  At least not at the precision level that I need.

I now need to decide between the smaller memory footprint of Single or Double data types as compared to the much larger storage requirement of Decimal.  It looks like that I will be computing the Longitude and Latitude values in Decimal, But using the –as operator in PowerShell to convert them into Single for storage since I do not need to go beyond 2 decimal places.

[Decimal]$Decimal = 5.5

$Single = $Decimal -as [Single]

$Single

 

The result will be a Single value that will have the precision that I need with a smaller memory footprint.

Monday, May 11, 2015

Listing Public Folders in Exchange Server

This weekend I built an entirely new virtual environment for my PowerShell classes moving forward.  Essentially I did this to add in some SQL, Exchange and DSC scenarios.  Just in time to.  I have two Exchange administrators in my PowerShell class this week here in Fort Wayne so I am using my new setup to enhance the class.  Here is the first one.

How do I let all of the public folders, including sub folders?

The Get-PublicFolder cmdlet can be used for this.  Here is the public folder structure that I created using the New-PublicFolder cmdlet.

Level 1 Level 2 Level 3
Folder1    
Folder2    
  FolderA  
    Folder1A
    Folder2A
  FolderB  

This command will recover all the public folders and their parents.

PS C:> Get-PublicFolder -Recurse | Select -Property name,parentpath

 

Name        ParentPath     

----        ----------     

IPM_SUBTREE                

Folder1     \              

Folder2     \              

FolderA     \Folder2       

Folder1A    \Folder2\FolderA

Folder2A    \Folder2\FolderA

FolderB     \Folder2

 

The second question is how to filter for public folders within a parent folder?

PS C:\> Get-PublicFolder -Recurse |

    Where-Object {$_.ParentPath -like "*Folder2*"} |

    Select -Property name,parentpath

 

Name     ParentPath     

----     ----------     

FolderA  \Folder2       

Folder1A \Folder2\FolderA

Folder2A \Folder2\FolderA

FolderB  \Folder2  

 

Here we are using The Where-Object cmdlet to filter the ParentPath property.  The Value of ParentPath is a string.  In this example, we are looking for any folder inside of Folder2.

Another option utilizes the FolderPath property.  The FolderPath property is an array of strings. 

PS C:\> Get-PublicFolder -Recurse |

    Select-Object -Property Name, FolderPath |

    Where-Object {$_.FolderPath -contains "Folder2"}

 

Name     FolderPath                 

----     ----------                 

Folder2  {Folder2}                  

FolderA  {Folder2, FolderA}         

Folder1A {Folder2, FolderA, Folder1A}

Folder2A {Folder2, FolderA, Folder2A}

FolderB  {Folder2, FolderB

 

This output also contains the root folder in the query, Folder2

More to come as we continue this week.

Wednesday, May 6, 2015

Working on my first build of Windows Server Tech Preview 2

Already integrated into my PowerShell code for rapidly building new VMs.

image

Any GUI only admins out there getting nervous yet?

image

There you have it!!!  Your interface.

image

OK, for those of you who have taken my PowerShell classes, just type PowerShell and press Enter.

Look, colorization in the shell!!!

image

Don’t worry, SCONFIG still works.  For those of you from my server classes, you know what to do at this point.

I’m going to play for a while.  Have fun everybody with the preview!

Friday, May 1, 2015

Working around “Always On Top” or “Always in Focus” Windows Issue

This has been a problem since I had Windows 8 on a very expensive laptop.  I’ve heard of it on Windows 7, but never had the pleasure of being introduced to the problem.  After I upgraded to Windows 8.1, I still had the problem.  The first time this happened was particularly embarrassing. I popped up while teaching a Windows class online.  Of course a new bug pops up when you are in front of the public.  Here is what is going on.

I open multiple windows, like most over achievers.  All of the sudden, one window will not lose focus and fall behind the others.  Up until now, the only way to work around this issue was to do one of two things.  Minimize the problematic window or close and re-open the application.  Since I like to switch between applications using Alt-Tab, this was a no go for me.  Unfortunately, it was my only option.

I just discovered this fix.  With the problematic window in focus, press Ctrl-Alt-Esc. No idea why, but the Window started to play nice again.  Give it a try.  I am a lot happier now.