Tuesday, June 22, 2010

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

Hi,

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 -

1> ADSI
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.

----------------------

Param(



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


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


,[switch]$doNotRestart


,[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


$output


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


}






Function Trim-AppPoolName ($appPoolName){
[string]$appPoolName.Substring(15)
}



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


foreach ($computer in $computers)


{



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


$iis

$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 -
http://support.microsoft.com/default.aspx/kb/939308?p=1

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]"
$obj.Terminate()


}


 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.