Aug 082011
 

A while ago I created a simple script to create some DNS records using dnscmd.exe. This because there where no DNS cmdlets for PowerShell available. Although it worked fine for me, I can imagine people would rather using PowerShell cmdlets.

Nowadays they are available for download yet pretty hard to find. I haven’t used them myself yet, but check it out yourself 🙂

http://dnsshell.codeplex.com/

As per version 0.4.4 the following cmdlets are available:

DNS Resolver

  • Get-Dns

WMI Wrappers

  • Clear-DnsCache
  • Get-DnsRecord
  • Get-DnsServer
  • Get-DnsZone
  • New-DnsRecord
  • New-DnsZone
  • Remove-DnsObject
  • Reset-DnsZoneType (no Get-Help)
  • Resume-DnsZone
  • Set-DnsRecord (no Get-Help)
  • Set-DnsServer (to be completed)
  • Set-DnsZone (to be completed)
  • Set-DnsZoneTransfer (no Get-Help)
  • Start-DnsScavenging
  • Start-DnsService
  • Stop-DnsService
  • Suspend-DnsZone
  • Update-DnsZone
  • Update-DnsZoneFile

Active Directory

  • Get-ADDnsPartition
  • Get-ADDnsRecord
  • Get-ADDnsZone
  • New-ADDnsRecord (to be completed)
  • New-ADDnsZone (to be completed)
  • Remove-ADDnsRecord (to be completed)
  • Remove-ADDnsZone (to be completed)
  • Set-ADDnsRecord (to be completed)
  • Set-ADDnsZone (to be completed)
Nov 032010
 

Today I heard something about Project Onyx from VMware. Although I just started playing with it today, I thought it was so interesting that I needed to write something about it.

First of all, Project Onyx is a little tool which can help you to automate certain processes without having a large amount of PowerCLI or SOAP knowledge. Of course, if you want to edit the script you need some knowledge about those things.

Anyhow, first things first. VMware Project Onyx can be found here. A second URL of Project Onyx can be found here. It’s a new tool from VMware which can generate code based on the mouse clicks you make in the VMware vSphere Client. At the URL I just provided you can also find the download link to the product. You don’t need to register or login to get it. Also there is no installation required for Project Onyx. Just download it, unzip it and start it up.

image

Once launched you will see the above window. Just enter your vCenter server name, your ESX hostname or IP address. Before pressing the start button, it’s handy to the tick the checkmark by “Launch a client after connected”.  If you do you can choose to start the VMware PowerCLI or the VMware VI Client.

When starting the VMware VI Client or as in my case the VMware vSphere client, you will get a warning message that you are connecting to the vCenter Server without encryption. However the traffic isn’t encrypted but tunneled trough the Onyx application which will be connected on SSL or port 443. One of the other things you will notice is that you are connecting to a different port of your vCenter Server. This is port number 1545.

Launching the vSphere Client:

image 

Warning message about the unencrypted traffic:

image 

Once the client is connected to vCenter server you can browse to one of your VM’s. Once you’re there switch back to the “black screen” of Onyx.

image 

The little play button on the top left starts the logging of your mouse clicks within the vSphere Client. The output mode is also interesting. Right now the output mode is PowerCLI.NET. This creates an output script in PowerCLI from your actions. However there are a couple of other possible actions including Raw SOAP Messages, C#.NET 2.0 and VCO JavaScript. Choose the language you need and press the little play button.

So what happens if I want to make sure that a VM boots into its BIOS at the next startup? This is a little and very handy option in the advanced properties of a VM, showed in the screenshot below.

image

If I enable the option: “The next time the Virtual Machine boots, force entry into the BIOS setup screen”, what is it that is actually happening? Well Check the screenshot below and this is how you could do it into PowerCLI:

image 

Doesn’t this look awesome? Ok what happens then if I change the memory settings from my UDA machine from 512 MB to 1 GB?

image

At the third line from above you see the newly allocated memory to my Virtual Machine. Ok, I have to admit, I’m not such a scripter anymore as I used to be. However I truly believe that scripting is important and in the future scripting will become even more important then it currently is. In the meanwhile, this awesome application can help me out by creating scripts. 🙂

I think this tool is really awesome and I recommend that you check it out yourself! So check out the website and the YouTube videos that they have posted on their pages.

Jul 152010
 

At my job site we have a very nice and cool lab environment. However due to budget cuts we are currently not in the position to extend our lab. So at the moment we currently have two uninterruptable power supplies (UPS) which would give the systems enough “juice” in case we have a power outrage. However, these UPS systems don’t have a management interface card. The problem with that is we are not able to communicate with the UPS to make sure that the servers are brought down nicely.

So we changed our system environment a bit. The Cisco switches are now connected on dirty power, so if we have a power outrage, the switches would be gone immediately. If the switches fail, our servers will not be able to communicate anymore with their default gateway. Within VMware this is known as isolation mode. VMware will bring it’s VM’s down, however our 3 physical servers (SQL 2008, VCenter and a DC) will have a problem. They are not brought down in such an event.

