Wednesday, March 2, 2016

Sign a powershell certificate

1. Obtain code signing certificate from SSL vendor.
2. Import the certificate to the machine.
3. On powershell issue below command.

Set-AuthenticodeSignature path @(Get-ChildItem cert:\CurrentUser\My -codesign)[0]

Where path is location of the script which you want to sign. 

Friday, January 2, 2015

Stop all websites without stopping IIS

Below is the appcmd command to stop all the running sites on a IIS webserver without stopping IIS.

c:\windows\system32\inetsrv\appcmd.exe list site /xml /state:"$=started" | appcmd stop site /in

Wednesday, December 3, 2014

VB Script to list user from multiple group AD


'Populate Group details in Excel file (Vertical)
'-------------------------------------------------------

Option Explicit

Dim objConnection, objCommand, objRecordSet, objGroup, objRootDSE,objFile, objFileSystem, objMember
Dim strLine

Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objFile = objFileSystem.OpenTextFile("c:\temp\Groups-03Dec2014.xls", 2, True, 0)
objFile.WriteLine "Group Name" & VbTab & "Number of Members" & VbTab & "Members"


Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

Set objRootDSE = GetObject("LDAP://RootDSE")
objCommand.CommandText = "SELECT name, samaccountname, aDSPath,mail " &_
      "FROM 'LDAP://" & objRootDSE.Get("defaultNamingContext") & "' WHERE objectClass='group'"
Set objRootDSE = Nothing

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 600
objCommand.Properties("Cache Results") = False

Set objRecordSet = objCommand.Execute

wscript.echo "Started...!!!"

While Not objRecordSet.EOF
      Set objGroup = GetObject(objRecordSet.Fields("aDSPath"))
     
            strLine = objRecordSet.Fields("name") & VbTab
           
            strLine = strLine & objGroup.Members.Count & VbTab
           

            For Each objMember in objGroup.Members
                  strLine = strLine & objMember.Get("name") & "[" & objMember.Get("samaccountname") & "]" & ","
            Next

            If Right(strLine, 1) = "," Then
                  strLine = Left(strLine, Len(strLine) - 1)
            End If
            objFile.WriteLine strLine
     
      Set objGroup = Nothing
      objRecordSet.MoveNext
Wend

objConnection.Close
Set objRecordSet = Nothing
Set objCommand = Nothing
Set objConnection = Nothing

Set objFile = Nothing
Set objFileSystem = Nothing

wscript.echo "Completed...!!!"

Monday, June 9, 2014

IIS version and status check - Powershell

Below is the script to check IIS version and its status.

1. Copy below script and save it as .ps1

$servers = (Get-Content servers.txt)

foreach($vm in $servers){
$IISversion = get-itemproperty HKLM:\SOFTWARE\Microsoft\InetStp\  | select versionstring 
$iis = get-wmiobject Win32_Service -ComputerName $vm -Filter "name='IISADMIN'"

if($iis.State -eq "Running")
{Write-Host "IIS is running on $vm" and Version is $IISversion}

else
{Write-Host "IIS is not running on $vm"}
}

2. Populate server name in servers.txt

3. Execute the script. 

Wednesday, March 12, 2014

Backup script for IIS 7.5

1. Copy below script in notepad and save it something like backup-iis.cmd

@echo off
cls

pushd "%WinDir%\System32\inetsrv"

echo.| date | find /i "current">datetime1.tmp
echo.| time | find /i "current">datetime2.tmp

for /f "tokens=1,2,3,4,5,6" %%i in (datetime1.tmp) do (
  echo %%n>datetime1.tmp
)
for /f "tokens=1,2,3,4,5,6" %%i in (datetime2.tmp) do (
  echo %%m>datetime2.tmp
)
for /f "delims=/ tokens=1,2,3" %%i in (datetime1.tmp) do (
  set TMPDATETIME=%%k%%i%%j
)
for /f "delims=:. tokens=1,2,3,4" %%i in (datetime2.tmp) do (
  set TMPDATETIME=D%TMPDATETIME%T%%i%%j%%k%%l
)

appcmd add backups %TMPDATETIME%

del datetime1.tmp
del datetime2.tmp

set TMPDATETIME=

popd
echo.

2. Schedule it using task scheduler.

Source:http://blogs.msdn.com/b/robert_mcmurray/archive/2008/03/08/automating-iis-7-backups.aspx

Task Scheduler - C:\Windows\SYSTEM32\cmd.exe" with return code 255

Task Scheduler successfully completed task "\Run Monthly scipt" . action "C:\Windows\SYSTEM32\cmd.exe" with return code 255

You may face this error when you try to configure scheduled task using domain account. 

Resolution:

Try to run the task using local account preferably 'System' 




Wednesday, February 26, 2014

Web garden in IIS

What are web gardens?

Web gardens are different from Web farms. A Web garden is configured on a single server by specifying multiple worker processes for an application pool. Web farms use multiple servers for a Web site.
Creating a Web garden for an application pool can also enhance performance in the following situations:
  • ·         Robust processing of requests: When a worker process in an application pool is tied up (for example, when a script engine stops responding), other worker processes can accept and process requests for the application pool.
  • ·         Reduced contention for resources: When a Web garden reaches a steady state, each new TCP/IP connection is assigned, according to a round-robin scheme, to a worker process in the Web garden. This helps smooth out workloads and reduce contention for resources that are bound to a worker process.

When do we need to go for a Web garden?

More RAM:

 If you have a single process serving a site/application and compare it to a web garden of five processes serving the exact same traffic load, you'll generally see more RAM consumed on the server. Part of the reason is because just spinning up a .NET application, even with no load, requires a certain amount of memory overhead. Another reason could be related to any application caching – multiple copies of the cached data (one per process) needs to be stored.

More CPU:

Multiple processes often consume more processor capacity in a web garden even with consistent traffic loads. In general, the more processes that an OS has to track and manage, the more resources it takes. I'm not sure exactly why, but we've seen processor usage climb drastically as web garden process counts are increased. On a busy web server it can actually overload the server, where the same load in a single process might handle all requests perfectly with a much lower overall resource load.