Hey, Scripting Guy! Quick-Hits Friday: The Scripting Guys Respond to a Bunch of Questions (1/22/10)
In this post:
- How Can I Manage a Remote Storage Array?
- How Can I Have a Dialog Box’s OK Button Clicked Automatically?
- How Can I Format Microsoft Excel Columns with Windows PowerShell?
- Troubleshooting a Script That Creates a Shortcut on a User’s Desktop
How Can I Manage a Remote Storage Array?
Hey, Scripting Guy! Here is my situation. I started a new job recently, and I am working in the Storage and Virtualization group. Windows PowerShell + PowerCLI do a great job for the VM side of things.
Now on the storage things, we are using Equallogic, which does not have much in the way of APIs. The first approach I have tried to manage these arrays via Windows PowerShell is with the /n software SSH cmdlets to connect and execute Equallogic’s CLI commands via the session and parse the output. This is neither a pretty concept nor a working one yet. I am still digging into the issues there, but I have a feeling that it has to do with the SSH implementation on the Equallogic arrays.
The second idea I had was that Equallogic provides a Host Integration Toolkit, which includes Virtual Disk Service (VDS) driver for their arrays. I believe with Windows Server 2008 R2 and the storage manager I should be able to manage the arrays to some extent around creating volumes (luns), etc. I was hoping that I could also translate that to Windows PowerShell. I’ve done some researching (to be honest not a ton yet) on this, and have found 1 or 2 examples of working VHD files via VDS with Windows PowerShell but nothing related to working with SAN Mgmt.
Microsoft Scripting Guy Ed Wilson here. It sounds like your first solution should work—using SSH via the /n software. However, I am not sure because I do not have a SAN for testing.
The second problem you mention can probably be done, but it might be very difficult. The VDS API uses C++ and will require you to use C++ from within Windows PowerShell 2.0. The VDS object model is documented on MSDN.
Here is an example of calling a user32 function from within Windows PowerShell 2.0 to give you an idea of what you will need to do.
# NAME: SwapMouseFunction.ps1
# AUTHOR: ed wilson, Microsoft
# DATE: 2/13/2009
# KEYWORDS: Add-Type, user32.dll, mouse, pinvoke
# COMMENTS: This script uses Add-Type to create a
# function from user32.dll that allows you to swap the
# mouse button.
#Requires -Version 2.0
$signature = @”
public static extern bool SwapMouseButton(bool fSwap);
Add-Type -memberDefinition $signature -name “Win32SwapMouseButton” -namespace Win32Functions -passThru
} #End Add-User32Mouse
# *** EntryPoint to script ***
#$SwapMouse = Add-User32Mouse
One other thing you might consider: I found a blog by Taylor Brown who is a test lead on the Windows Core Operating System team. He posted a script that uses Windows PowerShell that will mount a VHD, determine if an online disk is offline, clear the read-only bit, create a partition if one is not present, create a volume and format it, and assign a drive letter or mountpoint. The problem with the script is the methods he uses do not appear to be documented in MSDN. However, take a look at what he does, use Get-Member and other tools to see what he is doing, and it might provide a great starting point for you.
How Can I Have a Dialog Box’s OK Button Clicked Automatically?
Hey, Scripting Guy! Any chance you could you point me to a script that monitors for a specific dialog box presented to a user and automatically clicks the OK button if that dialog box is detected? Basically, terminal users are getting prompted with a dialog box that says, “You are idle for X minutes and therefore your session will be disconnected.” To make a long story short, the administrator wants to suppress the dialog with a Windows fix; however, we rejected fixing it in Windows code. We’re looking for a workaround with a script to just click OK.
There is nothing native out of the box that will do that. Using a WMI event, you can monitor for a specific event to occur. This is something like a process that starts a drive that has disk space change, an increase in CPU utilization, or something like that. If a new process that generates it produces your dialog box, you might be able to do something. But I suspect no new process is occurring. Perhaps a thread, but you would need to be able to identify a unique thread that always occurs. You cannot simply monitor for a dialog box. I have to know what caused the dialog box and how to identify what changes when the dialog box occurs. Therefore, I suspect you might be out of luck.
Hey, Scripting Guy! I have read your short tutorial about how to access Microsoft Excel via Windows PowerShell, but I would like to know how to set the format of a column to “Currency” or “Date.” I would also like to know where one could find actual documentation about how to use Windows PowerShell to access Microsoft Excel.
I have written several articles about using Windows PowerShell with Excel. I found them by using the tags on the right side of the Hey, Scripting Guy! Blo! for Microsoft Excel, and then clicking Windows PowerShell at the top of the page of results that was returned. (In the Script Center 101 Zunecast, I talk about finding stuff on our new Script Center site.) This is seen in the following image.
In the articles, I point to the MSDN documentation. This is vital because the MSDN documentation is the only place where the object model for Excel is adequately covered, and it is the proper documentation for Office Automation. It often takes quite a bit of abstraction to translate the VBA code that is given as examples into Windows PowerShell. That is part of where my articles come into play. After reading them, you should have a good feel for what is involved. To be honest, it is not always easy. Some of the enumerations are a bear, not unlike the bear seen in the following image that I saw at the Riverbanks Zoo in Columbia, South Carolina, one sunny morning.
Some of the method calls require passing by reference, but that is where my articles should be of assistance.
Troubleshooting a Script That Creates a Shortcut on a User’s Desktop
Hey, Scripting Guy! I am new to scripting and am looking for a solution to my problem: I would like to use a logon script with Group Policy in Windows Server 2003 to create a shortcut on the user’s desktop. The target of this shortcut is a shared folder on a file server. When I searched the Script Repository, I found the following script:
objWSHShell = CreateObject(“Wscript.Shell”)
strDesktop = objWSHShell.SpecialFolders(“Desktop”)
strShortcutName=”Corporate Public Folder”
objShortcut=objWSHShell.creatShortcut(strDesktop + “” + strShortcutName + “.lnk”)
I created a script file with the name of “logon.wsf” on a test Windows XP machine and ran the file; however, it displays an error message stating that “no jobs are defined in the file.” Now I wonder what should be added to this script file. I looked around the Microsoft Web site for a long time and can’t find a community where I can get help regarding this script. If you know about such a place, please reply with the link.
Save your script with a VBS extension instead of a WSF extension. A good place to get started with learning about scripting is the Learn page on the Script Center. One of the best scripting communities anywhere can be found on The Scripting Guys Official Scripting Guys Forum. We have an awesome group of moderators and dedicated participants.
Well, this concludes another edition of Quick-Hits Friday. It also concludes another exciting week on the Script Center. Join us next week as we delve into the mysteries of…well, we will let that remain a mystery for now.
If you want to