GAC DLL Comparison in Servers using PowerShell


Hi All,

Sometimes, in BizTalk server environments, we need to check the DLL based on length. Below is the sample script for that.

At the end, it will generate CSV file that contains the mismatched DLLs.

$Filepath = Split-Path -parent $MyInvocation.MyCommand.Definition

$output = $Filepath + "\output.csv"

$Sourceserver = ‘SourceServer’ # Source Server

$DestServers = "DesinationServer1","DesinationServer2","DesinationServer3" # Desination servers that needs to GAC DLL comparison

$GACFolders = "C:\Windows\Microsoft.NET\assembly\GAC_MSIL","C:\Windows\assembly\GAC_MSIL" # these are the GAC folders that needs to be used for comparison.

$AssembliesList = @()

$DiffAssemblies = @()

$ServerAssemblies = @()

foreach ($Server in $Sourceserver)

{

foreach ($gacfolder in $GACFolders)

{

$ScriptBlockContent = {

param ($Folder)

get-childitem -Path $Folder -filter ‘*.dll’ -Recurse |select name,length,fullname }

$AssembliesList += Invoke-Command -ComputerName $Server -ScriptBlock $ScriptBlockContent -ArgumentList $gacfolder

}

}

function getsizeDiff

{

foreach ($Dserver in $DestServers)

{

$ServerAssemblies = @()

foreach ($gacfolder in $GACFolders)

{

$ScriptBlockContent = {

param ($Folder)

get-childitem -Path $Folder -filter ‘*.dll’ -Recurse |select name,length,fullname }

$ServerAssemblies += Invoke-Command -ComputerName $Dserver -ScriptBlock $ScriptBlockContent -ArgumentList $gacfolder

}

foreach ($sAssebly in $ServerAssemblies)

{

$AssembliesList | Where-Object { $_.fullname -eq $sAssebly.fullname } |ForEach-Object {

if ( $_.length -ne $sAssebly.length)

{

$DiffAssemblies += [pscustomobject] @{

ServerName=$Dserver

AssemblyName=$sAssebly.name

AssemblyFullName=$sAssebly.fullname

Size=$sAssebly.length

}

$DiffAssemblies | Select-Object -Property ServerName,AssemblyName,AssemblyFullName,Size -Unique | Export-Csv -Path $output -NoTypeInformation

}

}

}

}

}

getsizeDiff

Regards,

Chaitanya

Logging Function for Scripts


Hi All,

We often log the errors/information warning while running the scripts in PowerShell. If we have the function , then it is better to call them where ever we need it in script instead of repeatedly adding the logging code.

## function for writelogs

function WriteLogs($LogMessage, $LogType)

{

$LoggingDateTime=get-date;

write-host

"$LogType, ["+
$LoggingDateTime
+
"]:"+ $LogMessage | Add-Content -Path $LogFilepath

}

You can call this function like below

WriteLogs "***Installation failed: *** " "Error"

Regards,

Chaitanya

SSMS for Sql Server 2016


You can download Sql server management studio component. This was the new feature that was separated from Sql product which has the functionalities that supports azure features.

https://msdn.microsoft.com/en-us/library/mt238290.aspx?f=255&MSPPError=-2147217396

Regards,

Chaitanya

IIS Web Server Learning Series -Part 2 – IIS web server installation


IIS web server installation

installing iis role: –

go to Server manager, It can connect to remote computers.

After opening the server manager

Go to roles-> add roles

Check the iis web server windows feature

after that check the sub features what you want

After installation completed, check the futures in the server manager and iis web server and right click on the iis webserver and select add role services

her you got the list of sub features for the iis

under the web server

web server (Installed)

-> Common http features

->static content– non executable code like ads

->default document–when u go to microsoft.com u will go to microsoft.com/default.aspx i.e. called default document

-> Directory browsing: directory structure: most web sites not installed this. if you don’t need this one… then don’t install it

->Http errors: we can place the custom errors page instead of 401 errors

->http redirection: redirect the url

->Web DAV (distributed authoring and versioning) publishing: used to send the files to web server using the http protocol… it is not recommended.

-> Application development– here executable code is placed

->asp.net– for this u need to have .net framework installed on server, for deploying the .net application

->.net extendibility: write the .net extensions

->asp- for ASP apps, we need to install, else no need

->CGI: use for web server extensibility. it is interface between IIS and programming languages, they used the CGI script. it is having performance issues

->ISAPI Extensions:

->ISAPI filters: ISAPI is faster than CGi and it is MS one

-> server side includes: dynamically inserting html pages to website pages before it sends to client, but asp,asp.net have this functionality default

And it is used when static content is used

Server side includes: is having some performance issues

-> Health and diagnostics– for troubleshooting the web site

->Http logging–it logs the web site activity in text file. most of sites are using this one only.

->custom logging: it will logs based on programming done. no need.

->odbc logging: it will log in the DB.

->logging tools: it will manage the web server logs and automate logging tasks

->Request monitor: it monitors websites health and performance. it has the details of http request inside the worker process

we can use the this monitor which http request is process is slow

->tracing: it is used for the diagnostic and trouble shoot the web apps.. with failed request tracing u can troubleshoot events like poor performance, authentication failures.

-> Security– most of them are for authentication

->basic authentication: it is used for internal networks, not for the public networks, main disadv is the credentials (clear text) transferred over this is very easy to decrypt

if you website is not using the https…it is like getting the dialogue box and asking the credentials

->windows authentication: used for internal websites. for windows domain. don’t use it for users that are accessing the website beyond the firewalls or using the proxy servers

-> digest authentication: works by sending the password in hash format over windows controller domain, it will give more security that basic authentication for users that are accessing the website beyond the firewalls or using the proxy server

