The Multifunctioning DBA:

January, 2009

Jan 31 2009   8:20PM GMT

Powershell Tools



Posted by: Colin Smith
Powershell

Powershell V1.0 does not come with any tools to write scripts. Powershell V2.0 does come with a IDE but it is not as good as some of the other third party IDE’s and V2.0 is still in CTP so you do not want to put it into production. Here are a couple links to a few that I have used and found to be pretty good. My favorite one is the Idera Powershell Plus product but download them all and try them out and then get the one that works best for you. Here are the links.

 http://www.idera.com/Content/Show65.aspx

 http://adminscripteditor.com/

 http://www.powergui.org/index.jspa

 http://www.primalscript.com/

Jan 30 2009   6:01PM GMT

Powershell V2.0 CTP 3



Posted by: Colin Smith
Powershell, Windows Administration, Microsoft Windows, SQL Server

Powershell CTP 3 is out and ready to download and try on for size. I am downloading now and can not wait to get it installed and start playing around with it. I am looking forward to the release of V 2.0 and I really hope that they add actual useable remote functionality. I would like to have this for my SQL Server Monitoring tools that I am writting all in Powershell. This should be able to help me better manage and interact with the SQL Servers from my PDA.  Here is a link to the download and I will post more about my Powershell scripts that I use for basic SQL Server admin later on.

 http://www.microsoft.com/downloads/detai…


Jan 28 2009   8:29PM GMT

Powershell Explained



Posted by: Colin Smith
Powershell, Windows Administration

If you are using Powershell but would like a better explanation of how it all actually works then here is a great video with Jeffery Snover and he explains things very nicely. Check it out and I hope that it will help you understand Powershell and even get even more into it.

 http://channel9.msdn.com/shows/Going+Dee…

If you have any questions please let me know at http://sysadminsmith.com and click on the Submit a question link on the right.


Jan 27 2009   10:53PM GMT

Partitioning Tool



Posted by: Colin Smith
Windows, Windows Administration

I made a big mistake at home and only gave myself a 10 Gig partition of a 250Gig drive to be my boot drive. This was OK for a while but I did not manage the space well and before I knew it I was out of space and could not delete any more files. I found this great tool for home that is free for home use and I am sure that the other pay per versions of this are even better. All I can say is that it worked awsome for me so I thought I would let you all take a look as well.

 http://www.partition-tool.com/

And come check out my site and let me know if you have any questions at http://sysadminsmith.com


Jan 27 2009   8:58PM GMT

Learning SQL



Posted by: Colin Smith
SQL, SQL Server

I have been a DBA for about a year now and I still have not had to really do much SQL. I do other things such as backups, restores, indexing, and other things to make sure that our databases are in good shape and that our data is safe. I thought it would be a great idea to learn some SQL though so when a developer complains about a query running slow I can take a look at the query and understand what it is doing and perhaps help them re-write the query so that it will preform better. I installed the AdventureWorks DB on my SQL Server Express instance that is running on my Desktop and I printed out a diagram of the database. I found a good site http://w3schools.com/ that has tutorials for many different proggraming languages and I have been working down the SQL Tutorial. I would not claim to be a developer but I have learned a lot and would recommend this to others that are trying to learn SQL.


Jan 27 2009   8:52PM GMT

Disk Monitoring Q and A



Posted by: Colin Smith
Powershell, Windows, Windows Administration

Mike sent me an email asking about the input file for the disk monitoring script that I posted a while back. He could not get the script to work as he was putting the hostname and the IP of the machine in the computerlistall.txt file. The script was written to have either the hostname or the IP of the machine but not both. This started me thinking that a file with both the hostname and the IP of the machine would be useful in more ways then just this script. We may be able to use this file for multiple scripts and certainly is a good idea just to manage and keep track of names and IP’s. So I did the following to accommodate Mike. I hope this helps Mike and some others out there.

Here is a screenshot of my new computerlistall.txt file. notice that I do have headers in the file. This is very important because of the way the import-csv cmdlet works.

Computerlistall.txt

Computerlistall.txt

Now that I have that as my input I have to modify the script just a bit to accommodate this format.

The arrows point out what I have changed. I put in the $computer and the $ip lines just to show you the output when doing this.

So you can see that $compuuter is now the value of the hostname and $ip is now the value of the IP for that server. I do not know about you but I think this is freaking Cool.
So if you modify your computerlistall.txt file to be a file with header values and data values seperated by commas and modify the script as I have shown you here then you should be all set. This will allow you to use either the $computer or the $ip variable in the WMI connection string. Below is the entire modified script.

##########################################

###         Gather PAC Disk Information      ###

##########################################

Clear-Content “D:\Scripts\Powershell\PAC\lowdisk.txt”

$i = 0

$users = “some.email@address.com”

$computers = import-csv “D:\Scripts\Powershell\PAC\computerlistall.txt”

echo “ServerName        Drive Letter      Drive Size  Free Space  Percent Free” >> “D:\Scripts\Powershell\PAC\lowdisk.txt”

echo “———-        ————      ———-  ———-  ————” >> “D:\Scripts\Powershell\PAC\lowdisk.txt”

foreach ($line in $computers)

{

$computer = $line.hostname

$ip = $line.ip

$computer

$ip

}

$drives = Get-WmiObject -ComputerName $computer Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3}

foreach($drive in $drives)

{

$size1 = $drive.size / 1GB

$size1

$size = “{0:N2}” -f $size1

$size

$free1 = $drive.freespace / 1GB

$free = “{0:N2}” -f $free1

$ID = $drive.DeviceID

$a = $free1 / $size1 * 100

$b = “{0:N2}” -f $a

##############################################

##    Determine if any disks low    ##

##############################################

if (($ID -eq “D:”) -or ($ID -eq “S:”) -or ($ID -eq “T:”) -or ($ID -eq “C:”) -and ($free1 -lt 1))

{

echo “$computer         $ID               $size       $free       $b” >> “D:\Scripts\Powershell\PAC\lowdisk.txt”

$i++

#[char]10 | Out-File -append ./low.txt

}

}

####################################################

##    Send Notification if alert $i is greater then 0         ##

####################################################

if ($i -gt 0)

