Category Archives: PowerShell

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

How to: Add new DC to existing domain with PowerShell

First of all you have to install AD DS role binaries on sever using either Server Manager GUI or PowerShell:

Note that if you are executing above command on real server Core installation you may get errors when using -IncludeManagementTools parameter as some of management tools can’t be installed on Core installation.

Once role is installed you may use script similar to this one to add DC to existing domain:

This script was tested with Windows Server 2012 R2.

Also script above is a great example of using tick (“`”) symbol which greatly improves readability of your PS scripts saved into a file. Just to highlight the difference most of this script supposed to be one line (starting from “Install-ADDSDomainController” cmdlet). Here is this line:

It is very easy to see how inconvenient it is to read/scroll through this line. Using tick symbol you can make your script far more readable.

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Using PowerShell to manage network settings

Just a quick and short post on essential PowerShell cmdlets which you may use to manage network settings. The slide below taken from “Configuring and Managing Windows 8.1” module of “Preparing for Windows 8.1 MCSA” MVA course.

PoSh_Netwrork_Mgmt

To be honest I didn’t know some of cmdlets listed and those may be useful not only for MCSA exam. What especially good about the slide above it is that it match PS cmdlets with CLI commands equivalents.

Also you may look through all available commands in PS by using get-command cmdlet (do remember to pipe output into more to see less 🙂 ):

\n\n\n[code language=”powershell” light=”true”]\nget-command | more\n[/code]\n\n

And also you may use wildcard search with get-command:

\n\n\n[code language=”powershell” light=”true”]\nget-command *network*\n[/code]\n\n

Despite PS is powerful and cool way to manage things I recently tried to configure IP and other adapter settings on Server 2012 R2 core and was not very pleased with the way this can be performed with PS. GUI gives you one network adapter object to access and manage IP, DNS and all the other settings so that despite settings split in different section you have this “single point of entry” – your network adapter object. Unfortunately PS does not give us such single cmdlet which can set and change all adapter related settings – it’s all somehow dispersed/supposed to be done with different cmdlets – not very convenient 🙁

Facebooktwittergoogle_plusredditpinterestlinkedinmail