Tuesday, November 30, 2010

How to repair and re-install WMI on a Windows 2003 server

We need to restart the server if we do a repair or reinstall of the WMI. We repair WMI components on the server and if it does not work, then reinstall and restart the server.

We need to follow the below steps in order to Repair WMI :-

1> Open a command prompt window (Run as Administrator) and change directory (cd) to %windir%\System32\wbem on 32bit Windows or %windir%\SysWOW64\wbem on 64bit Windows

2> Run both these commands one at a time-

a> FOR %i in (*.dll) do RegSvr32 -s %i
b> FOR %i in (*.exe) do %i /RegServer
c> FOR /f %s in ('dir /b /s *.dll') do regsvr32 /s %s

3> Net stop /y winmgmt

4> FOR /f %s in ('dir /b *.mof *.mfl') do mofcomp %s

5> Net start winmgmt

We need to verify by running any WMI query to check if the WMI is working on the server or not. If the issue is still not resolved, then we need to use the following command to detect and repair a corrupted WMI Repository:

a> rundll32 wbemupgd, RepairWMISetup
b> we need restart the server.

We need to verify by running any WMI query to check if the WMI is working on the server or not. If the issue is still not resolved, then we need to perform the Comprehensive Rebuild Method.

Important note: If you've installed a Service Pack, you need to insert your Windows XP CD with Service Pack integration (called as the Slipstreamed Windows XP CD). If you don't have one, you may point to the %Windir%\ServicePackFiles\i386 folder for a recent version of the system files required during WMI repair. Or you may create a slipstreamed Windows XP CD and insert it when prompted.

Click Start, Run and type the following command, and press ENTER:

1> rundll32.exe setupapi,InstallHinfSection WBEM 132 %windir%\inf\wbemoc.inf

Insert your Windows XP CD into the drive when prompted. Repair process should take few minutes to complete. Then restart Windows for the changes to take effect.
Hope this helps someone.

Thursday, September 2, 2010

How to enable the Three State Workflow in a Document Library in Sharepoint

The Three State Workflow, is by default disabled in Document Library but is enabled in Tasks in the Sharepoint Site.

Here we will see how do we enable the Workflow States which are greyed out by default.


When we open the Document Library and then go to the "Document Library Settings". Then we click on the link "Workflow Settings". We go to a page where we provide the Workflow name and then click on next button. In the other page, we get the section Workflow States and that section is greyed out. So we are stuck here when we try to create the workflow for the document library.


Here we have to create a column with the type of information in that column should be "Choice". And then add three options like, open, resolved and closed. Thats the reason why we call the workflow as 3 state workflow.
Once that column is specified, Now go ahead and create the workflow. Here in the "Workflow States" section you can see the options and the column name coming up without any issues.

If you try the same on the Tasks, you wont be facing such issue,as already that kind of choice column would be already present.

Hope this helps some onw.

How to disable the "New Folder" option in a document library in Sharepoint

When we go to a document library in a Sharepoint Site, we often see an option on the top as "New" which provides us an option to create a new document or new folder.

There may be a requirement which may come up that folder creation should be restricted for a particular document library.

We can follow the below steps to implement the same -

1> Open the Document library and click on "Settings" tab which comes besides the "Actions" tab.
2> Then select the "Document Library Settings"
3> Now go to "Advanced Settings" link and click on it.
4> There you will find out there is a "Folder" section, where it asks "Display "New Folder" command on the New menu?". Select the option as "No".

Then we are done. Go back to the Document library and click "New". you will get only the "New Document" option.

I would this implementation to be done for small Document Libraries. But for large Document Libraries, it is advisable to split the documents into various folders which inturn would improve the performance.

Hope this helps someone.

Wednesday, September 1, 2010

Installing SP2010 pre-requisites

Installation of Sharepoint 2010 Pre-requisites-

1> 64 bit Windows Server 2008 (2 in no.)
2> IIS 7.0 needs to be installed on web server
3> SQL 2008 is the database server

Steps to install Sharepoint 2010 on web server -

1> To install the O14 sharepoint, firstly run the pre-requsisteinstaller.exe file. This should install the following files and exe

a> IIS server role.

b> Power shell 1.0

c>.NET framework 3.5 SP1

d> MS windows Installer 4.5

e> MS "Geneva framework"

f> MS Synch framework runtime v1.0

g> MS chart controls for MS .NET Framework 3.5

h> MS filter pack 14

i> MS 2008 client utility

2> Once the pre-requsites are installed, executables are downloaded to the local system. Then the Sharepoint Configuration Wizard comes up. Then click on Next which will start the configuration.

It is important to have internet connection on the server as it connects to internet to download the above requirements.

Tuesday, June 22, 2010

Logging of IIS AppPools status for remote servers (Win 2003) using PowerShell


I was having a struggle in writing a script which would log the status of the App Pool from across all the remote servers. I tried using two things -

2> Get-WMIObject

Using the ADSI, I faced issue in which it was not able to access the remote server. It used to say RPC server unavailable. But the same when I tried using Get-WMIObject, it was able to get data from remote server. The catch here was, the Children class was availabe from ADSI but the same was not found using Get-WMIObject . Finally I was able to write the script using the Get-WMIObject.



[string]$global:computer = $env:COMPUTERNAME

,[string]$LogDir = "d:\AppPoolLogging"


,[switch]$enableLogging = $true


function Convert-AppPoolState([int]$value){

switch ($value){

1 {"Starting"; break}

2 {"Started" ; break}

3 {"Stopping"; break}

4 {"Stopped" ; break}

default {"Unknown"}



Function Write-Log($appPoolName,$message){

$dateTime = Get-Date -format "yyyyMMdd"

$LogFile = "$dateTime.log"

$logPath = join-path $LogDir $LogFile

$output = (Get-Date -Format "yyyyMMdd_HH:mm:ss") + "|" + $computer + "|" + $appPoolName + "|" + $message


If ($enableLogging) {$output | Out-File $logPath -Append}


Function Trim-AppPoolName ($appPoolName){

$computers = Get-Content "c:\computerlistall.txt"

foreach ($computer in $computers)


$iis = Get-WmiObject -Namespace root\MicrosoftIISv2 -Class IIsApplicationPoolSetting -ComputerName $computer -Authentication PacketPrivacy


$i = $iis.Count

for ($k = 0; $k -lt $i; $k++)

$name = $iis[$k].Name

$ApplicationPoolName = Trim-AppPoolName $name

$state = $iis[$k].AppPoolState

$Status = Convert-AppPoolState $state

Write-Log $ApplicationPoolName $Status



Monday, June 14, 2010

Installing the SMTP and POP 3 Services on Windows Server 2003

I know this would be real old stuff and many would be aware of these. But I would like to share it with respect to Sharepoint where we have to configure the incoming and outgoing mails. I would like to start from the beginning and provide other steps for configuring mails in sharepoint later. Hope you enjoy the post.

1> Click Start --> Control Panel --> Add or Remove Programs.
2> Click the Add/Remove Windows components button to the left of the Programs list. The Windows component wizard will appear.
3> Select Application Server and then click on the Details button below.
4> When the Application Server Dialogue box appears, Click Internet Information Services(IIS) to select it and then again click on the Details button below.
5> Tick the SMTP service check box and click OK. Then click OK again in the Application Server Dialogue box.
6> Click OK and in the Windows Component wizard dialogue box, tick the E-mail Services check box. Then click the Details button.
7> verify that both the POP 3 Service and POP 3 Service Web Administration is selected and ticked. Then Click OK.
8> In the Windows Components Wizard Dialogue box, click Next to install all the components.
9> If you have your windows 2003 CD, it will call the folder "i386" and then will install all the components. If you dont have the CD, you need to get a copy of that folder and then run the Component which shall install the components requested.

Sunday, April 25, 2010

Clearing SharePoint Configuration Cache

SharePoint stores some of the configuration in a cache on the SharePoint servers instead of makings calls to SQL Server (Config DB) every time inorder to improve performance.
But sometimes, this cache might have old or corrupted data which might cause timer jobs to fail.There would be cases where you want to take out a server from the farm and that doesn't refresh properly. Also there is a possiblity that this issue may come up when we change the service account of the sharepoint farm.

To clear the cache, we need to follow the steps below

Note: This operation will break your farm, if we delete the “GUID folder” or the “Cache.ini file”.
1> On all Servers in the farm, stop the Windows SharePoint Services Timer service (OWSTIMER.EXE). To do this go to the Services Console, right click on Windows SharePoint Services Timer service and click stop.

2> After this go the SharePoint Server running Indexing Server and navigate to “System Drive\Documents and Settings\All Users\Application Data\Microsoft\SharePoint\Config\GUID” in case of Windows Server 2003 or “System Drive\ProgramData\Microsoft\SharePoint\Config\GUID” in Windows Sever 2008.

3> In the folder there is single “cache.ini” & rest all are XML files. Delete all the XML files except for the “Cache.ini file”, make sure we do not delete the “cache.ini”. This is very important, do not even delete the whole GUID folder too, this is also very important. Do not delete the GUID folder or the cache.ini file!

4> Now open the “cache.ini” file and note down the number. Clear the number and type in 1.

5> Click save and close the “Cache.ini” file.

6> Now start the Windows SharePoint Services Timer Service on the Indexing Server from the services console.

We will see all XML files being generated again. We open the Cache.ini and we will see same the number, as you noted down before.

We need to repeat steps 2-6 on all queries servers followed by application/web servers.

Reference -

Friday, April 23, 2010

What is windows server core in Windows server 2008?

When I was installing Windows server 2008 R2 I came across the option where I had to install either Windows Server R2 Full install and other one was Windows R2 Server Core Installation.

Anyone thought what is Windows server core installation in 2008? I did some analysis. let me explain what is this all about.

What is Windows Server Core?
Windows Server Core is a type of install which installs what is needed to make the Hadware a server. The basics to call the hardware a server. We can call this as a "THIN" install.

Whats the difference between the regular install and the server core install?

a> Server core doesnt have a GUI. Command prompt is used for all the tasks.
b> There are no desktop Icons. Notepad, remote desktops access have got GUI.
c> There is no upgrade from windows 2003 to Windows 2008 server core. We need to go for fresh install.

Advantages -

1> Easier to secure,manage and maintain. It has reduced attack surface as less services and less applications are present. reduced management as less parts are present to manage.
2> Lower hardware requirement. So less maintenance overhead. minimum requirement is about 1.6 GB hard drive space, lower processor overhead and lower memory requirement.
3> Supports unattended installations. It can be fully automated.
4> Supports key infrastructure roles like IIS, AD DS, DHCP, DNS, AD LDS etc.

Disadvantages -

1> few roles not compatible with server core.
2> no windows GUI. work to be done using command prompt.  For example, you can open notepad GUI by typing notepad.exe on cmd . Also the datepalce by tping timedate.cpl on cmd.
3> There is not .NET framework or IE on the server.
4> This needs a fresh installation.

Configuring on server core -

using the command on the command prompt -
start /w ocsetup

This command will help you inconfiguring roles, AD DS, IIS etc.

Monday, March 22, 2010

Killing a process consuming more memory using PowerShell

There would be performance issues coming up in a server where we find that the server memory is being consumed by unnecessary processes. In order to prevent its unnecessary memory consumption, We can use the below powershell script which shall kill the process that consumes 100000000 KB of memory.

$computer = "mymachine"

$a = Get-Process -ComputerName $computer
$objs = $a | where-object {$_.WorkingSet -gt 100000000}
$processes = $objs | select {$_.ProcessName}

$i = $processes.Count

for ($k = 0; $k -lt $i; $k++)


$obj=get-wmiobject -comp $computer -query "select * from win32_process where name=$processes[$k]"


 Hope this helps....

List of services running on the server using PowerShell

As a systems administrator, there would always be a requirement for us to check if the particular services in the servers are running on that. To fix this, we can use the powershell script which shall give us the list of services running on a particular server and its status. We can also have a list of servers and get the powershell script run which would give details of the services from all the servers, We need to make sure that the account using which you would run this script is an administrator on all the servers on which you want to validate.

The powershell script is

$a = get-wmiobject win32_service -ComputerName "mymachine"

$a | select name,startname,startmode,state

Hope this helps....

Monday, March 15, 2010

Configuration Database details in Registry of the Sharepoint Server

For MOSS 2007, we can find the details about the configuration database and the SQL server where it's hosted in the below path in the registry of the sharepoint server.

HKLM\Software\Microsoft\Shared Tools\Web Server Extensions\12.0\Secure\ConfigDb

This path is applicable for WSS 3.0 also.

When we are planning for the migration of the SQL server and we face any issue during that, we can validate if the sharepoint is pointing to the correct SQL server or not from the above path.

Hope this helps someone.

Monday, March 1, 2010

Configuring FBA in MOSS 2007

What is LDAP?
Many a times this question comes up and how can we integrate it with Sharepoint. LDAP stands for Light Directory Access Protocol. In sharepoint, its equivalent to FBA i.e. Form Based Authentication.

FBA in Sharepoint is always recommended for Extranet sites and for the internet sites. The reason for not setting up it in intranet is very nicely explained by Nick in his blog http://planetmoss.blogspot.com/2009/02/using-ldap-authentication-with.html .

Well, coming to configuration for the FBA, I configured it following the steps from the site http://www.fivenumber.com/configuring-ldap-authentication-in-moss-2007/ and this worked as a charm for me.
I am providing the details in brief -
1> Create a website and extend it. Once the website is extended, select authentication as NTLM.
2> Copy and paste the tags which are basically the membership provider registration as mentioned in the site above. make sure that you provide your server name in the tags.
3> Once done, go to Central Administration > Application Management > Authentication Providers
Click on the extended web application, then select authentication type as Forms.
4> then click on Save.
5> Add the LDAP user. Once done, try to access the extended site using the LDAP user that was added.

Tuesday, February 16, 2010

Orphaned sites in MOSS 2007

There has been issues related to orphaned items present in the sharepoint sites. Inorder to detect and delete the orphaned items follow the commands as mentioned below...

Detect an orphan site

To detect orphaned items, use the following syntax:

stsadm -o databaserepair -url http://sharepointsite/ -databasename [name of DB where orphaned site is present]

Delete an orphan site

To delete orphaned items, use the following syntax:

stsadm -o databaserepair -url http://sharepointsite/  -databasename [name of DB where orphaned site is present] -deletecorruption

For more reference on this http://technet.microsoft.com/en-us/library/cc263282.aspx

Hope this helps someone...

Friday, January 22, 2010

Deleting a WebPart from a Page using PowerShell

I had come across a requirement where I had to automate the deletion of the webpart from the page and not from Webpart Gallery. I have written a PowerShell script that takes care of the above requirement. WebPart.txt file contains the name of the webparts that needs to be deleted from the page.




$url = "http://myserver"
$WebPageUrl = "Pages/Default.aspx"
$wpNames = Get-Content "c:\Powershell\webparts.txt"
$SPSite = New-Object Microsoft.Sharepoint.SPSite($url)
$SPWeb = $SPSite.OpenWeb()

foreach ($wpName in $wpNames)
$SPWebPart = $SPWeb.GetWebPartCollection($WebPageUrl,

$SPWebPart | select Title
$count = $SPWebPart.Count

for ($k = 0; $k -lt $count; $k++)
    $wp = $SPWebPart[$k]

        if ($wp.Title -eq $wpName)


           $SPWeb = $SPSite.OpenWeb()
           $pubweb = [Microsoft.Sharepoint.Publishing.PublishingWeb]::GetPublishingWeb($SPWeb)
           $d = $pubweb.GetPublishingPages()
           $SPPage = $d.get_Item($WebPageUrl)
           $Page = $SPPage.ListItem.File

          if ($Page.Level -eq [Microsoft.SharePoint.SPFileLevel]::Checkout)
             $SPWebPart = $SPWeb.GetWebPartCollection($WebPageUrl,[Microsoft.SharePoint.WebPartPages.Storage]::Shared)

            $SPPage.CheckIn("Checked in")

Write-Host " $wpName Deleted"

$SPWebPart = $SPWeb.GetWebPartCollection   ($WebPageUrl,Microsoft.SharePoint.WebPartPages.Storage]::Shared)

$c = $wp.StorageKey
$SPPage.CheckIn("Checked in")

Write-Host "$wpName Deleted and Checked in"
Write-Host " $wpName not found"

Deleting WebPart from a WebPart Gallery using PowerShell

Here I shall show you how to delete a webpart of a list of webparts from the WebPart Gallery of a particular Sharepoint Site. webparts.txt contains the list of webparts that needs to be deleted from the gallery. Note that the webpart name should be in the form of webpart1.webpart or webpart.dwp as in the url http://myserver/_catalogs/wp/Forms/AllItems.aspx 



$url = "http://myserver/"

$wps = Get-Content "c:\Powershell\webparts.txt"
$SPSite = New-Object Microsoft.SharePoint.SPSite($url)

foreach($wp in $wps)
$SPWeb = $SPSite.OpenWeb()
$WebPartGallery = $SPWeb.Lists["Web Part Gallery"]

$gall = $WebPartGallery.Items | select Name

$count = $gall.Count
for ( $i =0; $i -lt $count;$i++)
if ($gall[$i] -match $wp)
Write-Host "found"
Write-Host "$wp deleted"

Hope this helps someone....

Tuesday, January 19, 2010

Adding a Child node to an XML file using PowerShell

There has been a need to add a child node to an XML file. Doing that using powershell can be seen here
[xml]$Config = Get-Content "C:\tofolder\Files\myfolder\config.xml"
$element = $Config.CreateElement("MyKeyElement")
$element.setattribute("Value", "xxxyyyzzz")

Thus, saving the config file appends the changes in the config file. Once you open the config.xml after running the above script you can see "MyKeyElement" element has been updated with its value in the config.xml file.

Hope this helps someone.

To find the port number of the Central administration using powershell

In Order to find the Central administration port number in MOSS 2007, you can run the below script to get the port number.


In Order to get the same in SP2010, you can run the below powershell script



Also you can run the below powershell line. this shall give you the web application URLs of all web applications.

Get-SPWebApplication -IncludeCentralAdministration

Hope this helps..

Tuesday, January 12, 2010

copying of folders and subfolders from one location to another using powershell

There has been a need to copy folders and subfolders inside from one location to another. I have used powershell to do the same. First by creating a new folder and then copying the files, folders and sub folders inside that new folder.
$server1 = "Server1"
$tofolder = "NewFolderName"
$fromfolder = "OldFolderName"
$frompath = "
$topath = "
New-Item -Name $tofolder -ItemType Directory -Path $topath
Copy-Item -Path $frompath\$fromfolder\* -Destination $topath\$tofolder -Force -Recurse
Write-Host Copying of the latest sharepoint build $tofolder is done

Hope this helps...

Monday, January 4, 2010

finding out disk space and free space percentage for the servers using powershell

It is necessary for the server administrators to keep an eye on the disk space issues that come up now and then. Its nearly impossible to check the disk space by logging into the servers if there are about 50-100 of them, on a daily basis and verify the same. I have written a powershell script, that will help to keep a track of the disk space and also in terms of percentage the free space available and take actions accordingly.

del "C:\Powershell\lowdisk.xls"
echo "ServerName DriveName DriveSize FreeSpace PercentFree" >> "C:\Powershell\lowdisk.xls"
$computers = Get-Content "c:\Powershell\computerlistall.txt"
foreach ($computer in $computers)
$a = Get-WmiObject -ComputerName $computer -Class Win32_LogicalDisk Where-Object{$_.DriveType -eq 3}
if ($a.DeviceID -eq "C:")
$FSize = ($a.FreeSpace)/1GB
$TSize = ($a.Size)/1GB
$PerFree = ($FSize/$TSize)* 100
#echo "ServerName DriveName DriveSize FreeSpace PercentFree" >> "C:\Powershell\lowdisk.xls"
echo "$computer $driveName $TSize $FSize $PerFree" >> "C:\Powershell\lowdisk.xls"
$i = $a.Count
#echo "ServerName DriveName DriveSize FreeSpace PercentFree" >> "C:\Powershell\lowdisk.xls"
for ($t = 0)
$driveName = ($a[$t].DeviceID)
$FSize = ($a[$t].Freespace)/ 1GB
$TSize = ($a[$t].Size)/1GB
$PerFree = ($FSize/$TSize)* 100

echo "$computer $driveName $TSize $FSize $PerFree" >> "C:\Powershell\lowdisk.xls"
if ($t -eq $i)
if ($PerFree -lt "40.00")
Write-Host $PerFree -BackgroundColor Red >> "C:\Powershell\lowdisk.xls"
Write-Host "disk space check completed for " $computer