{

foreach ($user in $users)

{

echo “Sending Email notification ro $user”

$smtpServer = “smtp server”

$smtp = New-Object Net.Mail.SmtpClient($smtpServer)

$emailFrom = “fromuser@domain.com”

$subject = “Email Subject”

foreach ($line in Get-Content “D:\Scripts\Powershell\PAC\lowdisk.txt”)

{

$body += “$line `n”

}

$smtp.Send($EmailFrom,$user,$subject,$body)

$body = “”

}

}

Hope that helps and please drop me a line by heading over to http://sysadminsmith.com/ and clicking the Submit a Question link on the right hand side of the page. Thanks


Jan 22 2009   5:24PM GMT

Putty Connection Manager Tool



Posted by: Colin Smith
Unix, Linux, Sybase, Oracle

If you are working in Unix or Linux you are most likely using some tool to connect via ssh to that server for your session. Putty is a free tool that manages this very nicely. Many of you are already using Putty I am sure. If you are I did find a Putty Connection Manager that is really very nice. This allowas you to hav multiple putty sessions open as tabs. Check it out it is a very nice tool. http://puttycm.free.fr/


Jan 21 2009   5:25PM GMT

Powershell 2.0 CTP (Transactions)



Posted by: Colin Smith
Powershell, Windows

As I said I am just starting to fool around with Powershell V2.0 and I ran across a cmd-let that really grabbed my attention and I went to read more about it. This is a Fanatastic Idea and I am so excited to see Powershell use this in more Providers.

Transactions, How cool is that? Just like when running a query in a database, this will run the commands as a transaction and have the ability to roll back the changes. If all of the changes that you would like to be made are not completed correctly it will rollback to the way it was before the script ran. Currently it looks as though only the registry PSProvider supports this but man I hope that changes. I can think of many scripts where this would be useful. One example is my SQL Server Monitoring tools, I have a function that goes out and changes the on-call contact. I think it would be nice for it to be all or nothing. That way you do not get two people on call if for some reason the function does not complete. I love it. Read more at http://www.microsoft.com/technet/scriptc…


Jan 21 2009   4:48PM GMT

Powershell V2.0 CTP



Posted by: Colin Smith
Powershell

I finally got on the ball and downloaded Powershell V2.0 CTP and am starting to play with it now. You can download all that you need from http://www.microsoft.com/downloads/detai… You will need to unistall Powershell Version 1 in order to install version 2.0. I just installed this and have not had much time to chek it out but so far it is looking good. Looks like more cmd-lets and now have remoting functionaltiy which is one thing that I really wanted in Version 1.

Version 2.0 also comes with a graphical interface in order to write scripts and not need a third party utility such as Primal Script or Powershell Plus. As I learn more and play with this I will post what I think about it. Remember that this is a preview edition and is not ready for production at this time. I would only install this in Testing environments at this time. Features can still be added, subtracted, or changed from this version so be careful with it. Also check out this link for more good info.

 http://www.microsoft.com/technet/scriptc…


Jan 20 2009   5:49PM GMT

Environmental Variables in Powershell



Posted by: Colin Smith
Powershell, Windows

I have a script that I run in production that requires the script to access the Environment Variables for the server the script is executing on. This is a very simple task in powershell and very very useful. In my script I am using it just to verify that the machine name that it is executing on is the same as the machine name that I want the script to execute on. This is because the script is run from a single location and runs on many servers. The script compares the name that I am inputting to the actual machine name before moving on. Here is how easy this is in Powershell:

$name = (get-content env:Computername)

$name will now hold the value of the environmental variable on that machine for ComputerName. Powershell makes this so easy by having env as a PSDrive. This means that you can connect to it like you would a drive letter and get information from it. try the following:

cd env:

ls

and here is a sample of the results.

PS C:\Documents and Settings\smithco> cd env:
PS Env:\> ls

Name                           Value
—-                           —–
Path                           D:\oracle\ora92\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\Program Files\Oracle\jre\1.1.8\bin;D:…
TEMP                           C:\DOCUME~1\smithco\LOCALS~1\Temp
SESSIONNAME                    Console
PATHEXT                        .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PSC1
APPDATA                        C:\Documents and Settings\smithco\Application Data
SYBASE                         D:\Apps\sybase
PROCESSOR_ARCHITECTURE         x86
SystemDrive                    C:
HOMESHARE                      \\pni-pcfs01\HOME
DEFLOGDIR                      C:\Documents and Settings\All Users\Application Data\McAfee\DesktopProtection
windir                         C:\WINDOWS
USERPROFILE                    C:\Documents and Settings\smithco
TMP                            C:\DOCUME~1\smithco\LOCALS~1\Temp
SYBASE_JRE                     D:\Apps\sybase\shared-1_0\jre1.2.2
USERDNSDOMAIN                  PNI.US.AD.GANNETT.COM
USERDOMAIN                     PNI
ProgramFiles                   C:\Program Files
FP_NO_HOST_CHECK               NO
HOMEPATH                       \
COMPUTERNAME                   PNI-BT15689
CLASSPATH                      .;D:\Apps\sybase\ASEP_Win32\3pclass.zip;D:\Apps\sybase\ASEP_Win32\monclass.zip;C:\Program Files\Ja…
USERNAME                       smithco
NUMBER_OF_PROCESSORS           2
PROCESSOR_IDENTIFIER           x86 Family 15 Model 4 Stepping 3, GenuineIntel
VSEDEFLOGDIR                   C:\Documents and Settings\All Users\Application Data\McAfee\DesktopProtection
INCLUDE                        D:\Apps\sybase\OCS-12_5\include;
ComSpec                        C:\WINDOWS\system32\cmd.exe
LOGONSERVER                    \\PNI-DVADDC02
SYBASE_OCS                     OCS-12_5
CommonProgramFiles             C:\Program Files\Common Files
SystemRoot                     C:\WINDOWS
PROCESSOR_LEVEL                15
PROCESSOR_REVISION             0403
QTJAVA                         C:\Program Files\Java\jre1.6.0_05\lib\ext\QTJava.zip
lib                            D:\Apps\sybase\OCS-12_5\lib
ALLUSERSPROFILE                C:\Documents and Settings\All Users
WF_RESOURCES                   D:\oracle\ora92\WF\RES\WFus.RES
OS                             Windows_NT
HOMEDRIVE                      H:

PS Env:\>

Pretty cool huh….