Skip to main content

Posts

Showing posts from August, 2009

List of all VBScript error codes.

In class we talked about the ability to handle errors in our scripts. The question came up as to how many potential error codes there are. Run the script below to find out. Remember that the function your are attempting to provide error handling for will not be capable of generating all these errors. You only need to script against the most likely ones, and then a catch all for anything unusual that pops up. This script uses a method that we did not talk about in class, Err.Raise. You use Err.Raise followed by the error number that you are interested in to help you test your error handling. This will cause your script to believe that the error actually occurred and invoke your error handling. Dim errDef, i WScript.Echo "VBScript-Errors:" WScript.Echo "Number", "Description" On Error Resume Next Err.Raise 1 errDef = Err.Description For i=1 to 2^16-1 Err.Clear Err.Raise i If Err.Description <> errDef Then WScript.Echo Left(Err.Number & "

If you upgrade a 2003 domain to a 2008 domain, are OUs protected from deletion?

OU deletion protection allows you to prevent the deletion of accidental move of an OU. This is a particular problem with using a laptop with a tiny mouse pad for administration. It is easy to accidently move an OU into another OU. With Group Policy, this can easily create problems. In Windows Server 2008, All OUs are created with the new OU Deletion Protection turned on by default. The question is, are OUs created on a Windows 2003 Domain protected after an upgrade to a Windows 2008 domain? The answer is no. I tested using a Windows 2003 domain created in a Hyper-V environment. I creaed an empty OU and another one with both a user account and a group. OU protection was not on by default for both of them after the upgrade. Also the objects inside the did not have deletion protection. To activate Deletion protection: · Open AD Users and Computers · Click View and select Advanced Features . · Right click the OU and click Prop

How to install the 2008 admin tools on Windows XP?

The adminpak for Windows Server 2008 (RSAT) will not run on Windows XP. In our test environment, we configured: Windows Sever 2008 R2 Domain controller Windows Server 2003 member server Windows XP SP2 We copied the adminpak.msi file from the 2003 server and installed it on the XP client. We were able to create an OU, Group, and User account on the 2008 domain controller without any issues. The RSAT program is not part of server 2008 like the adminpak was for 2003. You will need to download it from Microsoft. Microsoft Remote Server Administration Tools for Windows Vista http://www.microsoft.com/downloads/details.aspx?FamilyID=9ff6e897-23ce-4a36-b7fc-d52065de9960&DisplayLang=en

PowerShell: Parse the events of the last 24 hours and color code them.

The following script demonstrates how to read events for an event log that have occured over the past 24 hours and to color code them. Now, use your imagination. With a little enginuity, you could parse for events that you are interested in and have this script exercise some procedures as opposed to just displaying colored text on your monitor. PowerShell is desighed for you to be able to create the tools that you need. # ================================================================== # EventColors.PS1 # Author: Jason A. Yoder, MCT # WWW.MCTExpert.com # # Demonstrates how to list events from an event log written # in the last 24 hours and also adding color to denote the event # type. # ================================================================== # Get the current date and subtract 1 day. This is used to determine if # an event is less the 24 hours old. $Date = (get-date).adddays(-1) # Gather the details of all event from the "System" log that are # less the

VBScript Code for Excel formatting

VBScripting is capable of providing us will enormous amounts of information. The problem that we with VBScript is how to present that information? One way to do this is to use MS Excel to display our output. The following lines of code will open an Excel workbook. It will then enumerate and display some of the potential property values for borders in Excel. By looking through this script, you will get an idea of how to format the cells, enter data, and selecting the cell that you want to place data in. ' ============================================================================= ' Boarder1 ' File: Border1.vbs ' Author: Jason A. Yoder ' Version 1.0 Status: Completed ' -----------------------------------------------------------------

New class added: 50025 PowerShell for Administrators

After a few requests, I'm finally adding PowerShell into my class lineup. Some of you have already noticed that I'm posting PowerShell tips on Tuesdays. I figured that it is time to start teaching it as well. I've been writing administrative scripts for 5 years now. PowerShell is a clear improvement on VBScript. In one of my future Tuesday postings you will see how a 75 line VBScript was written in just 6 lines in PowerShell. Now that is something! In this class we will look at some key aspects to get you off and scripting in PowerShell. We will cover the environment, Syntax and logic, and how to make your life a little bit easier. I'll be instructing this class on September 9th 2009 at ENS Group in Fort Wayne, IN. Give Dave Shriner a call and let him you are interested in this three day class.

How do you change the network interface name on Server Core?

To do this we are going to use the netsh command. By Default, Windows starts naming the network interfaces “Local Area Connection”. There are situations in which you may want to change this. Let’s say you have more than one network interface on your system. Maybe you use one for domain isolation. In other words. You can only talk to a set of servers on this interface that is secured with IPSec. This is a common scenario for domain controllers. To help you identify which interface you are working on, you can rename it. Netsh interface set interface name=” Old Name” newname=” newname ” For example, lets take the default interface and give it a new name. Netsh interface set interface name=”Local Area Connection ” newname=”DCIsolation” In the above example, we changed the default name of Local Area Connection to DCIsolation .

What is the default tombstone value for computer accounts in Windows Server 2008?

At one point, the tombstone value for Microsoft networks was 60 days. The problem with that is that prestaged computers did not always make it from the factory to being joined on the domain in time. For that reason, Microsoft started to change the tombstone value to 180 days. Here are two guidelines to help you determine the tombstone value: On a domain controller in a forest that was created on a domain controller running Windows Server 2003 with Service Pack 1 (SP1), Windows Server 2003 with Service Pack 2 (SP2), Windows Server 2008, or Windows Server 2008 R2, the default value is 180 days. On a domain controller in a forest that was created on a domain controller running Windows 2000 Server, Windows Server 2003, or Windows Server 2003 R2, the default value is 60 days. To absolutely know, follow this procedure on your Windows 2008 domain controller: 1. Click Start , point to Admi

PowerShell: What if I do this???

In PowerShell we have the ability to see what a command will do before it executes. Image when you were first starting out in IT. Someone told you to type Format C: without telling you the results. Obviously formatting the C: drive is not something you want to do on accident. You can ask PowerShell what would happen if you did _______. We use the - WhatIf parameter. Let's first get a list of all services running on you client: Get-Process You noticed that a process is called BlueToothHeadsetProx y is listed. What would happen if you typed: Stop-Process -ID 5200 (5200 is the process ID ) You would disconnect your headset. We can use the -Whatif parameter to discover what would happen if we would execute this command without executing it. To do this type: Stop-Process -ID 5200 -whatif stop-process -id 5200 -whatif What if: Performing operation "Stop-Process" on Target "BluetoothHeadsetProxy (5200)" . We can also confirm each step before it is taken: Stop

UTC Conversion Code

When working with Date/Time functions in the WMI environment, we need to remember that this data is given to us in UTC time. For example, the date 2/25/2008 10:07:08 PM is formatted as 20080225220708.000000-300. Below is a function that will translate this UTC time into the conventional formatting for date/time. The time being feed is the OS installation date/time for the client running the script. strComputer = "." Set objSWbemServices = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colOS = objSWbemServices.ExecQuery("SELECT * FROM Win32_OperatingSystem") For Each objOS in colOS Wscript.echo WMIDateStringtoDate(objOS.InstallDate) Next Function WMIDateStringToDate(dtmInstallDate) WMIDateStringToDate = CDate(Mid(dtmInstallDate, 5, 2) & "/" & _ Mid(dtmInstallDate, 7, 2) & "/" & Left(dtmInstallDate, 4) _ & " " & Mid (dtmInstallDate, 9, 2) & ":" & _ Mid(dtmIn

Event Subscription procedure that actually works.

I have been very frustrated with Microsoft’s Event Subscription procedure. First of all, it does not work. I have tried many times and cannot get past the part where you add the collector computer account to the local administrators group on the sender computer. I even watched a video from Microsoft that did everything but showed you that it worked. Below is my Event Subscription procedure. Environment: The test environment is in a Windows 2008 R2 Hyper-V environment. Domain: Wilderness.com MCT-DC1 : Windows Server 2008 R2 Domain controllers – Will be the collector. MCT-Core-1 : Windows Server 2008 Core MCT-SRV-1 : Windows Server 2008 member server The prep work: First off, we need to use a service account. When creating a service account, I recommend a long, complex password. We will be setting the password not to expire so having a long and complex password will help with security. On MCT-DC1: · Open Active Directory Users and Computer

What do you need to know about IIS for exam 70-290?

Exam 70-290 is not necessarily an IIS exam. Now, I can’t teach the questions that are on the exam, but I can direct you to additional resources. TechRepublic has an article about what to expect on the exam. The first link below is to that article and the second is what the article suggest you read about IIS 6.0 before you take the exam. http://articles.techrepublic.com.com/5100-10878_11-5055957.html http://www.microsoft.com/windowsserver2003/evaluation/overview/technologies/iis.mspx

PowerShell: How to read data from a text file.

This is a simple, but yet very useful task for anyone who scripts, how to read data from a text file. We will be utilizing the Get-Content cmdlet for this task. In VBScript, we first had to create an object from the FileSystemObject. We then used the GetFile method to set another object to point to the data file itself. Next we would open the data file and then set up code to read the data file one line at a time and display each line as it was read. Then we would close the the file. In Powershell, we can get a simple display of the contents of a data file simply by typing: Get-Content DataFile.txt where Data File.txt is the path and name of the file that we want to read. Lets say you want to count the number of lines. In VBScript, we would set a variable to increment with each line of test. In Powershell we type in the comment below: Get-Content DataFile.txt | Measure-Object . Count : 7 Average : Sum : Maximum : Minimum : Property : The text file sampled above ha

Enumerate all files in a folder.

The question in class was “How do I list all the files in a remote computer?” First off, make sure that you are a member of the Administrators group on the target machine. In the first line (strComputer=”.”), replace the period with the name or IP address of the target machine. In the third command, replace ‘C:\Windows’ with the target folder. strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colFileList = objWMIService.ExecQuery _ ("ASSOCIATORS OF {Win32_Directory.Name='c:\Windows'} Where " _ & "ResultClass = CIM_DataFile") For Each objFile In colFileList Wscript.Echo objFile.Name Next

How can I put events in the event log for testing?

Luckily there is a command lint tool that can be used to place custome events in both the Application and the System event logs. EventCreate will allow you to put test data into the logs. Eventcreate /l application|system /t E RROR|WARNING|INFORMATION /id 1-1000 /d description Here is an example eventcreate / application /t information /id 51 /d "This is a test." Give it a try.

Can Windows Server 2008 block websites in a GPO or otherwise?

This topic seems to be a question that many are asking on the internet, but not getting the answers that they want. Before we dive into this, I would consider using a third party filtering service for blocking web sites. One of the purposes of Group Policy is to make life easier for Network Administrators. By taking on the responsibility of choosing what are appropriate websites, you are opening up yourself for a lot of work. By using a filtering service, you are paying someone else to do the grunt work. Also, many will filter your email. Should you lose your email server, these services will cache your email and deliver it once your server is back online. The following article tells you how to use group policy to control website access. This is not necessarily for server 2008, but it gives you guidance. http://www.chrisse.se/MAQB.asp?ID=17 Others are utilizing ISA server. I have even found some that are using a HOST file that points websites that they want to bloc

How to enumerate all the installed updates on a computer?

This script will come in handy in an environment where you do not have Windows Server Update Service (WSUS) installed. Set objSession = CreateObject("Microsoft.Update.Session") Set objSearcher = objSession.CreateUpdateSearcher intHistoryCount = objSearcher.GetTotalHistoryCount Set colHistory = objSearcher.QueryHistory(1, intHistoryCount) For Each objEntry in colHistory Wscript.Echo "Operation: " & objEntry.Operation Wscript.Echo "Result code: " & objEntry.ResultCode Wscript.Echo "Date: " & objEntry.Date Wscript.Echo "Title: " & objEntry.Title Wscript.Echo "Description: " & objEntry.Description Wscript.Echo "Client application ID: " & objEntry.ClientApplicationID Wscript.Echo "Server selection: " & objEntry.ServerSelection Wscript.Echo "Service ID: " & objEntry.ServiceID i = 1 For Each strStep in objEntry.UninstallationSteps Wscript.Echo i & " -- " &