Monthly Archives: October 2011

Compare two files and report the differences

Sometimes you have two sets of data and you want to compare them, or find the difference. Perhaps you want to get find out which rows are in CSV (or Excel worksheet) but not in another, or you need to compare two columns. Either way, if you export the data to a CSV, powershell can do the rest pretty easily.

The following command uses “diff” which is an alias for “compare-object” to look at two separate files, and export the differences to HTML.

PS C:\> diff (get-content z:\shared\processes.csv) (get-content z:\shared\processes1.csv) | convertto-html > z:\shared\d

If for example you had lists of files, processes, customer records, you could use this pretty easily to see the difference.

Of course this actually works better too if you work with XML, because you can then use the “-property” parameter to focus on individual parts of each line (the column in Excel-speak).

So something like this:

PS C:\process> diff (import-clixml c:\process\process1.xml) (import-clixml c:\process\process2.xml) -property Name | con
vertto-html > c:\process\process.html

Leave a comment

Filed under Powershell

Problem connecting to Terminal Services

If you get a server that appears to be up, but you cannot connect with terminal services, you can do the following:

Connect remotely, and you can delete the following registry key:


The server will then need to be rebooted (if the Terminal Services service cannot be started remotely), and it should recreate the key and connect.

Leave a comment

Filed under Microsoft

Getting rid of the hybernate file in Windows 2008

The Hiberfil.sys hidden system file is located in the root folder of the drive where the operating system is installed. The Windows Kernel Power Manager reserves this file when you install Microsoft Windows. The size of this file is approximately equal to the amount of random access memory (RAM) that is installed on the computer.

Click Start, and then type cmd in the Start Search box.
In the search results list, right-click Command Prompt, and then click Run as Administrator.
When you are prompted by User Account Control, click Continue.
At the command prompt, type powercfg.exe /hibernate off, and then press ENTER.
Type exit, and then press ENTER.

Leave a comment

Filed under Microsoft, Windows 2008

DCPROMO on Server Core

FIrst, you have to install the server and set an IP address – my previous posts on IP changes on DCs all used netsh commands as well, so if you followed thouse, you should be somewhat prepared for Server Core. I already had a WIndows Server 2003 DC in the environment, so that will be my primary DNS server for the install, untill DCPromo edits the settings.
netsh interface ipv4 set address local static 10
netsh interface ipv4 set dns local static
netsh interface ipv4 set wins local static

Now networking is set up, we can rename the computer: netdom renamecomputer %computername% /NewName:dc02 and join the domain with netdom join dc02 /domain:foo.local /UserD:FOO\Administrator /reboot:5 /PasswordD:*. The “5″ after the reboot flag says to reboot 5 seconds after completion, and the “*” at the end says to prompt you for your password. I join the system to the domain manually first, because then I can WSUS patch it (if WSUS is in the network), or open up the firewall for any other patching software I have.

Once the server is back from reboot, activate, update the firewall to allow remote MMC connections (if you’re not doing that through GPO already), and install new roles.
slmgr.vbs -ato
netsh advfirewall firewall set rule group=”Remote Administration” new enable=yes

The following roles are optional, depending on the service of the server. Mine has DNS and the File Server roles, but not DHCP. None of these are required to install AD Domain Services!
start /w ocsetup DNS-Server-Core-Role
start /w ocsetup DHCPServerCore
start /w ocsetup FRS-Infrastructure
start /w ocsetup DFSN-Server
start /w ocsetup DFSR-Infrastructure-ServerEdition

If this is the first Windows Server 2008 DC in your environment, you’ll need to take the Windows Server 2008 DVD to the DC with the Infrastructure Master role (required for /gpprep only) and run the following (E: assumed as DVD-ROM drive):
e:\sources\adprep\adprep.exe /forestprep
e:\sources\adprep\adprep.exe /domainprep
e:\sources\adprep\adprep.exe /domainprep /gpprep (Also run adprep /rodcPrep if you plan on building RODCs.)

Now you’re ready to do the DCPromo itself. Create an unattend.txt file. To add a DC to an existing domain, you can use:

DCPromo will wipe out the passwords when it starts, or you can fill in “*” instead of the password, to be prompted. When it’s done, the server will reboot and be a new Global Catalog / DC in your domain. DCPromo will install neccessary binaries and configure the firewall for DC Services for you. It’s quite slick.

Leave a comment

Filed under Powershell

Get Eventlog details from a group of machines

Want to get recent events from a list of computers? Use the following Powershell command:

PS C:\> get-eventlog system -ComputerName (get-content c:\machines.txt) -Newest 10 | Select EventID, MachineName, EntryT
ype, Message | convertto-html > events.html

Not only will it export it in nice HTML, but you can change the parameters to choose a different log (say, System rather than Application) and also choose how many are returned (10 in this example).

Just make sure c:\machines.txt (or wherever) has a list of servers/PC’s in it.



Leave a comment

Filed under Powershell