Archive for the ‘Uncategorized’ Category

Arcade Cabinet – by request

20140718_083456[1]some people were asking so I snapped a quick pick about my toy.

New Desk!

20130807_230000

20130801_181702

PowerShell – Format this!

So I was at my monthly powershell script club working out how to format a text file. I did it the hard way ahead of time, using excel to move columns around and concatenate stuff. Then I used notepad++ to do the fiddly bits with the specific spaces and column spacing required. (Don’t ask, its for ingestion into a VERY old system)

I showed the guys the file format I get sent to me, then I showed them an example of the file output. Here’s the magic we came up with. Keep in mind they wanted me to condense this down to one line, but I’d rather keep it expanded so I can steal bits of it later. (yes, they gave me permission!)

This file takes in a file as an array, adds headers (not needed, but nice for get-member on the $data variable). The format command then parses the data and formats it to the correct places, finally outputting the formatted array to a text file.


$data = Import-Csv -Header 'account',"usage","sign","ConcatAddress" -Delimiter "`t" "c:\somefolder\messedupfile.txt"

$format = ' {0,-10:D10}{3,-36}{1:D9}{2}'
$output=foreach ($line in $data)
{
$format -f [Int64]$line.account,[Int64]$line.usage,$line.sign,$line.concataddress}
$output | Set-Content 'C:\somefolder\formated.txt'

Hey, see where I used “a” and sometimes ‘a’? turns out powershell doesn’t care which you use so long as the open and close quote style match.

Sysadmins – uptime

this is funny. you really need to read this: Dedication

Server Core Hyper-v Switch removal – The PowerShell Way!

So I’ve been playing with server core for few days now. I’m really starting to get the hang of the interface. I did however, goof something up. I accidentally created a virtual switch on the wrong NIC. I still think the way MS assigns the NICs is silly. the NICs are labled 1-4 on the box, but MS just seems to randomly pick adaper numbers. Probably not random, I just don’t know the answer. thats for another blog post, I suppose.

Regardless, I found myself needing to remove that virtual switch. Turns out someone smart figured out how to do that. Roger Johnson found a way to make it happen. In a nutshell, he found a way to create an object reference to the WMI class “MSVM_VirtualSwitchManagementService”. Very cool! anyway, here’s the steps. basic even for those of us who need a complete walkthrough:

1. download the hyper-v module. you’ll need that for the commands to function. You can download from Codeplex

2. right click on the .zip file and unblock it. then move it to your server. I use a network mapped drive that I can access from my server. Copy the file to where the rest of your modules are:
c:\Windows\System32\WindowsPowerShell\v1.0\Modules

3. Check to make sure powershell can find it. open powershell from the command prompt by simply typing “powershell”. Then enter the command

Get-Module -list

4. Import the module.

import-module HyperV

Now the fun stuff. the POWERSHELL!

Set your execution policy to unrestricted for this session.

Set-ExecutionPolicy Unrestricted

Create a variable and set it equal to that WMI class
$HVSwitchObj = Get-WMIObject –class “MSVM_VirtualSwitchManagementService” –namespace “root\virtualization” –computer “.”

Select the virtual switch to be deleted. Again we create a variable for that

 $HVSwitch = Choose-VMSwitch

Then delete that offending switch!

$HVSwitchObj.DeleteSwitch($HVSwitch)

GONE! fun. right? any props should go to Roger Johnson. he put the hard part together. I just added some of the basic stuff at the begining.

Dell PowerVault – Reclaiming space

This command will make all space on diskgroup 0 contiguous

navigate to the following ( make sure you have the dell powervault client software installed)

c:\program files (x86)\Dell\MD Storage Manager\client

smcli -n gfpdiscsi01 -c “start diskGroup [0] defragment;”

Virtual Server – Windows module installer / Preparing to configure Windows reboot loop

So I usually keep my virtual servers all nice and backed up just in case something dies. My production servers are backed up nightly, databases more frequently…. You get the drill. Backup or die.

Today I died. I have a server that I reserve for IT use. Holds some tools that scan my network, keep an inventory and host an internal blog for notes and whatnot. I don’t back that one up. Stupid, stupid, stupid. I figured it wasn’t REALLY production. Not THAT important. When it died, I sure realized how important it became. Enough of berating myself. On the the issue!

So the server rebooted itself. One of my other monitoring tools (nagios) let me know it went down, then came up, then went down….

When I attempted to connect, nothing. no website access, no RDP. The console through Hyper-V manager didn’t fly either. I’d see the message “Windows module installer is loading” followed by “Preparing to configure Windows”. Then the server would reboot. Rinse repeat ad nauseum.

I googled around some and found a number of faux fixes that didn’t work for me. mostly boot into safe mode and remove the offending hotfix. No dice. Then I remembered that I had downloaded Microsoft Deployment and Recovery tools from Technet. I gave that a shot. The automated recovery tools didn’t work. So I loaded up the System manager from the tools menu and just disabled the windows module installer. Low and behold it worked. It did load once, then reboot though. I quickly backed up my databases and files and got the heck out of dodge. Data saved!

Just a note, I was able to attach the .vhd file to another functioning server to get direct access to the file structure. Its just SO much easier to do database backups from the tools themselves than moving the flat files.

Update that powershell

Found a pretty cool link from the Powershell User group I attend.
http://code.msdn.microsoft.com/PowerShellPack

Keep that powershell alive with some added functionality from this powershell pack.

Return top