Therefore I wrote a little PowerShell script you can find below. Simple edit the time and other variables to suit your environment. With the current timers, the quickest shutdown will take place within 4 minutes, else it will take up to a maximum of 6 minutes. Note: make sure your UPS can hold it that long.

Although I do know that this is really a poor mans solution, I don’t think we have a better choice.

[code lang=”ps”]
$Gateway = "10.75.36.254"

function checkStatus {
$PingCount = "2"
 if (!(Test-Connection $Gateway -Count $pingCount -ErrorAction SilentlyContinue)) {
  $Subject="Network Lost"
  $LogLevel= "Warning"
  $Message = "Gateway didn’t respond within a timely fasion"
  WriteEventLog
  Recheck
 }
}

function Recheck{
$PingCount = "4"
#recheck gatway response within 4 pings.
#wait ten seconds before continue. This to rule out a temporarily  unplugged cable.
Start-Sleep -Seconds 180
 if (Test-Connection $Gateway -Count $pingCount -ErrorAction SilentlyContinue) {
  $Subject="Network connection restored"
  $LogLevel= "Information"
  $Message = "Gateway responded again. ‘nConnection restored."
  WriteEventLog
 }
 else {
 #If ping is still not responding, receck it again, else shudown the Windows Server
 Start-Sleep -Seconds 60
  if (!(Test-Connection $Gateway -Count $pingCount -ErrorAction SilentlyContinue )) {
   shutdownSystem
  }
  else {
  $Subject="Network connection restored"
  $LogLevel= "Information"
  $Message = "Gateway responded again. ‘nConnection restored"
  WriteEventLog
  }
 }

Function shutdownSystem{
$Subject="Network Lost"
$LogLevel= "Error"
$Message = "System is going down since network is lost. Possible due to a power failure `nPlease contact one the System Administrators."
WriteEventLog
# Shutting down the computer will start right now.
Stop-Computer -Force
}

Function WriteEventLog {
 $Event=new-object System.Diagnostics.EventLog("System")
 $Eevent.Source=$Subject
 $InfoEvent=[System.Diagnostics.EventLogEntryType]::$LogLevel
 $Event.WriteEntry($Message,$InfoEvent,65000)
}

$Counter = 1
do {
 #loop forever
 start-sleep -Seconds 120
 checkStatus
}
while ($Counter -eq 1)

[/code]

May 032010
 

Since I’m currently busy with installing multiple ESX servers in our test environment, I needed to create about 32 DNS records. Well since I’m lazy and I’ve really been loving Powershell I thought it would be a nice challenge to use PowerShell and of course the powerful DNScmd command. Since we have a logical IP plan, I could use the following script.

1..32 | % {iex ([string]::format(“dnscmd /RecordAdd mylab.com ESXhost{0} /createPTR A 192.168.10.{0}”,$_))}

Of course there are many other ways. For example, using a CSV file to import the DNS records.

For example:

Import-CSV c:\DNS.csv | foreach {dnscmd /RecordAdd $_.Zone $_.hostname /createPTR A $_.IPaddress}

However, keep in mind that PowerShell uses comma separated files and not the semicolon separated file which Excel automatically creates. So for example, use:

Hostname,IPaddress,Zone
ESX1,192.168.10.50,MyLab.com
ESX2,192.168.10.51,MyLab.com
ESX3,192.168.10.52,MyLab.com
ESX4,192.168.10.53,MyLab.com

Instead of:

Hostname;IPaddress;Zone
ESX1;192.168.10.50;MyLab.com
ESX2;192.168.10.51;MyLab.com
ESX3;192.168.10.52;MyLab.com
ESX4;192.168.10.53;MyLab.com

Apr 292010
 

Yesterday, I received a request to clear out a user attribute in Active Directory , specifically the ‘OtherTelephone’ attribute. Although I know you can do this with ldife, I wanted to do this with PowerShell. And although I’m not a PowerShell Guru I thought this would be a challenge.

Anyhow, before I could even start I needed to created some test accounts in my lab. For this I used the following script. It created 20 users for me.

1..20 | ForEach { New-QADUser -ParentContainer mylab.com/Test -Name ("Test" + $_)}

Then I had to set the OtherTelephone attribute. At first I did it manually, but what would be the fun of that? So I created another script and guess what? It worked. 🙂

get-QADuser –SearchRoot mylab.com/Test | foreach {Set-QADuser -identity $_.samaccountname -ObjectAttributes @{otherTelephone=(‘121312345’)}}

And then to do my main objective, I needed to clear OtherTelephone out. The script below worked for me. I don’t know if this is the best solutions but it worked. 🙂 Note that it will search all nested OU’s within the selected OU.

get-QADUser -SearchRoot mylab.com/Test | foreach {Set-QADUser –Identity $_.samaccountname -ObjectAttributes @{otherTelephone=@{Clear=@()}}}

The get-QADUser and other interesting AD related CMDlets are available from Quest. If you do a lot with AD, I really suggest you download those CMDlets. They are free of charge. 🙂