Tag Archives: scripts

Scripts for taking K2 service memory dumps

I’ve spent some time today improving “create K2 service memory dump script” (one which I already mentioned in “K2 MSMQ thread & MSMQ abort exception” blog post) and creating “collect dump support files”. Next step will be merging them into one and adding some nice to have things I have no time for right now.

Collect dump support files script (GitHub link):

$DumpPath='C:\Dumps'
$NetV2='C:\Windows\Microsoft.NET\Framework\v2.0.50727'
$NetV2x64='C:\Windows\Microsoft.NET\Framework64\v2.0.50727'
$NetV4='C:\Windows\Microsoft.NET\Framework\v4.0.30319'
$NetV4x64='C:\Windows\Microsoft.NET\Framework64\v4.0.30319'

$NetV2Dump="$DumpPath\Microsoft.NET\Framework\v2.0.50727"
$NetV2x64Dump="$DumpPath\Microsoft.NET\Framework64\v2.0.50727"
$NetV4Dump="$DumpPath\Microsoft.NET\Framework\v4.0.30319"
$NetV4x64Dump="$DumpPath\Microsoft.NET\Framework64\v4.0.30319"

If (!(Test-Path $DumpPath))
{
Write-Host 'Creating folder'
(New-Item $DumpPath -ItemType Directory | out-null)
} 
Else {
Write-Host 'Folder already exist'
}

Write-Host "Attempting to copy $NetV2\mscordacwks.dll" -ForegroundColor Green
If (!(Test-Path "$NetV2\mscordacwks.dll"))
{
Write-Host "$NetV2\mscordacwks.dll - File not found, skipping" -ForegroundColor Red
}
Else 
{

If (!(Test-Path "$NetV2Dump")) {New-Item "$NetV2Dump" -Type Directory | out-null}
Copy-Item "$NetV2\mscordacwks.dll" -Destination "$NetV2Dump\mscordacwks.dll"
Write-Host "Done!" -ForegroundColor Green
}

Write-Host "Attempting to copy $NetV2\sos.dll" -ForegroundColor Green
If (!(Test-Path "$NetV2\sos.dll"))
{
Write-Host "$NetV2\sos.dll - File not found, skipping" -ForegroundColor Red
}
Else 
{

If (!(Test-Path "$NetV2Dump")) {New-Item "$NetV2Dump" -Type Directory | out-null}
Copy-Item "$NetV2\sos.dll" -Destination "$NetV2Dump\sos.dll"
Write-Host "Done!" -ForegroundColor Green
}

Write-Host "Attempting to copy $NetV2x64\mscordacwks.dll" -ForegroundColor Green
If (!(Test-Path "$NetV2x64\mscordacwks.dll"))
{
Write-Host "$NetV2x64\mscordacwks.dll - File not found, skipping" -ForegroundColor Red
}
Else 
{

If (!(Test-Path "$NetV2x64Dump")) {New-Item "$NetV2x64Dump" -Type Directory | out-null}
Copy-Item "$NetV2x64\mscordacwks.dll" -Destination "$NetV2x64Dump\mscordacwks.dll"
Write-Host "Done!" -ForegroundColor Green
}

Write-Host "Attempting to copy $NetV2x64\sos.dll" -ForegroundColor Green
If (!(Test-Path "$NetV2x64\sos.dll"))
{
Write-Host "$NetV2x64\sos.dll - File not found, skipping" -ForegroundColor Red
}
Else 
{

If (!(Test-Path "$NetV2x64Dump")) {New-Item "$NetV2x64Dump" -Type Directory | out-null}
Copy-Item "$NetV2x64\sos.dll" -Destination "$NetV2x64Dump\sos.dll"
Write-Host "Done!" -ForegroundColor Green
}

Write-Host "Attempting to copy $NetV4\mscordacwks.dll" -ForegroundColor Green
If (!(Test-Path "$NetV4\mscordacwks.dll"))
{
Write-Host "$NetV4\mscordacwks.dll - File not found, skipping" -ForegroundColor Red
}
Else 
{

If (!(Test-Path "$NetV4Dump")) {New-Item "$NetV4Dump" -Type Directory | out-null}
Copy-Item "$NetV4\mscordacwks.dll" -Destination "$NetV4Dump\mscordacwks.dll"
Write-Host "Done!" -ForegroundColor Green
}

