17 June 2011

Useful Command prompt (CMD) and PowerShell commands

This time I’ll make it short. In this blog I’ll start collecting useful Command prompt and PowerShell commands that I frequently use. Commands are inside the quotes:

Command prompt:

Did you ever search what is the username of the currently logged in user? Here is an answer:
Windows XP: “echo %username%
Windows 7: “whoami” or “echo %username%

And command that shows computer name:
Windows XP, 7, 2003, 2008: “hostname


************************************************
On the file server you need a list of all opened files:
net file
net file < .\desktop\openfiles.txt if the list is too long and doesn’t fit into command prompt window.
net file | find "Search string"
filter results by specified search string.


************************************************
Get a list of all drivers installed to Windows computer:
driverquery


************************************************Display user logon server (domain controller) in command line:
set
echo %logonserver%


************************************************
This tool displays operating system configuration information for a local or remote machine, including service pack levels, original install date, system boot time, total physical memory, available physical memory, page file max size, page file available, page file in use and much more:
"systeminfo"


************************************************
Get a list of all roles applied to Windows 2008 server:
servermanagercmd -q


************************************************
Detecting memory leaks:
Create memory snapshots into a file, if you run this command repeatedly new memory snapshots will be added to the end of the file:
"memsnap /m memsnap.log"
Analyze memory snapshots for memory leaks:
"memsnap /ah memsnap.log"


 
************************************************
This tool enables an administrator to display the MAC address for network adapters on a system:
"getmac /v"



************************************************
Group Policy Results (GPResult.exe) is a command line tool that displays Group Policy Settings that are in effect for a specific user or computer.
"gpresult /s ComputerName /user UserName /r /v > gpresult_filename.txt"


************************************************
Display / list Active directory FSMO (Flexible Single Master Operations) roles. Run this command on domain controller:
netdom query fsmo




************************************************
Get a list of group members from AD:
dsget group "CN=Domain Admins,CN=Users,DC=domain,DC=local" –members


************************************************
Get a list of disabled user accounts from AD:
DSQUERY USER -disabled


************************************************
Get a list of inactive user accounts from AD (in weeks):
DSQUERY USER -inactive 4


************************************************
Get a list of inactive computer accounts from AD (in weeks):
DSQUERY computer -inactive 4



************************************************
Get a list of all computer accounts and servers from AD (name and OS):
dsquery * -filter "(&(objectClass=Computer)(objectCategory=Computer))" -attr sAMAccountName operatingSystem -limit 1000


************************************************
Get AD schema version. Run this command on domain controller:
dsquery * cn=schema,cn=configuaration,dc=domain,dc=local -scope base -attr objectVersion


************************************************
Klist is a command line utility included in the default installation of Windows Server 2008 and Windows Server 2008 R2 which can be used to list and purge Kerberos tickets on a given computer. To run KLIST, open a command prompt in Windows Server 2008 and type Klist:
klist tickets


************************************************
Get Exchange schema version:
dsquery * CN=ms-Exch-Schema-Version-Pt,cn=schema,cn=configuration,dc=domain,dc=local -scope base -attr rangeUpper



************************************************
Get a list of Service Principal Name (SPN) for specified server:
setspn -l ServerName


************************************************
Get AD site information for computer on which you're running this command:
Nltest.exe /dsgetsite


************************************************
Get DFS server list for computer on which you're running this command:
dfsutil /pktinfo


This is it for today. Have fun!

14 April 2011

Problems connecting to Exchange 2010 from different AD

Not while ago we suggested to our customer that has few other companies to merge all email traffic to one Exchange 2010 server. The plan is that all users use email addresses from their original company. This setup would be like some kind of email hosting. After we migrated first of this external companies to centralized mail server we encountered strange behavior on merged company client side.

External company has few users that use Outlook 2007, just like all other users, with a difference that they can't open Out Of Office Assistant (OOF). If they open this wizard they receive this error:

"Your Out of Office settings cannot be displayed, because the server is currently unavailable. Try again later."

They also receive Offline Address Book (OAB) synchronization error:

"Task 'Microsoft Exchange' reported error (0x8004010f): 'The operation failed. An object could not be found.'"

I started troubleshooting this problem and tried all sorts of suggested solutions that I could found on Google. Steps that didn’t help were:
- checked if there is a proxy problem
- check permissions inheritance in AD on problematic users
- reapplied permissions inheritance on problematic users
- created new user from problematic user (copy) and tested new user. New user doesn't have these problems
- other user, except problematic ones, on the same computer doesn't have problems
- problematic user have problems on different computers
- created new mailbox store, move test user there and test if it works
- checked Exchange autodiscovery

Then I noticed something that pointed me to what could be wrong, but still couldn’t solve the problem. When I deleted user, created new one (with the same username) and attached old orphaned mailbox everything worked well until I:
- Unchecked "Automatically update e-mail addresses based on e-mail address policy."
- Set primary email address from name.surname @ domainA.com to name.surname @ domainB.com

After I made this change problem came back. If I apply the setting "Automatically update e-mail addresses based on e-mail address policy." back the problem remains.

I was so desperate at this point that I went sniffing Outlook traffic with WireShark. After this I finally found out what is going on and prepared a workaround. It looks like autodiscovery messes up Outlook to the point that it thinks that OAB and OOF is located on different address (in our case domainB.com) as other services. I’m not quite sure if this is an Exchange 2010/Outlook bug or my misconfiguration.

Workround goes like this:
For existing user:
- change primary email address of a user back to original domain (name.surname @ domainA.com)
- create new profile in Outlook and open Outlook to setup/initialize new profile and wait to receive few emails
- check if OOF and OAB are working
- close Outlook
- change primary email address of a user back to hosted domain (name.surname @ domainB.com)
- check if OOF and OAB still works

For new user:
- leave primary email address as given by Exchange policy (name.surname @ domainA.com)
- create new profile in Outlook and open Outlook to setup/initialize new profile and wait to receive few emails
- check if OOF and OAB are working
- close Outlook
- change primary email address of a user to hosted domain (name.surname @ domainB.com)
- check if OOF and OAB still works

Customer is now happy and so am I :)

This is it for today. Have fun!

06 April 2011

Unable to remove printer driver from Windows 7

I was contacted by a customer few days ago with yet another challanging problem. He called and said: “Luka hi, we can't upgrade or remove some printer drivers from one third of our Windows 7 x64 SP1 machines.”

The error message when we tried to remove different printer driver packages was:
Failed to remove driver HP Universal Printing PCL 6 (v5.2). The specified printer driver is currently in use.
Failed to remove driver HP Universal Printing PCL 6. The specified printer driver is currently in use.
Failed to remove package hpcu111u.inf. Driver package is in use.

and

Failed to remove driver Kyocera Classic Universaldriver. The specified printer driver is currently in use.
Failed to remove package oemsetup.inf. Driver package is in use.


I started troubleshooting this and tried almost all suggested solutions I could found on the net like:
- stop / start spooler
- reboot to safemode and unistall driver from there
- msconfig disabling all non Microsoft services
- cleanspl.exe
- logged on as every user, deleted both the printer and the driver
- disabling bidirectional support
- RUNDLL32 PRINTUI.DLL,PrintUIEntry /dd /c \\MachineName /m "AGFA-AccuSet v52.3" /h "Intel"
- printui /s /t2
- MS forum post: Deleting Printer drivers from Vista system 
- MS Answers question: Trying to un-ininstall print driver error message ...
- Skidzopedia post: How To Fix “Cannot remove or delete network printer” Error in Windows 
- and probably other solutions that also didn't help ...

At the end I found interesting workaround that went like this:
1. First I removed printer in "Devices and Printers"
2. Then I stopped print spooler
3. In registry I opened

HKLM\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows x64\Print Processors\

4. I renamed all Print Processors that were listed. Like Winprint to Winprint.old, Hpcpp107 to Hpcpp107.old, and so on ...
5. I started print spooler
6. Removed problematic driver pack in Print Management MMC
7. Reopened registry location

HKLM\SYSTEM\CurrentControlSet\Control\Print\Environments\Windows x64\Print Processors\

8. Renamed back all Print Processors to original name. Like Winprint.old to Winprint, Hpcpp107.old to Hpcpp107, and so on ...
9. Restart print spooler
10. Installed new printer drivers
11. Tested printing

Maybe this procedure will also help someone else with similar problems :)

This is it for today. Have fun!

12 February 2011

This should be an easy task (push install Mozilla Firefox 3.6.x)

Not while ago one of our partners gave me, what was supposed to be an easy task. He said: “Please help us install Mozilla Firefox on all our computers”. No problemo, I said. You have Script Logic Desktop Authority which is great for these kinds of tasks and Firefox also shouldn’t be a problem. How wrong could I be? 

My objectives were:
- Preconfigure Firefox homepage to predefined web site
- Preconfigure Firefox so it won’t use proxy
- Do not configure Firefox as default browser. Do not ask to become default browser.
- Disable automatic updates Firefox.

After Googling for a while I found numerous blogs, notes and hints how to accomplish this task but no complete solution. The most useful links I found are Mike’s Musings, Glen Bettridge, Chris Ilias and Shivanand Sharm’s blogs.  Mozilla Firefox turned out to be quite difficult to roll out and preconfigure.

For these task to accomplish I had one virtual Windows 7 to test on, Windows 2008 R2 AD servers, Windows 2008 R2 member server with Script Logic Desktop Authority. I also installed 7zip on test computer and added 7zip install folder to Windows PATH.

