String Theory

Mastering the laws of physics with Windows PowerShell

A few days ago I posted the question online of how I could change the Windows 7 theme using any automated method such as .Net or even C++ which I could call from Windows PowerShell. Although I was unable to locate a solution to the problem, PowerShell version 3 did offer a compromise.

 

Figure 1: Get-ControlPanelItem (Click image for full-size.)

 

In version 3 (CTP2) two new cmdlets were added that allow interaction with the Windows Control Panel. The first cmdlet, Get-ControlPanelItem allows you to list all of the control panel applets in your system. It accepts three different parameters that allow you to retrieve the items that you want: Name, CanonicalName, and Category. The categories are the same as when you view the Control Panel in category view.

Demonstrating Get-ControlPanelItem

Figure 2: Show-ControlPanelItem (Click image for full-size.)

The second cmdlet added was Show-ControlPanelItem. As you can guess from the name it shows the specified Control Panel applet. As shown in Figure 2, you can specify either the Name or CanonicalName directly or you can pass the output from Get-ControlPanelItem. When executed the control panel applet is shown.

In my case I could not find a way to automatically set the Windows 7 theme, but I was able to use Show-ControlPanelItem Personalization to present the user with the dialog box to allow them to change the theme manually. It wasn’t the solution I was looking for but it still made the task easier to accomplish.

 

 

 

 

 

Enhanced by Zemanta

One of the nice things that has changed with PowerShell Version 3 as of CTP 2 is the way that the registry is displayed. In PowerShell Version 3, the PowerShell team updated the format files for the registry provider. To see this difference first do a directory listing for HKCU: in version 2. You will get a similar output to Figure 1.

Listing of HKCU: in PowerShell Version 2

Figure 1: Listing of HKCU: in PowerShell Version 2 (Click image for full-size)

As you can see the listing is compact and actually somewhat hard to read, especially if you are interested in the properties. Now, perform the same action in version 3. You will be presented with the output similar to Figure 2.

Listing of HKCU: in PowerShell Version 3

Figure 2: Listing of HKCU: in PowerShell Version 3 (Click image for full-size)

As you can see the display is longer and isn’t completely captured in the screenshot. You will notice though, that it is much easier to read and you can view the values for each property very cleanly. This makes using PowerShell to navigate the registry so much easier and is a definite plus to the language.

Disclaimer: This post covered PowerShell Version 3 CTP 2. Since this is a pre-release version, there is a possibility that the features described herein will be changed or completely removed from the final product.

Imagine the scenario: You are working on a script or command in your PowerShell session and you need to get help on a cmdlet. Sure, you have tab completion, but you can’t remember whether the parameter takes a string or an object, or you can’t remember how the value should be formatted. So you break out the ever helpful (haha) get-help cmdlet.

Get-help provides you the information, but now you have to get back to your command. You start typing the command and realize you need more information. You either have to scroll up or rerun get-help. Wouldn’t it be nice if you could just have the help in a separate window that you can reference for as long as you need it?

Well it should be no surprise that you can display help in a separate window. Otherwise I wouldn’t have anything to write about, right? In version 3, Get-Help has a new parameter, -ShowWindow. As you can imagine -ShowWindow presents the help contents in a new, separate window as shown in Figure 1.

Get-Help -ShowWindow

Figure 1: Get-Help -ShowWindow (Click image for full-size)

Now you can continue editing your command AND have the help right there where you need it. Furthermore, you can search the help and customize the output to include/exclude the section you want by clicking on the Settings button as shown in Figure 2.

ShowWindowOptions

Figure 2: Get-Help -ShowWindow Options. (Click image for full-size)

Disclaimer: This post covered PowerShell Version 3 CTP 2. Since this a pre-release version, there is a possibility that the the features described herein will be changed or completely removed from the final product.

Not too long ago I was filling out an “achievement” form for an award that I want to obtain. This award was based on your community presence and how well you engaged the community to spread the value of the award’s intended purpose. One of the questions asked was your twitter username and how many followers you had.

Every day I receive at least one user following me that is either a local business, some “hot chick” looking for a lonely guy, or someone selling some device at ridiculously low prices. Each and every time I reach for the spam link to report them, I think about that form. Do I  block them because they probably have no interest in what I have to say, or do I let them follow so they can pad my follower count? We are talking about the possibility of hundreds of additional followers.

