Andy Schneider's profileFourteen SixBlogLists Tools Help

Fourteen Six

April 30

There are 10 kinds of people in the world, those who understand binary, and those who don't

 

I was playing around with a couple functions to convert binary numbers to decimal and vice versa. The end game is being able to calculate subnets with powershell, but that will be another post for another day. For starters, I came up with 2 functions:

function Convert-IntToBinary ($int)
        {
       if ($int -ne $null)
        {
        [Convert]::ToString($int,2)
        }
       else
                {
                        foreach($element in $input)
                                {
                                [Convert]::ToString($element,2)
                                }
                }
        }


function Convert-BinaryToInt ($binary)
        {
                if ($binary -ne $null)
                {
                        [Convert]::ToInt32($binary.ToString(),2)
                }
                else
                {
                        foreach ($element in $input)
                        {
                        [Convert]::ToInt32($element,2)
                        }
                }
        }

 

What was kind of interesting to me was figuring out how in my my function to take input from a parameter or from the pipeline. My solution was to just use an if statement looking to see if a parameter was passed or not by seeing if it was null.  If its not null, then use the parameter. If it is null, then process $input (the enumerator that is passed to the function by the pipeline)

April 16

Editing RDP Shortcuts

 

I use Remote Desktop all the time, as I am sure everyone that manages a Windows Server does.  For most of my servers, I just use the RDP Client Admin tool to keep track of all my connections.  Today was a bit different. I actually needed to create a shortcut on a desktop for a user. So I did start | run | MSTC | OK and got the dialog box, made all my changes and did a Save As.  Good deal. Now all they have to do is double click it and all the settings are changed. So what if you want to update that short cut. I had realized I forgot to allow connection to the local hard drive.  I could recreate the short cut and save over the original one, but updating one line in Notepad is way easier. Right click on the short cut and edit with Notepad, or your friendly text editor of choice. All kinds of options become avaialble. I was able to change  redirectdrives:i:0 to redirectdrives:i:1 and I was good to go.

Here's a dump of what you get in notepad.

screen mode id:i:1
desktopwidth:i:1024
desktopheight:i:768
session bpp:i:16
winposstr:s:2,3,594,6,1626,801
full address:s:1.2.3.4
compression:i:1
keyboardhook:i:2
audiomode:i:0
redirectdrives:i:1
redirectprinters:i:1
redirectcomports:i:0
redirectsmartcards:i:1
displayconnectionbar:i:1
autoreconnection enabled:i:1
authentication level:i:0
username:s:USERNAMEGOESHERE
domain:s:DOMAINNAMEGOESHERE
alternate shell:s:
shell working directory:s:
disable wallpaper:i:1
disable full window drag:i:1
disable menu anims:i:1
disable themes:i:0
disable cursor setting:i:0
bitmapcachepersistenable:i:1

April 12

Fight Diabetes

 

I have a good friend who struggles with Diabetes. I am all for helping out. Scott Hanselman has  a campaign going to try to raise $50,000.00 It's all tax deductable as well.  Jump on board and help fight diabetes!

ISA and Powershell

 

I had mentnioned in an earlier blog that I had done some work with ISA using Powershell and I thought I would share the code I came up with.

Below I have three functions that will create computer objects, create a rule, and also add a user.  The one thing that tripped me up a bit was literally 1's and 0's.  But actually, once I started thinking about it, it made perfect sense. I was thinking about the fact that routers and firewalls are fundamentally the same type of device. They both segment IP networks and act as a gateway between subnets.  However, by default, a router permits all traffic through and a firewall denies all traffic. ISA is obviously a firewall and thus its default is to deny traffic.  So in "ISA Land" a 1 means deny and 0 means allow.  In my mind, at first, 1 means True, +5 Volts, positive, and i just assumed it meant allow. Alas that is not the case.

For users and protocols, the 1's and 0's as arguments determine whether they are allowed or exceptions to the rule.

function AddComputer ($name,$ip){
    $fpc = New-Object -com "FPC.ROOT"
    $oIsaArray = $fpc.GetContainingArray()
    $computer = $oIsaArray.RuleElements.Computers
    $coputer.Add($name,$ip)
    $computer.Save()
}

function Add-Rule ($ruleName, $ruleUser, $DestinationComputer){
    $oFPC = New-Object -com "FPC.ROOT"
    $oIsaArray = $oFPC.GetContainingArray()
    $rules = $oIsaArray.ArrayPolicy.PolicyRules 
    $newrule = $rules.AddAccessRule($ruleName) 
    $newrule.action = 0  
    
    # Set Access Properties
    $newrule.AccessProperties.UserSets.Add($ruleUser,0) 
    $newrule.AccessProperties.SpecifiedProtocols.Add("PING",0)
    $newrule.AccessProperties.SpecifiedProtocols.Add("RDP (Terminal Services)",0) 
    $newrule.AccessProperties.ProtocolSelectionMethod = 1
    $newrule.AccessProperties.DestinationSelectionIPs.Computers.Add($DestinationComputer,0)
    
    # Set Source IP Information
    $newrule.SourceSelectionIPs.Networks.Add("Internal",0)                                                            
    $newrule.SourceSelectionIPs.Networks.Add("Local Host",0) 
    $newrule.save()
 }
 
Function Add-User {
    $oFPC = New-Object -com "FPC.ROOT"
    $array = $oFPC.GetContainingArray()
    $user = $array.RuleElements.UserSets.Add($NewUser)
    $user.Accounts.Add($WindowsGroup)
    $user.save()
    }  
April 04

Two Aweome "Little" Utilities

 

I am sick and tired of Adobe Reader taking forever to load.  Get rid of it and install http://www.foxreader.com

Also, if you ever wanted to type down to your 30 or so favorite apps super quickly, check out http://www.bayden.com/SlickRun/

I've been using these two tools a lot lately and they have greatly increased my productivity.

Oh, and for quick editing of powershell scripts. I highly recommend http://www.vim.org

It takes a bit to get used to but you can really fly around once you get the hang of it, and you never have to leave your console window and screw around with Notepad