1. Prepare batch file to install Firefox
To script Firefox installation we need three files:
- FirefoxDeploy.ini
- Install_Firefox.cmd and
- Later also FirefoxSalus.exe

All these files should be copied to network share from where you’ll push installation.

- In FirefoxDeploy.ini is:
[Install]
InstallDirectoryName=Mozilla
FirefoxCloseAppNoPrompt=true
QuickLaunchShortcut=false
DesktopShortcut=true
StartMenuShortcuts=true
StartMenuDirectoryName=Firefox

- In Install_Firefox.cmd is:
REM x32 install Mozilla FireFox
IF NOT EXIST "C:\Program Files\Mozilla\firefox.exe" (
pushd \\SALFS\InstallPoint\FireFox
FirefoxSalus.exe /INI=\\SALFS\InstallPoint\FireFox\FirefoxDeploy.ini
popd
)

2. Preconfigure Firefox home page and proxy
- Unpack Firefox installer to some temp folder

- Change folder previously unpacked installer folder .\Firefox Setup 3.6.13\nonlocalized\ and cerate file named mozilla.txt.

- Open mozilla.txt and put these lines in it:
//
lockPref("network.proxy.type", 0);
lockPref("browser.startup.homepage", http://www.Hoponbike.com/);

- Download program ByteShifter and encode Mozilla.txt to Mozilla.cfg by simple “byte-shifting” with an offset of 13.


- Copy Mozilla.cfg to unpacked installer folder where Firefox.exe is.

- At the end of file named all.js located in unzipped installer folder ".\Firefox Setup 3.6.13\nonlocalized\greprefs\" add this line:
pref("general.config.filename", "mozilla.cfg");

Preconfigure Firefox to skip default browser checking and automatic updating

- Find file named firefox.js in unzipped installer folder ".\Firefox Setup 3.6.13\nonlocalized\defaults\pref\” and change these:
pref("browser.shell.checkDefaultBrowser", false);
pref("app.update.enabled", false);

3. Repackage Firefox and create installer
- Repackage installer by first zipping changes you made. To do this open command line and change directory to the root of unzipped installer folder. Enter these command to create a file called app.7z:
7z a -r -t7z app.7z -mx -m0=BCJ2 -m1=LZMA:d24 -m2=LZMA:d19 -m3=LZMA:d19 -mb0:1 -mb0s1:2 -mb0s2:3

- Download file 7zSD.sfx needed to repackage installer and save it to the root of unzipped installer folder.

- Create file named app.tag, also in the root of unzipped installer folder and put in it these lines:
;!@Install@!UTF-8!
Title="Mozilla Firefox"
RunProgram="setup.exe"
;!@InstallEnd@!

- Repackage installer by executing this command:
copy /B 7zSD.sfx+app.tag+app.7z FirefoxSalus.exe

- Copy newly created installer FirefoxSalus.exe to your install point folder.

So this is it, now you’re ready to test your Mozilla Firefox deployment on small group of computers with a help of Group policy or some other method. I personally did it with Script Logic Desktop Authority.

This is it for today. Have fun!

13 December 2010

Where are my desktop icons?

It happened again :( About a week ago I installed Windows 7 on my laptop, this time x64 version, and today it happened again. Some of my desktop icons, more exactly broken links, disappeared.
 These happened to me before, when I installed my first Windows 7. I noticed that my icons keep disappearing. Until I found a solution. Don’t be afraid this is not a virus, neither a spyware but it’s a feature of Windows 7 diagnostic task.

To resolve this issue open Task Scheduler with administrative rights (Start-All Programs-Accessories- System Tools).



Expand the tree of Task Scheduler to Diagnostic (Task Scheduler-Task Scheduler Library-Microsoft-Windows-Diagnosis).


Right click on scheduled task and click Disable.


Simple as that, and no more disappearing icons :)


This is it for today. Have fun!

12 December 2010

Virtualizing Windows 2000 server (P2V)

Last week a customer called and said that a disk died in an old Dell PowerEdge 1500SC server with Windows 2000 installed. Since this is a really old server, my estimation is about 8 years, the best solution was to virtualize it. This was also my suggestion for the customer. They agreed and I started working.

At the beginning I didn’t prepare much since I made numerous P2V migrations with VMware Converter in my career without any problems, but none of it involved Windows 2000. I prepared server and network like I usually do:
- I checked latest full server backup.
- Installed and connected temporary Gigabit switch (pluged in server and my laptop which have VMware vCenter Converter Standalone Client installed).
- Wrote down IP settings (ipconfig /all).
- Stopped / disabled all unnecessary services and wrote down their names and startup type. We wanted to control services startup. I also stopped and disabled all Dell management agents and AV software.

After server was prepared I started VMware Converter and run P2V wizard as described in my previous blog.

During this wizard I was asked to point to newer version of Scsiport.sys file. My current version was 5.0.2195.7017 and I needed 5.0.2195.7059. I started searching and found it on some other W2k server. I pointed a wizard to this file and moved forward. After two hours server was virtualized and ready to start.

Before booting virtual machine I always change Power On Boot Delay parameter to value 9000 in Virtual Machine Properties. I do it because I don't like catching ESX at boot to choose whatever boot parameter I need.


Dammit, Blue Screen or so called BSOD! It says STOP: 0x0000001E (0xC0000005,0x804a6467,0x00000000,0x000000B0).

I checked on Google and quickly found out that the problem is in Scsiport.sys driver. Quote from MS KB904374: “This problem occurs because of a code problem in the Scsiport.sys driver that is included in Update Rollup 1 for Windows 2000 SP4”. I also found this two other links: KB Article 1879 and KB Article 1005208.

Here is few suggestions for solving this issue that I found but didn’t help:
1. Injecting SCSI controller device drivers into Windows (VMware KB 1005208). I tried it and it didn’t help.
2. I also tried changing Scsiport.sys with some older and newer versions and didn’t help either. I did this by booting virtualized server from Ultimate Boot CD and copying the files to proper location on server’s hard disk.
3. I downloaded and extracted Hotfix from KB904374 and copied files to virtualized server. Didn’t help.
4. I changed SCSI controller from BusLogic to LSI Logic and got different error “STOP 0x0000007B INACCESSIBLE_BOOT_DEVICE”.

The solution that worked was:
1. I installed hotfix from KB904374 to original server.
2. I also installed VMware SCSI controller driver to original server. I did this:
   a. Download the VMware SCSI Disk Controller driver floppy.
   b. Extract with vmscsi-1.2.0.4.flp with 7zip to original server.
   c. Start “Add new hardware” from Control panel.
   d. Add new SCSI device and point to extracted files.
3. Repeat server prepare steps and start P2V wizard from VMware Converter.
4. Boot virtualized server and “Voila” Windows 2000 virtualized server is now booting.

After successful first boot I prepared virtualized machine as described in my previous blog.

Next time I’ll do P2V of something for the first time I’ll probably Google first ;)