Most of the time I just report them for spam but I always have to think about it first. To me this is just the social version of “What certifications do you have?” Most certification exams are no more than just a test of how well you can memorize something, not how well you know a subject. Saying you have a lot of followers just means you know a lot of people. Maybe the better question is: Who are your followers? Quality over quantity.

The AppSense Environment Manager can provide you with valuable information related to the processes involved in login and logoff . Using Windows PowerShell you can easily retrieve this information to assist you in identifying problem spots.

continue reading…

Starting with an innocent conversation a little over 15 months ago, I agreed to co-author a book on Windows PowerShell. I had no idea what I was getting into nor the amount of work it was going to entail. It was a very long and detailed process, but I can finally say it was all absolutely worth it.

The book is in its final stages and we are looking at a September or October release date. As you can see from the image to the left we have our book cover. This is the part I was most looking forward to.

I am especially proud to have been able to use my experience and knowledge to dedicate individual chapters to Citrix XenApp 6 and  to Citrix XenDesktop 5. My goal from the beginning of this project was to include these topics because I felt they hadn’t been addressed in any other resource appropriately. These chapters are only a beginning and I look forward to expanding on the information contained.

If you haven’t yet seen the new PowerShellGroup.org site I would recommend that you take a look.  Joel Bennett and I have been working very hard to migrate the system from the old site to the new one. It wasn’t an easy process, but I can honestly say that I am proud of the new site. With the new host I haven’t seen a single “Page Not Found”.

The new User Group map is the feature that I am most proud of. When I was preparing my proposal for taking over the site it was the feature that I wanted the most. The were two questions that were prevalent at the Scripting Guys booth during MSTechEd here in Atlanta:

  1. Is there a PowerShell user group where I live?
  2. How can I start my own PowerShell user group.

The User Group map answers that first question. As to the second question: stay tuned. I will be starting work on a ‘New User Group’ welcome packet that provides all of the resources you need to start your very own user group.

With the book completed and more free time, I am working hard to complete everything I have postponed and become an active member of the PowerShell community once again.

I am delighted beyond belief to be able to announce that I get to be an honorary Scripting imageGuys team member, at least for a week.  I received an email earlier this week from Ed Wilson himself asking whether I would be interested in helping @ScriptingGuys and @ScriptingWife staff the Script Center booth at MS TechEd 2011 in Atlanta May 16-19, 2011. After picking myself up off of the floor and having my wife verify what I read, I immediately accepted the invitation.

I am so excited about this opportunity because not only do I get to work a booth with The Scripting Guy himself and The Scripting Wife, but that I am going to get to meet so many great people and spread the word of Windows PowerShell. If you are attending TechEd please stop by the booth and say hello. Feel free to add me as a contact on MyTechEd.

If you use VisionApp Remote Desktop in your environment then you know it’s an extremely valuable tool. If you are not familiar with it then here is a snippet from the product’s website.

visionapp Remote Desktop makes it easy to manage remote connections to Windows-based systems. Administrators who need to maintain simultaneous connections to multiple systems can create and organize Connection-specific settings and login credentials for quick access and simplified day-to-day use.

It’s a life-saver for admins by allowing you to maintain multiple tabbed connections to a whole library of SSH, ICA, RDP, VNC, and Telnet with saved credentials.  I have used it for many years now, but I finally realized one of its other great hidden potentials.

In the application you can create “External Applications”. External Applications are simply applications that you can reference from inside the product. I decided that I would really benefit from having Windows PowerShell at my ready within this application, so I created a PowerShell External imageApplication. As you can see by the image to the left I have three commands. Yes, I usually have a PowerShell console open, but having it within the application makes it much more efficient. Why? Well I am able to embed the computer’s name within the command. So now I can right-click the computer and select the “Windows PowerShell (remote)” application and immediately have a PowerShell session on the remote machine via WinRM. (The computers must have WinRM enabled to connect to them of course.) I also created a couple of local PowerShell sessions for a quick session when you need them.

If you are interested in the applications then you can download them from here.

We covered this in our AppSense Specialist class today and I thought it was important information for the community. This is the kind of stuff one might find useful on an exam.

AppSense Management Center

  • 90XX AM Agent
  • 91XX PM Agent
  • 93XX EM Agent
  • 97XX CCA, Events and AMC

Performance Manager

  • 91XX Memory & CPU
  • 9197/9199 Licensing
  • 92XX Application Manager
  • 90XX Application blocked/allowed
  • 9099 License Problem

EM – Policy

  • 93XX Self Heal
  • 9399 Licenses
  • 94XX Triggers and Actions
  • 95XX User defined

EM – Personalization

  • 96XX Personalization settings
  • 9661 Timeout communicating with Personalization Server

Recently at work we have been doing some load testing and finally realized that we needed to load balance the AppSense Personalization servers in our environment. Prior to this we have just utilized the standard AppSense failover method. We needed something a little more robust. These were the requirements.

Solution must be able to distribute the load among all of the AppSense Personalization servers

We didn’t require that each Personalization server have an exact equal load. We just needed to make sure that the load was distributed among them without one taking all of the work.

Solution must be able to detect when a Personalization server was unavailable and take it out of the list of available servers.

Simply stated, if a server was unable to serve the Personalization role we needed it removed so no further connections were created until it was functioning again.

Determine How to Monitor Availability

Before I configured anything I needed to determine method I would use to detect that the Personalization server was actually functioning. Probably the first two things that come to mind would be a TCP monitor on port 80 or an http monitor. Neither of these monitors would be acceptable.

I didn’t just want to know if IIS was still running. I wanted to know if Personalization was working. We have had several cases where something caused application crashes which then caused the PersonalizationServerPool to crash enough times to trigger the application pool’s “Rapid-Fail Protection”. In this case IIS and thus http was still functional so those checks would still register successful.

I was then reminded by our AppSense channel partner about the status page who just happened to be in our office that day.

On your Personalization server at http://Server:Port/PersonalizationServer/status.aspx is a dynamic status page that you can use to get information about your client and Personalization server.

image

For this page to return any data Personalization needs to be running so I decided to use it for my test. I just need some text to synchronize the test on and “Successfully connected to the profile server status handler” seemed fitting so I decided to use that.

Configuring the NetScaler

Setting up the Monitor

Now I am ready to do some dirty work. I logged into my NetScaler and navigated to the Load Balancing node and then to Monitors. I created a new monitor named MON-AppSense. You are going to use the HTTP-ECV monitor type.

Leave the Destination IP and Destination Port blank. This allows the NetScaler to insert the servers information into those fields. This enables you to use the monitor on all of your Personalization servers.

The first five fields on your left side determine how often you will probe your server and how you will react to changes. These values are going to be dependent on your environment and I recommend you sitting back for a couple of minutes to think about your values.

SNAGHTML41e0af

  • Interval. The time interval between probes sent to a server. The value must be greater than the value entered for the response time-out. The value is set in seconds.
  • Response Time-out. The time the monitor waits for the response from the server. The value must be less than the monitoring interval. The value is set in seconds.
  • Down Time. The time interval before the next probe after a server is marked DOWN. The value is set in seconds.
  • Deviation. Deviation from the learned response time for Dynamic Response Time monitoring. The maximum value in seconds is 159 and 159000 in msec. The minimum value is 10 msec. Minimum value: 1, Maximum Value: 2147483647.
  • Retries. The number of consecutive probes failures after which the appliance determines the service as DOWN. The default value is 3. The minimum value for this parameter is 3 and maximum value is 127.

SNAGHTML493f09

The Special Parameters tab is where you put in the URL and the string you are expecting to get back if the service is up.  You are directing NetScaler to get the /PersonalizationServer/status.aspx page and expect to see “Successfully connected to the profile server status handler” somewhere in the data that is sent back to that request.

Now you just need to go into each of the Services for the Personalization server and attach the monitor to the Service

SNAGHTML4e20fa

Configuring Load Balancing

Now you are ready to configure the actual load balancing for the Personalization servers in the Virtual Server section. The key parameters for this step are the Load Balancing Method and the Persistence.

The Load Balancing Method is the method which the NetScaler distributes connections to the individual Personalization servers. I decided to use the “Least Connection” method, which is the default. I am not a networking guru so I am not going to say that is the absolute best choice. But I did some load testing afterwards and was satisfied with the results.

This method will work especially well if we do encounter a failure. The NetScaler will monitor the connections to the servers and maintain an even connection count. For my load testing I took one of the servers out of rotation. The other server took up the slack with perfection. When I re-added the original server the connections were again balanced.

The persistence is what determines how the NetScaler determines where to send connections so that subsequent requests are sent to the appropriate server. For Personalization each request contains all of the necessary information for that transaction. In other words there are no “sessions” created for each transaction. This may sound strange, but trust me. I did a full load test after implementing this change and did not encounter any issues with users not receiving or submitting their personalization settings.

SNAGHTML54b760

As always I welcome all of your comments and questions.