Tag: Script
Brocade Clone Config
by dwarfsoft on Jun.22, 2015, under Scripting, Storage, Uncategorized, Work
I was attempting to get a cloned configuration on Brocade switches as part of a PowerShell script that is adding Aliases and Zones to the Active Config. The original code that created the tasks to be run on the Brocade switch required 2 separate calls to PLINK in order to get all its information. The first was a call to cfgactvshow, and the second was a call to alishow. I knew there had to be a better way, so I developed the following one liner for cloning the active zone configuration based on our standard rules:
zoneobjectcopy "`cfg=\`cfgactvshow|grep "cfg:"\`;echo ${cfg:6}\", \"${cfg:6}_\`date +\"%Y%m%d%H%M%S\"\``" |
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.
Group Policy Editing – Findings
by dwarfsoft on Jun.15, 2010, under Novell, Scripting, Tweet
I had started another post on Group Policy editing, and how the Policy files are structured, and how to use and improve on the existing Group Policy Editor tool. The post has been found to be far too epic, so I have decided to cover a smaller subset of recent finds.
As everybody is probably already aware, we use Novell ConsoleOne and Zenworks where I work. ConsoleOne has some interesting features that require that whenever a Group Policy is being edited it takes over as the policy on the machine that is editing it. Rather than have a useful tool like Microsofts Group Policy Management Console, Novell likes to replace the local Group Policy and then just run gpedit.msc. Which is where my first gripe about gpedit.msc comes in:
GPEdit.msc requires line by line entry of things like, for example, port exceptions and program exceptions for the Windows Firewall. This is usually not an issue except that, as I have discussed in previous posts, we have been moving towards a Windows Domain environment. Firewall Exception rules are configured within two places in Group Policy: Domain Profile and Standard Profile. I have found that there is a need to move our current Standard Profile settings across to the Domain Profile settings. After a bit of registry searching I found a neat trick for doing exactly that.
Last Login Time
by dwarfsoft on Apr.22, 2010, under Scripting, Tweet, Work
I have recently been having a look into determining the Last Login Time of a user for a BGInfo implementation. Firstly I had a look at the getCurrentUserLastLoginTime script suggested for use with BGInfo. The limitation of this script, however, is that it will reset the login time to the last time the Windows login box was Authenticated against, which also includes the time that the workstation was unlocked.
In order to maintain current BGInfo information the implementation is running periodically, so this is unnacceptable. Therefore I had to work to resolve the issue manually. As I have had a fair bit of experience with Windows Profiles recently (see the last blog post) I was familiar with the ProfileLoadTimeHigh and ProfileLoadTimeLow registry keys in the ProfileList. So I set out to determine how to actually use these to determine the login time. I first wrote some code to get the User SID based on the users “%userdomain%” and “%username%”:
Shared User Profiles – Staging Scripts
by dwarfsoft on Mar.15, 2010, under Novell, Scripting, Tweet, Work
As promised, here are the scripts required for the Pre-staging of Domain User Profiles on the local machine. The first thing we need to do is Enumerate all the Local User Accounts.
Function StageAllUsers(DomainFQDN, strDomain) ' Enumerate all users that are Local and not built in accounts. strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 'Enumerate users where the User Domain is the Local Machine Set colItems = objWMIService.ExecQuery _ ("Select * from Win32_UserAccount " & _ "Where Domain = '" & GetComputerName & "' " & _ "And Disabled = FALSE And Name <> 'Administrator'") ' Stage each user For Each objItem In colItems ' Ensure the account actually has a profile (otherwise we can ignore it) If GetLocalUserProfile(objItem.Name) <> "" Then ret = StageUser(objItem.Name, DomainFQDN, strDomain) End If Next End Function |
The functions called here are GetComputerName, which returns the name of the local machine, and the other important ones are GetLocalUserProfile and Stage User. The first we can check is GetLocalUserProfile. (continue reading…)
More GTD-PHP Work
by dwarfsoft on Aug.20, 2009, under Authoring, Scripting, Tweet
I have updated my GTD-PHP Email Import Addon so that it now integrates with the current Subversion revision of the code. There is one bug left in it, in that it will not check that there is a mail server set before it tries to connect. I find that this error occurs the first time the session is established with the server, and from then on it works fine. By performing an error check against $server = “” I should be able to remove that bug as well.
The updated EmailImport Addon is now available for download from the GTD-PHP Trac wiki.