Tag: Powershell
Windows Disk LUN WWID
by dwarfsoft on Aug.28, 2014, under Scripting, Storage, Tweet, Work
One of my main issues with attempting to identify storage on Windows Systems is that the Bus/LUN Id can be stored in multiple places, and trying to track that back to a Volume is pretty hard. So after doing some fairly deep investigation into DeviceIOControl calls to query Page 80 (Device information such as Vendor and type) and Page 83 (which returns the WWID object) I have managed to wrangle the C# into a Type usable from a PowerShell Script.
What is a WWID?
Start-iseTranscript
by dwarfsoft on Jul.15, 2014, under Scripting, Tweet, Work
I finally got around to fixing one of my biggest bugbears in PowerShell ISE 2.0, and when I did so I found on our new management server that it was broken for PowerShell ISE 4.0. I’m talking about Command Transcription. One of the most useful things I use in my day to day work is Start-Transcript for the standard PowerShell Shell. I have it automatically start in my PowerShell Profile so I can always go back and find how I achieved a particular goal.
I don’t use PowerShell ISE often, but when I do it’s usually because I am researching how to get something to work, or doing a colorized copy of the code for documentation purposes. For a long time I was happy enough with the suggested “Start-iseTranscript” provided by the Scripting Guy Blog.
Network Interface Removal and Renaming
by dwarfsoft on Dec.09, 2012, under Drivers, Scripting, Tweet, Work
So we had some Blade Chassis and implemented some Firmware upgrades. Surely this should not impact the blades themselves, or the OS on which they run? You’ve got to be kidding right. As soon as the Blade Chassis firmware has been upgraded we lost all four Broadcom NICs, and we had four new Broadcom NICs added in their place. This means that any IP Configuration has been lost and so has, in our case, Team configuration. Due to the four original NICs being removed, their Connection Names have also become unusable, because there are hidden devices that are still using those names.
Firstly, how do we remove devices via PowerShell. The Answer can be found on any Windows 7 workstation in the C:\Windows\Diagnostics\System\Device\CL_Utility.ps1. There is a function there called RemoveDevice.
Word.Application Trolling in PowerShell
by dwarfsoft on Nov.21, 2012, under Scripting, Work
I’ve been doing a little bit of investigation into OneNote and Word in PowerShell. So after this I got around to thinking of some of the mischievous things that could be achieved with some of the things I’ve learned… Like enumerating all documents, and in those documents enumerating all sentences, and then providing a 1% opportunity to replace its Font with Wingdings.
The following script demonstrates managing multiple threads, and managing the closure of those threads/jobs once they are complete. I’ve tested this on my C:\Temp folder with a number of documents in it, and the results are as expected. It provides some amusing opportunities for trolling.
PowerCLI – Virtual Machine Disk Usage Report
by dwarfsoft on Oct.25, 2012, under Scripting, Work
So, this is one of my largest PowerCLI/PowerShell scripts. This maps for each Virtual Machine, every Disk that is attached and trace back to what the LUN ID is that the disk is stored on, be it a VMDK, Thick/Thin provisioned disk, Physical/Virtual mode RDM, etc.
For the moment I will just paste the script as it stands, but I hope to return and explain some of the components.
NIC Bind Order for Microsoft Failover Cluster Virtual Adapter
by dwarfsoft on Oct.24, 2012, under Scripting, Work
I’ve been busy working on a project that is implementing a SQL Geo-Cluster. One of the requirements was to modify the NIC bind order such that the order of preference is Production,Heartbeat,…,Microsoft Failover Cluster Virtual Adapter. Most of this can be achieved through the Network Adapter Advanced Configuration window (Start->run->ncpa.cpl->Advanced Menu->Advanced Settings…) but the Microsoft Failover Cluster Virtual Adapter is a Hidden adapter and needs to be handled separately.
The original Suggestion from the Design document is to run “wmic nicconfig get description,settingid”. This list is used to get the SettingId of the NIC where the description is “Microsoft Failover Cluster Virtual Adapter”. The SettingId is then checked and moved in HKLM\SYSTEM\CurrentControlSet\services\tcpip\Linkage\Bind. The line in the Multi String that equals “\Device\” needs to be moved to the last line.
PowerShell Profile and Global Functions
by dwarfsoft on Jul.16, 2012, under Scripting, Work
So I came across an interesting problem today while trying to dynamically load Functions using a Load-Lib function. The issue was that Loading a Script within a function means that the functions defined within that File are only defined within the Scope of the loading function. The two ways around this are to Define every Function like:
Function Global:Load-Lib { ... |
Personally, I wanted my script to be the same whether I was loading it as a Global Module, or locally within a Function. In order to get the behaviour I wanted I had to redefine the functions as Global dynamically. This idea would also resolve the other issue I had: Redefining functions did not seem to always overwrite or replace the existing function code.
PowerShell, Exchange 2010, and MPS Report Sanitization
by dwarfsoft on Jul.13, 2012, under Uncategorized
I’ve spent a lot of time over the last couple of weeks buried in PowerShell scripting. Mostly PowerShell 1, but some VMWare PowerCLI and some Exchange 2010 PowerShell Scripting.
I look forward to posting up some code, particularly for performing some Post Server-Build tasks and rebuild tasks after some experience failing to get Exchange 2010 Setup /m:RecoverServer working (and having it remove all instances of the server from the AD Configuration).
Additionally, today I spent a lot of the day working on a script to Sanitize MPS Reports. So far I have a Powershell 1 script that can extract the entirety of the MPS Cab (Maintaining folder structure) and I’m on the way to getting regex to clean the files of any IP Addresses, Site info, AD Structure, and User Data. As I work for an Outsourcer to a Government Department, there are certain things we are and are not allowed to send to external sources… Having found very few Sanitization products available (and none that were flexible enough for my liking, although Notepad++ Regex Replacement on Folder was very close) I decided to write my own. Next week I hope to bring some scripts to the fore on this task.