Tag Archives: PowerShell

Add iSCSI Target to Software iSCSI Initiator on All Hosts in a Datacenter

If you’re like me, you have noticed that adding an iSCSI target to many hosts takes a really long time in the vSphere client. You have to navigate to the configuration tab of each host, enter the storage adapters section, select the iSCSI initiator you want to update, go to properties, to dynamic discovery, add the IP address, and finally rescan the HBA to see the new block device(s).

Many of these steps have a lag time of up to 30 seconds. These steps are obviously not difficult, but this time really starts to add up when you’re updating many hosts.

I’ve created the script below to automate this process, and save some time. When running the script, you’ll be prompted for the vCenter server you’d like to connect to, the IP address of the new iSCSI target, and whether or not you’d like to initiate a rescan on each host after adding the new target IP address.

If there is more than one datacenter in the selected vCenter, you’ll have to choose which datacenter you would like to work with. This script assumes that you want to add the target to all hosts in the datacenter, but you could easily take the section of code that selects the datacenter and reuse it to make a cluster selection.




Add NFS Datastore to all Hosts in a Chosen Cluster

Have you ever wished you could add a datastore to all hosts for a given cluster at once, rather than having to add it to each host one-by-one? This PowerCLI script was created to accomplish just that.

It’s pretty straight forward – run it and you’ll be prompted for some input, namely:

  • Name of a vCenter
  • If more than one cluster exists in that cluster, a cluster selection
  • IP of NAS hosting the NFS export you wish to mount
  • NFS export path
  • Datastore name

Note: As the script runs, you’ll see some red error text. This is the script returning an error on getting a datastore with the name provided.  There are better (far more elegant) ways to do this, I’ll update the script with a better method down the road…




Script to Backup MySQL Database

Being that that this blog is “Proudly Powered by WordPress,” which uses a MySQL database, I wanted to find a way to schedule regular backups of MySQL databases. I am not that well versed with MySQL – all of the DB’s which I work with professionally are either SQL Server or Oracle – so I was looking to MySQL WorkBench to do the scheduling of regular backups, and to my dismay, you can’t schedule backups there.

I am not sure if this is something that Oracle has stripped out, or what, but it’s pretty crazy. So, I created this quick and easy PowerShell script to use the MySQLDump.exe to export the DB to a specified location, and cleanup any backups older than 1 month old.

Use the Task Scheduler to create a task to execute this script daily or weekly, and you’re set with your local backups of your MySQL DB.

Hope someone new to MySQL stumbles across this in less time than I took to realize that this functionality was not in MySQL WorkBench and to write the script. Enjoy!



XenApp 6 PowerShell SDK: Enabling Remoting via Enable-XAPSRemoting

I was running through the steps outlined over at http://community.citrix.com/display/ocb/2010/09/07/XenApp+6+SDK+-+Remoting+via+PowerShell+Remoting the other day, and just wanted to comment on one thing that I came across.

I was beginning to get frustrated because I could not successfully run the Enable-XAPSRemoting command on my Citrix Server, because it was telling me that it did not have a certificate to use for SSL communication. I installed the PowerShell SDK for XenApps 6, this server is a web interface so I have IIS installed, I have an internal PKI so rather than using a self-signed certificate as detailed in the Citrix forum, I installed a certificate from my internal CA via the IIS certificate wizard.

Now that I have this certificate installed, I should be able to enable XAPSRemoting, and remotely invoke the Citrix PowerShell commandlets from computers in my domain over an SSL connection, right? Wrong (not yet anyway).


Issuing the Enable-XPSRemoting command from the Citrix Server returns a response that I do not have a certificate to use for SSL which has CN=servername.domain.local in the subject, and has Server Authentication specified in the Enhance Key Usage field.  Did I screw up my certificate request and create a common name that does not match the FQDN? Is the certificate not in the right store?

First I check that the certificate is there. Since I am already in PowerShell, I check the store from there cd cert:\localmachine\my shows the certificate is there with the proper CN in the subject. Secondly, I fire up the Certificates Snapin from the MMC, and view the certificate. Everything looks good there, it has the “Server Authentication” in the Enhanced Key Usage field, which I am being told is required, and the subject has the proper CN=server.domain.local FQDN. The error message only states these two requirements for my certificate.


From the Certificates Snapin in my MMC, I request a computer certificate from my internal CA. Once installed, I run the Enable-XAPSremoting command again, and it executes without error. Going back to view the certificates side-by-side, the only thing that I can tell is that the Enhanced Key Usage has both Server AND Client Authentication.

I am not sure how many people will run into this, but since there is few little information about the XenApp PowerShell SDK at this time, I thought it couldn’t hurt to provide this information.