Advanced Windows PowerShell Scripting Video Training

Thursday, May 14, 2015

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.

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-Identityjyoder|

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.

And this is the result after.

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.

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.

Tuesday, May 12, 2015

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-lt10)

{

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-lt10)

{

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

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

NameParentPath

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

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

NameParentPath

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

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.

Friday, May 1, 2015

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.