->client certificate mapping: uses client certificates to authenticate users. client certificate is digital id from the trusted source

IIS offers 2 types of mapping: this type offers one to one certificate mapping across multiple web servers

-> IIS client certificate mapping: this one is more performance and IIS offers here one to one and many to one certificate mapping. If your website is not having authentication, no need of installing all the above authentications

-> URL authorizing: preventing the users from accessing the web content by binding the rules to the users, groups, http verbs

-> Request filtering: take all request and filer it based on rules set by administrator and send it to server

-> IP address and domain restrictions: used to set certain IP address only hit or certain IP address will not hit the server.

-> Performance:

->Static content compression: compressing the static web pages, so that CPU have more band width and iis will keep it in cache

->Dynamic content compression: not recommended

->Management tools:

->IIS management console

->IIS Management scripts and tools

->Management service: it should be installed so that other that server can be IIS web connected remotely and managed

-> IIS 6 Management compatibility:

-> IIS mat abase compatibility

->IIS 6 WMI compatibility

->IIS scripting tools

->IIS 6 management console

don’t login into server and manage the iis and manage it remotely

-> FTP server:

for windows server 2008 RTM, iis 7 has the ftp 6.0 version, after that they release ftp7.o version for iis 7.0

-> FTP service

-> FTP extensibility:

> IIS Hostable web core: it is the dll file used by application developers in their application

Installing IIS through script

http://technet.microsoft.com/en-us/library/cc771209.aspx

Regards,

Chaitanya

Closing Notepad Application in Multiple Servers


Hi All,

Often some users opens notepad applications in servers and they don’t save it and they do it for temporary data usage. We can close them with one PowerShell script in multiple servers.

Below is the PowerShell script for that.

For local :

Get-Process notepad | ? { $_.CloseMainWindow() | Out-Null }

For remote server:

invoke-command -ComputerName Server1,server2 -ScriptBlock{

Get-Process notepad | ? { $_.CloseMainWindow() | Out-Null }

}

Caution : it would close all the unsaved notepads. Please make sure before proceeding further.

Regards,

Chaitanya

IIS Web Server Learning Series -Part 1 – Architecture of IIS


Architecture of IIS

Windows is the OS that divides into 2 modes

1. kernel mode: it is fastest and provides the direct access to hardware and Kernel mode has full access to every resource

things running in kernel mode are bypassing most operations as the operating system runs in this mode

Ex: device drivers

a badly written device drivers can crash the entire operating system and it causes the blue screen issue

2. User mode: where the actual s/w executes and uses the actual memory and has restricted access to resources.

it is the most protected area. if anything happened in this mode then OS will interpret and correct it but in kernel mode it is not possible

IIS is the tool which performs the operation in kernel mode and user mode:

IIS have the http listener running in kernel mode and it is listening all the requests coming from Web

IIS have the multiple websites and http listener listens the web requests and dispatches the request to the user mode process called worker process

these worker processes are seen in task manager and these took the requests and send according to the request type: if it is asp.net request then it executes the asp.net script

in addition to dispatching the request to the worker process, it will check the any requests coming from web is not having the requested pages in the server

then it discards the requests immediately.

if the worker process processing the request is of type badly written code one, then that worker process is killed and it will not affect the other worker process

Windows kill that worker process and claim the memory

IIS is having modular architecture:

Going to site in IIS gives the site information in the form of modules Like Asp.net, IIS, Management

For this IIS, you need least windows 2008 and With IIS 7.0, you will get the IIS 6.0 also

Previous of versions of IIS is using the command line for managing the IIS

IIS 7.5 uses the windows PowerShell and MS used VB script form previous versions and they deprecated and now they migrated to PowerShell scripts

Regards,

Chaitanya

Check Services which are in StopPending State in Multiple Servers


Hi All,

Below is the PowerShell script for that.

## check the services in Servers which are in state stop pending state

$computers = "server1","server2"

$array =@()

foreach ($computer in $computers)

{

$obj =New-Object psobject

$Services = Get-Service -ComputerName $computer | where { $_.Status -eq “stoppending” }

Add-Member -InputObject $obj -MemberType NoteProperty -Name Servername -Value $computer -Force

Add-Member -InputObject $obj -MemberType NoteProperty -Name Services -Value $Services -Force

$array+=$obj

$obj=$null

}

$array| select servername, services|select -ExpandProperty services|select machinename,name

Regards,

Chaitanya

PowerShell on Linux and Open Source


Hi All,

It’s not a latest news, but still a best news for all scripting lovers. Power shell is now open source project with Linux support.

Power shell is automation scripting language for windows environment, now making its move towards other systems. It’s one of key mile stones in Microsoft.

Below is the information on this.

https://blogs.msdn.microsoft.com/powershell/2016/08/18/powershell-on-linux-and-open-source-2/

At the end ,I want to say everyone who is reading this post : Happy Scripting to All.

Regards,

Chaitanya

Check Remote Servers Ping Status


Hi All,

Below is the sample script for that.

# check the servers are pingable or not

$computers = "Server1","localhost"

$computers | where { -not (Test-Connection $_ -quiet -Count 1)}

Regards,

Chaitanya

How to un Install Applications using PowerShell


Hi All,

Below is the sample script for that. Run this in your local desktop.

# uninstall using Below script

$programs = @(“Google Update Helper”, “Java 7 Update 79 (64-bit)”)

foreach($program in $programs){

$app = Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -like "$program" }

Write-Host "Uniinstalling Application $($app.name)"

$app.Uninstall()

Write-Host "UninStall Complete for app $($App.Name)"

}

Make sure to test it in your local /test server first before doing it in other environments.

Regards,

Chaitanya

Design a site like this with WordPress.com
Get started