This is it. Have fun!

01 December 2010

Virtualization and SAN upgrade on Windows 2003 cluster (part 2)

In my previous blog I described how we migrated data from our old SAN to new one. In this blog I’ll describe how we virtualized (P2V) two cluster nodes from HP physical machines to VMware ESX 4 virtual environment.

So let’s go straight to the point. Before the actual virtualization we prepared a short plan how we’re gonna do it without too much impact on this 24/7 production environment. Our steps were:
- We informed users that there may be some troubles on the network.
- We prepared server environment.
- P2V virtualization of cluster nodes.

There is not much to talk about informing the users. The usually don’t read notifications and they always complain that they didn’t receive one.

The preparation of server environment was done like this:
- We assigned appropriate LUNs to VMware servers.
- We backed up both cluster nodes.
- We wrote down IP settings (ipconfig /all)
- We migrated all cluster resources to one node (Node1).
- We installed VMware vCenter Converter Standalone Client to one of the computers with Gigabit Ethernet.


After all this was done, we started virtualizing Windows 2003 cluster servers.
- We stopped / disabled all unnecessary services and wrote down their names and startup type. It is very important to stop and disable Cluster Service, because we don’t want it to accidently start after server is virtualized and not yet configured. We wanted to control services startup.


- We also stopped and disabled all HP management agents and AV software.

After server was prepared we started VMware Converter and run P2V wizard.
- Choose the server we wanted to virtualize.


- Choose the destination server


- Enter the name of the virtual machine


- Choose datastore and virtual machine version


- Setup parameters for the conversion task. Be careful to remove unnecessary disk drives from conversion. We only need local drives and not those located on SAN.


- Once again review the conversion parameters and start conversion.


After conversion was done and before we started this machine we edited machine properties to add RAW hard disks and change startup delay.


I always change Power On Boot Delay parameter to value 9000. I do it because I don't like catching ESX at boot to choose whatever boot parameter I need.


OK, everything looks great and we were ready to start the server. But before we did it we switched off the old one! This is very important, never leave both servers running!

After successful first boot we did these:
- Installed VMwareTools.


- Configured correct IP address.
- Uninstalled HP management agents.
- Checked and configured correct disk / SAN presentation.
- Checked DNS just to be sure that cluster node didn’t register itself with wrong IP address.
- Rechecked cluster communication on Node1



After all this was done we enabled and started services one-by-one, with Cluster Service being the last.

Cluster service started successfully and we could start testing resource migration to these newly configured virtual cluster node. After we tested all resources and few days passed we virtualized the second node. We did it the same as the first one.

I hope this blog will help someone at their cluster migration :)

This is it. Have fun!