Thursday, December 24, 2015

Powershell: Ensuring Values Are Returned As Arrays

It's Christmas Eve and I'm in the office catching up on some work.  This year has flown by pretty quickly and I have realized I have not added any content this year despite being very busy with VDI deployments, scripting, a zero-downtime SAN migration (which really deserved/deserves an article), and other miscellaneous tasks.
When scripting today, I came across an challenge that I remember solving earlier in the year. It took a bit of searching through previous scripts for the answer and I finally found it. I decided to turn it into a post for easier recollection later. I also hope it helps someone that runs across the same issue. Others will read this and probably just shake their head as common knowledge.

The Problem:
I have a function that returns multiple values into an array that I can then run a ForEach loop on.  However, it is possible that the function may only return a single value.  In that case, the variable is no longer an array, but a string or integer (depending on what is returned).
Example:

   $files = Get-ChildItem -Path E:\music –File | Select-Object Name
The example would return all the file names in E:\music as Strings and store it in the variable $files. If there were multiple values returned, the $files variable would be an array but let's say there is only one file in E:\music named mysong.mp3. The output of $files[0] would be:
   m
Not the entire file name. It makes sense when you think about it.  When you only assign one string value to a variable, the variable is going to be a string. Weird, eh?

The Solution:
When you are declaring a variable as an array, you can do something like: 
   $myArray = @( )
So when you are assigning the value of a function to a variable and want to ensure it is stored as an array, you would use:
    $files = @(Get-ChildItem -Path E:\music –File | Select-Object Name)
The result of running $files[0] using the same scenario as above would be:
   mysong.mp3
     

Wednesday, June 11, 2014

VDI: Xenith Pro Endpoints and Imprivata SSO High Availability

This is the first in, I imagine, a series of articles regarding VDI processes, lessons learned, tech issues overcome, etc. as it relates to my experience planning, configuring, deploying, and managing a Virtual Desktop Infrastructure roll out.
One issue that had cropped up after the pilot deployment was how fail over of single sign-on (SSO) authentication would work on the 0-client endpoints that use the ProveID Web API calls to the SSO infrastructure (2 Imprivata appliances, single site).  On the Windows side, HA was built in to the agent, whereas it downloads the SSO topology from an appliance after agent install.  Appliance failovers are seamless and Offline mode is configured to prevent authentication failure even if both appliances go offline.  However, all documentation on the ProveID side was sparse from Imprivata and further research did not reveal any answers to these questions:

Q. If the appliance configured in 'OneSignServer=https://<servername or IP> SignOn=yes' is down, will the endpoint go into an offline mode? Will it fail over to another appliance?
A. The answer is no to both. You will not be able to authenticate after the endpoint boots.  A visual cue is that the Imprivata logo will be missing from the logon box.

Q. Does the entry for OneSignServer accept multiple servers then?  If so, what is the syntax?
A. Yes, you can specify multiple servers.

OneSignServer=https://server1.domain.com,server2.domain.com SignOn=yes

Note: You can use a comma or semi-colon for separation.  Do not add the https:// to additional servers.

Friday, September 27, 2013

A GUI front-end for your Powershell scripts!

     I've recently discovered that it is possible to create a windows form for your powershell script.  As it just so happens, I've recently started creating scripts to automate tasks that are run by non-techhies.  Right now, all they can do is kick off the script that already contains all the necessary information and then sends an email with the results. I am starting to rework these scripts to include a GUI interface which will give them the ability to set their own options and also provide them instant feedback of the result without having to wait for an email.
  •  Get PrimalForms (Community Edition) from here.
    • You will use this tool to design the form and modify the attributes of the controls.  It will then generate the powershell script.
  • Edit the powershell script to make the controls do something with your favorite ISE
It's actually not too difficult to learn to make your scripts work from button clicks or to read input from a text box.  I'm not a big VB guy but I hear that in some cases, you can make the same program with powershell with a lot less code.

So is Powershell still just for scripting?