Tag Archives: PowerShell

How to quickly grab K2 HTTPS certificate thumbprint using PowerShell

I’ve already mentioned this in my old blog post (along with GUI way for this task), but just posting this separately for better visibility/searcheability 🙂

In case you need to obtain thumbprint value of your K2 site HTTPS certificate (or any other certificate) you can use this PowerShell script:

If necessary you can put it into variable and reuse in other commands/script, just replace “Write-Host” with “$thumbprint = ” to store certificate thumbprint value in $thumbprint variable. Just don’t forget to change filter argument  “K2.domain.com” to something that is relevant for your certificate.

Facebooktwittergoogle_plusredditpinterestlinkedinmail

New-SPAppManagementServiceApplication : A SharePoint database named XYZ already exists.

I was configuring SharePoint app catalog service applications the other day using my old scripts for that, and there is one problem I often see when using PowerShell scripts for configuring SharePoint: those work much better as they save your time you may spend on wading through cumbersome GUI, but in case when you need to re-run this script once again (let’s say it failed in the middle as you not updated some of the variables with proper values, or forgot to adjust something in line with your naming convention), you are often in trouble as you need to clear up things created by the script before you will be able to re-run it without errors.

Normally (especially if you fully understand what your script actually does) it is not a big problem, but this time when creating App Management Service Application I run into this error:

New-SPAppManagementServiceApplication : A SharePoint database named SP2013_AppManagementSvc already exists. You must supply another
name for the new database.

Looks like straightforward error which prompts to fire off SSMS and drop DB in question and I think I did it before, but this time there was NO such DB on SQL server yet I keep receiving this error. A bit of Googling showed me that I just have a reference to this DB in Objects table of SharePoint configuration database. So we can use SQL script (GitHub link) to search and if necessary remove it:

Little quick fix, but as usual in case it is anything like production environment better take DB backup before messing with anything in it.

Facebooktwittergoogle_plusredditpinterestlinkedinmail

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):

Take K2 service process dump (GitHub link):

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

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Configuring SQL instance firewall rules via PowerShell

Doing distributed environments setups rather frequently these days I realized that I really don’t want wasting my time setting up SQL Server firewall rules via GUI (I described the process here) and luckily enough Ryan Mangan already created such script. All I had to do is try it (confirm that it works), save it on GitHub and share on my blog for the benefit of wider community:

Original blog post by Ryan/source of this script: PowerShell Script for SQL Firewall rules

Facebooktwittergoogle_plusredditpinterestlinkedinmail

How to: configure K2 NLB port rules with PowerShell

Long time ago I did a video and blog post on configuring Windows NLB K2 cluster. I know that those materials are not perfect, but thanks to blogging you not only can be subject of mockeries for mistakes and naivety in your old posts, but also you can review and improve on them over time 🙂

Anyhow my old blog post on creating K2 NLB cluster contained this neat picture of required port rules:

As I tread my test K2 environments as “wipe and load”-ready and subject them to all sort of experiments leading to wipe and load and rebuilds I grow tired of creating this rules via GUI. Thanks to PowerShell and Microsoft Community it is not a problem to find a sample script to create Windows NLB cluster. I actually wanted to rewrite it with minor improvements and K2 specifics to spin off K2 NLB cluster quicker but due to endless lack of time this idea moved on the back-burner. What I did instead though is prepared PS script to create port rules:

That’s help a bit when I rebuilding my test environment. You can grab this script from GitHub too.

Facebooktwittergoogle_plusredditpinterestlinkedinmail

PS script to get SQL version from BAK file

Quite unpleasant thing about MS SQL Server database backup files it that you can’t restore them on an older version of SQL Server (it seems that even if you really want to create such BAK file it is not possible), moreover this is valid not only for major versions but also for things like R2, meaning you can’t restore BAK file created in SQL Server 2008 R2 on SQL Server 2008 Server (non-R2).

Just to save my time trying to restore BAK files against wrong versions of SQL Server I created this script which allows you to retrieve SQL version from BAK file headers and compare it with your server SQL version. Specify path to your BAK file and check the output – if BAK file SQL version is newer that your server version then BAK file can’t be restored on this server. Sample script output can be found below:

It tells you that backup was taken on SQL Server 2012 SP3, while you run SQL Server 2012 SP2. Once you install SP3 for SQL Server script output will change to this:

Once two numbers match you are ready for backup restore 🙂

Facebooktwittergoogle_plusredditpinterestlinkedinmail

How to: quickly check which installation type of Windows Server you are using?

Just a quick how to post. When you do more and more remote management with PowerShell it may be necessary for you to quickly check if you run Full Server or Core or Nano. And unless you never logon locally to the box you and you only managing it via PowerShell then you may be not very sure if it is running Full Server, Minimal Management Interface, Core or Nano. There is a ServerLevel registry key available starting from Windows Server 2012, and quick look up for its value will answer this question:

Sample output you may see in case of Nano Server:

Another use case for this key is when you writing a script and need to adjust its behavior depending on whether it is being executed on Full Server, Core or Nano.

Facebooktwittergoogle_plusredditpinterestlinkedinmail

System.IO.IOException : The requested operation could not be completed due to a file system limitation

I recently had a support case thanks to which I discovered rather cool way of checking out on big files in specific directory which I will describe later here.

Under certain conditions you may see the following issue in K2: very high CPU usage and by extension overall sluggishness of K2 applications accompanied with “System.IO.IOException : The requested operation could not be completed due to a file system limitation.”

As in most of the cases error message itself indicates what is wrong here and “The requested operation could not be completed due to a file system limitation” should ring a bell for you that some file or files run amok and growth beyond file system limits or something along these lines. If you read your logs even more closely they may even give away specific culprit to you indicating log file name which is responsible for this.

K2 has broad logging capabilities for monitoring and troubleshooting purposes (quite good overview of K2 logging can be found here) but in terms of logging volume main suspects are: SmO logging (the only logging which can’t be capped in terms of file size), ADUM logs (very voluminous, especially on debug logging level; file size can be limited by adjusting configurable settings, meaning that you have to go extra mile if you want to allow unhealthy big file name) and lastly debug assemblies you may receive from K2 support. Debug assemblies usually are quickly build ad-hoc troubleshooting tools to investigate specific issue and may well not have log file limit and write super detailed logging (=voluminous log files). As such those supposed to be removed upon completion of your troubleshooting effort, but in reality can be left applied for a while which gradually evolves into forever…

Anyhow exception “System.IO.IOException : The requested operation could not be completed due to a file system limitation.” in K2 host server log in most of the cases caused by abnormally high in size log file, which becomes so big that it exceeds RAM size which makes it difficult to open it and append for writing, and then you have that slippery slope situation with degraded performance and high CPU moment, and to that “aha, I forgot to disable/remove unneeded logging” moment.

Now my take away from this case (though what is said above also worth noting). How to quickly check on huge files in specific directory. Just use this PS script:

You may add “-First 10” parameter right after Select-Object in the script above to minimize output which is especially useful when you primarily interested to identify largest file or files.

Here is how the result for healthy K2 folder looks like (by healthy I mean one without strangely big log files):

Large files search

As you can see normally you should not have anything with size of 1 gigabyte more, but above mentioned exception is usually caused by 10-20 GB log file which will be featured prominently on the top of the output.

See also related K2 community KB: Exception – The requested operation could not be completed due to a file system limitation.

Facebooktwittergoogle_plusredditpinterestlinkedinmail

How to change Network Profile in Windows Server 2012/2016

Sometimes Windows picks up wrong profile for you network and there is no obvious (or even any?) way to change this via GUI. But you can easily do this with PowerShell (v4.0 or newer):

I guess looking at above and keeping in mind that you have get-help cmdlet changing Network Profile is no longer an issue for you.

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Internet access slowness on host after installing Windows 10 Client Hyper-V

I’ve recently switched from VMware Workstation to Windows 10 Client Hyper-V and I really pleased with capabilities I get so far. But after awhile I noticed extreme sluggishness of web browsing on my host machine which I had not linked initially with Hyper-V. Issue has not crop up immediately after I installed and started using it, but seemingly after I added Internal Virtual Switch. So I spend day and a half blaming slowness on my ISP before trying to investigate and fix the problem.

In case if you not recognize whether you have the same problem or not here is somebody’s YouTube video demonstrating it along with fix valid for Window 8/8.1 (note that adapter names may vary from case to case). Windows 10 fix can be found below.

Essentially when you create External Hyper-V switch it sorts of hijacks your physical NIC unbinds IPv4 from it and passes its IPv4 config onto External vEthernet adapter in some obscure way. But slowness crops up due to the wrong connections priority which was easy to adjust in Win 8 as described in this TechNet blog post – you just navigate to Network Connections (ncpa.cpl) > Press Alt on keyboard to access Advanced Settings as depicted below and from there just reorder your connections making sure that External vEthernet adapter is listed first.

Problem is that in Windows 10 you no longer have this GUI because as one person put it “There are no longer any components that utilize the binding order. The only known component that used the binding order was DNS ordering. By default, Windows uses the Route Metric + Interface Metric to determine which route has the highest priority by choosing the route with the lowest value.” This is explanation which I got here.

Long story short what you likely have to do to bring your browsing speed back to normal is issue Get-NetIPInterface cmdlet to get list of your interfaces along with their Index and Interface Metric values. It should return you something like this:

Get-NetIPInterface

Now you want to make sure that your vEthernet gets highest priority by issuing the following cmdlet:

If I use example with interfaces listed above it would be something like this:

This should fix your browsing speed.

Facebooktwittergoogle_plusredditpinterestlinkedinmail