≡ Menu

Pin applications to Task bar using powershell

Description:

This powershell function helps you pinning the specified program to Task bar in windows 7/Windows Vista/Windows 2008 computers.

Usage:

[PS]:>Pinto-Taskbar -application “c:windowssystem32calc.exe”

The above statement Pins the calculator program to Task bar.

Code:

function pinto-taskbar {

param(

[parameter(Mandatory = $true)]

[string]$application

)

$appfolderpath = $application.SubString(0,$application.Length-($application.Split(“”)[$application.Split(“”).Count-1].Length))

$objshell = New-Object -ComObject “Shell.Application”

$objfolder = $objshell.Namespace($appfolderpath)

$appname = $objfolder.ParseName($application.SubString($application.Length-($application.Split(“”)[$application.Split(“”).Count-1].Length)))

$verbs = $appname.verbs()

foreach ($verb in $verbs) {

if($verb.name.replace(“&”,””) -match “Pin to Taskbar”) {

$verb.DoIt()

}

}

}

{ 1 comment }

Close applications gracefully using powershell

By saying “Graceful” close, I mean allowing the users to save any un saved data before exiting the application. It is equivalent to clicking on “CLOSE” button at the right top corner. The advantage with this method when compared “stop-process” is, it allows the user to save data and hence there is no data lose.

This option came handy to me several time.

Code:

Get-Process notepad | % { $_.CloseMainWindow() }

The above code will get list of  notepad processes running in your PC and prompts you to save data for the processes which have unsaved content. The notepad processes which don’t have anything to save will get closed normally.

Hope this helps you…

{ 9 comments }

Create Outlook 2007 Icon on Windows 7 Desktop

Microsoft Office 2007 installation in windows 7 won’t create any Outlook Icon on User desktop. This is expected behavior with default installation. If you want to get this icon, then import the below registry information to your system and you should be able to see it immediately.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINESOFTWAREClassesCLSID{00020D75-0000-0000-C000-000000000046}]

[HKEY_LOCAL_MACHINESOFTWAREClassesCLSID{00020D75-0000-0000-C000-000000000046}ShellFolder]
“Attributes”=dword:00000072

[HKEY_LOCAL_MACHINESOFTWAREClassesCLSID{00020D75-0000-0000-C000-000000000046}]
@=”Microsoft Office Outlook”
“InfoTip”=”Displays your e-mail, calendar, contacts, and other important personal information.”

[HKEY_LOCAL_MACHINESOFTWAREClassesCLSID{00020D75-0000-0000-C000-000000000046}DefaultIcon]
@=”C:\PROGRA~2\MICROS~1\Office12\OUTLOOK.EXE,7″

[HKEY_LOCAL_MACHINESOFTWAREClassesCLSID{00020D75-0000-0000-C000-000000000046}InprocServer32]
@=”C:\PROGRA~2\MICROS~1\Office12\MLSHEXT.DLL”
“ThreadingModel”=”Apartment”

[HKEY_LOCAL_MACHINESOFTWAREClassesCLSID{00020D75-0000-0000-C000-000000000046}Shell]

[HKEY_LOCAL_MACHINESOFTWAREClassesCLSID{00020D75-0000-0000-C000-000000000046}ShellOpen]

[HKEY_LOCAL_MACHINESOFTWAREClassesCLSID{00020D75-0000-0000-C000-000000000046}ShellOpenCommand]
@=””C:\PROGRA~2\MICROS~1\Office12\OUTLOOK.EXE””

[HKEY_LOCAL_MACHINESOFTWAREClassesCLSID{00020D75-0000-0000-C000-000000000046}ShellPropertiescommand]
@=”rundll32.exe shell32.dll,Control_RunDLL “C:\PROGRA~2\MICROS~1\Office12\MLCFG32.CPL””

[HKEY_LOCAL_MACHINESOFTWAREClassesCLSID{00020D75-0000-0000-C000-000000000046}shellex]

[HKEY_LOCAL_MACHINESOFTWAREClassesCLSID{00020D75-0000-0000-C000-000000000046}shellexPropertySheetHandlers]

[HKEY_LOCAL_MACHINESOFTWAREClassesCLSID{00020D75-0000-0000-C000-000000000046}shellexPropertySheetHandlers{00020D75-0000-0000-C000-000000000046}]
@=””

[HKEY_LOCAL_MACHINESOFTWAREClassesCLSID{00020D75-0000-0000-C000-000000000046}ShellFolder]
“Attributes”=hex:72,00,00,00

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionExplorerDesktopNameSpace{00020D75-0000-0000-C000-000000000046}]

You can save above bunch of keys as reg file and import into the target machine. Obvious thing is that you should take backup of your registry before you import.

Hope this tip helps you!!

[Source]

{ 0 comments }

[PLEASE USE https://techibee.com/powershell/check-disk-space-of-remote-machine-using-powershell/430 to check free disk space of remote computer. I made it more advanced there.]

Description:

This function takes the computer name as argument and displays the disk free/total size information. One advantage with this function is, no need to search for admin windows when you want to run it. It prompts for admin credentials and connects to remote computer using them.

Usage:

PS C:temp> Check-Diskspace -computer remotepc
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
Drive Name :  C:

Total Space :  232.83 GB

Free Space :  0.94 GB

PS C:temp>

Code:

function Check-Diskspace {            
             
param (            
             
[parameter(Mandatory = $true)]             
[string]$computer            
             
)            
             
$cred = Get-Credential            
             
$drives = Get-WMIObject -Class Win32_LogicalDisk -ComputerName $computer -Credential $cred | where { $_.DriveType -eq 3 }            
             
foreach ($drive in $drives) {            
             
write-host "Drive Name : " $drive.DeviceID             
write-host "Total Space : "($drive.size/1GB).ToString("0.00") "GB"             
write-host "Free Space : " ($drive.FreeSpace/1GB).ToString("0.00") "GB"             
write-host " "            
             
}            
             
$cred = $null            
             
}
{ 4 comments }

Get computer uptime using Powershell

Simple Way to get local computer uptime….

PS C:> (gwmi win32_operatingSystem).lastbootuptime
20100728180723.375199+330
PS C:>

Now, let’s query the remote computers uptime.

PS C:> (gwmi win32_operatingSystem -computer remotePC).lastbootuptime
20100728180723.375199+330
PS C:>

The above are oneliners, if you want to convert this into full fledged function, use the below code. This gives the uptime of computer you have parsed.

C:>Get-PCuptime -computer remotePC

System(remotePC) is Uptime since :  14 days 20 hours 54 minutes 20 seconds

C:>

Code for function:

function Get-PCUptime {            
[cmdletbinding()]            
param($computer)            

$lastboottime = (Get-WmiObject -Class Win32_OperatingSystem -computername $computer).LastBootUpTime            
$sysuptime = (Get-Date)  [System.Management.ManagementDateTimeconverter]::ToDateTime($lastboottime)            
Write-Host“System($computer) is Uptime since : ” $sysuptime.days “days” $sysuptime.hours `
“hours” $sysuptime.minutes “minutes” $sysuptime.seconds “seconds”            

}
{ 6 comments }

Changing the password is one of the regular activities for a typical System Administrator. It is not an easy task unless you have required tools in your tool kit. If you have changed one of your domain admin password, you need to find the places(be it services or scheduled tasks) where you have saved it and update password there. If you have 1000 servers, then you will endup updating/scanning remote server’s services/scheduled tasks one after another unless you have some home grown scripts to serve this purpose. 

Well, I have some good news if you are still spending long hours to change the passwords. Today I came across a new utility called SSTUM (Service and Scheduled Task User Manager) which helps you in changing the password in remote services or scheduled Tasks with less efforts.

A few things I notices about this tool are…

1) Easy to use and saves lot of time
2) Input can be a computer list or you can make selection from active directory
3) Has an option to restart service after changing the password — pretty useful
4) Support exporting of results to some text file
 5) Supports changing the username as well.

More details about this tool and download location are available at http://martin77s.wordpress.com/2010/07/19/service-and-scheduled-task-user-manager/

Hope this definitely helps.

{ 3 comments }

Exchange 2003 – Queue Directory Corrupt

For one of our client, we have received an alert stating that “The Microsoft Exchange Information Store service terminated with service-specific error 0 (0x0)”.

The error seems to simple and everyone would just suggest to start the service back. But the root cause was different.

One of our colleague started working on the alert and here is the chronology of steps followed in resolving the issue. found that the Information Store service was in stopped state and started the service.  Started verifying queues , encoutered error stating that “Default SMTP Virtual Server is unavailable”. Verified and found that SMTP Service was in started mode.

Escalated call to me and I’ve started working on the issue.

Upon further analysis, found that the SMTP Virtual Instance was stopped in ESM (Exchange System Manager). Tried to start the instance, encountered error stating that “Queue Directory is corrupted , hence the instance could not be started”.

Error logged in Eventlog & Error pop-up when accessed Queue Directory from explorer.

Executed following Steps to resolve issue:

1. Uninstalled existing Antivirus (AVG)

2. Executed chkdsk on volume in which the exchange database is stored. Found disk errors.

3. Executed chkdsk /f on the volume and restarted the server

4. Created new Queue Directory and pointed the path from ESM to the new folder.

5. Started SMTP Virtual Instance & Information Store Services.

Mails started flowing fine.

{ 0 comments }

Outlook was unable to recover some or all of the items in this folder. Make sure you have the required permissions to recover items in this folder and try again. If the problem persists, contact your administrator

I came across this error while I(or my users) trying to restore bulk emails in outlook using “Recover Deleted Items” option. Single or little more emails restoration works fine but this issue is coming only when I attempt bulk restoration.

When this happened for the user, I am clue less what was happening. I went to event viewer on the server where user mailbox is hosted and observed below error when the user is attempting the restoration.

Event Type:     Error
Event Source:   MSExchangeIS
Event Category: General
Event ID:       9646
Date:           7/19/2010
Time:           3:45:47 PM
User:           N/A
Computer:       MYEXCHANGE
Description:
Mapi session “/o=ORG/ou=SITE/cn=Recipients/cn=myuser” exceeded the maximum of 500 objects of type “objtFolder”.

After a little bit of googling I found an article (http://support.microsoft.com/kb/830829/en-us) which is talking about similar issue and increasing the limits on Object types that you see in event viewer should fix the issue. I tried increasing the ObjFolder limit to 1000(note: 500 is the default; if you don’t find this key, it is safe to create one as per KB) on my exchange server but still it didn’t work and was saying exceeded the limit of 1000 this time. At this point I was not sure what was the optimum value to which I should increase this limit to make the restoration happen. As I didn’t find answer to this question in google, I polled one of friend who is with MS and knows more about exchange. He said there are no limits defined as such and it’s a trial and error method we should try. I bumped it to 10,000 this time and restoration worked. Along with this informaiton, my friend passed me a note as well. The more limit you put the more the load on your exchange server. So, be cautious while increasing the limits and I prefer to do it during off hours so that load will be less on the server and your users will be away anyways and that also gives you ample time to troubleshoot any unforeseen issues.

Additional note: While trying this you might see events about exceeding the limits of other object types described in aforementioned KB. You should create necessary registry keys for them as well to make your restoration suceessfull. Don’t forget to revert your settings once you are done with restoration; otherwise it will impact your server performance. Generally this will come into effect after store restart. Otherwise you can wait for 15-30 mins to make store pick these changes without restarting the IS.

Hope this information helps you.

{ 6 comments }

I started my day with some exciting stuff. Since the time I started working on Windows 7 computers, I always failed to access remote computer’s(windows 7) administrative shares(for example: c$) using computer’s local admin account(this used to work in windows XP as the local admin name and password are same across all systems). I didn’t pay much attention to it as I got domain admin privileges which anyways working. But these days with the increase in my testing efforts on windows 7 computers, the need to access remote shares with local administrator got increased. I don’t want to put domain admin every time as it is a high level account and moreover I need to put in the credentials every time I access a new computer which is waste of efforts.

Well, I got this problem resolved by little registry tweak. Steps follows….

Fix:

  1. Go to Start -> RUN
  2. Type: REGEDIT
  3. Navigate to “HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem”
  4. Create a new DWORD key with name “LocalAccountTokenFilterPolicy” and value “1”
  5. Restart your computer.

This solved the problem and I am able to access the shares of the computers where I made above change.

Thanks to TechNet Forums for directing me to the solution and special thanks to Jammah.com for providing this tip.

Additional Notes:

Well, the registry key fixed the problem but I am curious about the reasons behind this design. I did some research on this topic and understood that, it is a “Security Measure” for UAC(User Access Contorl) enable systems. The whole purpose of enabling UAC is to make administrators work with non-elevated environment to defend the attacks. As part of UAC implementation, the ability for local administrators to elevate their rights from remote computers is disabled by default and can be enabled on optional basis using aforementioned procedure.

More details can be grabbed from:   http://support.microsoft.com/kb/951016

Hope this information helps you.

{ 3 comments }

[For a change today I am posting some non-technical stuff]

Today I received this short story as a forward from my friend. Thought of posting it here.

Here goes the story….

A shopkeeper watching over his shop is really surprised when he sees a dog coming inside the shop, He shoos him away. But later, the dog is back inside again. So he goes over to the dog and notices that it has a note in its mouth. He takes the note and it reads “Can I have 12 soaps and a shampoo bottle, please. The money is with the dog.” The shopkeeper looks inside the dogs mouth and to his surprise there is a 100 rupees note in his mouth. So he takes the money and puts the soap, shampoo and change in a bag, and then places it in the dogs mouth.

The shopkeeper is so impressed, and since it is the closing time, he decides to follow the dog. The dog is walking down the street, when it comes to the zebra crossing; he waits till the signal turns green. He walks across the road till the bus stop. He waits on the stop and looks up the timetable for the bus. The shopkeeper is totally out of his mind as the dog gets into the bus and sits on a vacant seat. The shopkeeper followed the dog. The dog waits for the conductor to come to his seat. He gives the change to the conductor and shows him the neck belt to keep the ticket. The shopkeeper is almost fainting at this sight and so are the other people in the bus.

The dog then moves to the front exit of the door and waits for the bus stop to arrive, looking outside. As soon as the stop is in sight he wags his tail to inform the driver to stop. Then not even waiting for the bus stop to arrive the dog jumps out and runs to the house nearby. It opens an big iron gate and rushes towards the door. As it approaches the door, he changes his mind and walks towards the garden. The dog walks up to the window and beats his head several times on the window. It then walks back to the door and waits. The shopkeeper maintaining his senses walks up to the door and watched a big guy open the door.

The guy starts beating, kicking and abusing the dog. The shopkeeper is surprised and runs to stop the guy. the shopkeeper questions the guy “What in the heaven are you doing? The dog is a genius he could be famous in life.”

The guy responds “You call this clever? This is the 3rd time in this week that the dog has forgotten the door keys.”

The moral of the story: You may continue to exceed onlooker’s expectations… But will always fall short of the bosses expectation…

{ 1 comment }