Write-Host "Attempting to copy $NetV4\sos.dll" -ForegroundColor Green
If (!(Test-Path "$NetV4\sos.dll"))
{
Write-Host "$NetV4\sos.dll - File not found, skipping" -ForegroundColor Red
}
Else 
{

If (!(Test-Path "$NetV4Dump")) {New-Item "$NetV4Dump" -Type Directory | out-null}
Copy-Item "$NetV4\sos.dll" -Destination "$NetV4Dump\sos.dll"
Write-Host "Done!" -ForegroundColor Green
}

Write-Host "Attempting to copy $NetV4x64\mscordacwks.dll" -ForegroundColor Green
If (!(Test-Path "$NetV4x64\mscordacwks.dll"))
{
Write-Host "$NetV4x64\mscordacwks.dll - File not found, skipping" -ForegroundColor Red
}
Else 
{

If (!(Test-Path "$NetV4x64Dump")) {New-Item "$NetV4x64Dump" -Type Directory | out-null}
Copy-Item "$NetV4x64\mscordacwks.dll" -Destination "$NetV4x64Dump\mscordacwks.dll"
Write-Host "Done!" -ForegroundColor Green
}

Write-Host "Attempting to copy $NetV4x64\sos.dll" -ForegroundColor Green
If (!(Test-Path "$NetV4x64\sos.dll"))
{
Write-Host "$NetV4x64\sos.dll - File not found, skipping" -ForegroundColor Red
}
Else 
{

If (!(Test-Path "$NetV4x64Dump")) {New-Item "$NetV4x64Dump" -Type Directory | out-null}
Copy-Item "$NetV4x64\sos.dll" -Destination "$NetV4x64Dump\sos.dll"
Write-Host "Done!" -ForegroundColor Green
}

Take K2 service process dump (GitHub link):

# Obtain K2 service PID
$procid=get-process "K2HostServer" |select -expand id
# Create target folder if not exist:
$DumpPath="C:\dumps"
If (!(Test-Path $DumpPath))
{
Write-Host 'Creating folder'
(New-Item $DumpPath -ItemType Directory | out-null)
} 
Else {
Write-Host 'Folder already exist'
}
# -ma - Write a full dump file which includes All the Image, Mapped and Private memory
# -ma - Just takes a full dump immidiately from running process
# -e -ma - takes full dump file on unhandled exception aka crash dump
C:\procdump\procdump.exe -accepteula -ma $procid $DumpPath\k2hostserver.dmp

Be sure checking out GitHub links as I keep editing/updating these scripts there.

Please follow and like us:

SQL Script: List all tables in DB with their row counts

Often I need to test something and use SQL database table of particular size for my test, and sometimes it is easier to pick up some table of appropriate size (at least in terms of rows number) from what you already have. This is the case when this SQL script may come in handy:

DROP TABLE #counts

CREATE TABLE #counts

(

table_name varchar(255),

row_count int

)

EXEC sp_MSForEachTable @command1='INSERT #counts (table_name, row_count) SELECT ''?'', COUNT(*) FROM ?'

SELECT table_name, row_count FROM #counts ORDER BY row_count DESC

Please follow and like us:

How to: get a number of lists and lists items for SharePoint site collection

The fastest way to do it is to use following PS script:

Add-PSSnapin Microsoft.Sharepoint.Powershell

$ListsInfo = @{}

$TotalItems = 0

$SiteCollection = Get-SPSite "http://sitecollection.domain.com/"

ForEach ($Site in $SiteCollection.AllWebs)

{

ForEach ($List in $Site.Lists)

{

$ListsInfo.Add($Site.Url + " - " + $List.Title, $List.ItemCount)

$TotalItems += $List.ItemCount

}

}

$ListsInfo.GetEnumerator() | sort name | Format-Table -Autosize

Write-Host "Total number of Lists: " $ListsInfo.Count

Write-Host "Total number of ListItems: " $TotalItems

It will count all the lists and number items inside of these lists, plus output total lists number and total items number in all lists for site collection URL of which you specify in 4th line of this script. This script works both for SharePoint 2010 and 2013.

If you are on look out for script to generate some list items for testing purposes you may find exactly what you need in Cameron Dwyer’s blog, in the following post “SharePoint PowerShell How To: Create SharePoint List Items (in Root and in Folders) for Load/Performance Testing.”

Please follow and like us: