Gorgo.Live.ToString()

Mariusz, Gorzoch tech Blog

Archive for July 2013

“Site Web Analytics reports” freeze on use

leave a comment »

Recently I discovered strange problem in our SharePoint 2013 environment, that is : if you go to “Site settings” and you will try to use “Site Web Analytics reports” then your browser will freeze and you can notice increase load on SharePoint server caused be IIS process. On the end this load will stay on the server till you restart iis. I dig around and found that I’ve also have problem with using “View health reports” on central administration. On the end both of those problems were connected with that http://www.jrjlee.com/2012/11/problems-viewing-health-reports-in.html . As soon you apply that fix on database (yes, yes = I know you shoudn’t touch SharePoint db) then both of those problems will by fix.

#Microsoft, please supply offical fix for that.

 

Written by Mariusz Gorzoch

22 July 2013 at 20:43

Posted in Bez kategorii

How to enumerate all members from all groups in TFS project collection

leave a comment »

Even if above sound difficult then in reality this is quite simple. First what we need to do is to add references to:

  • Microsoft.TeamFundation
  • Microsoft.TeamFundation.Client
  • Microsoft.TeamFundation.Common

and next, use below peace of code :

TfsTeamProjectCollection teamProjectCollection =
TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(“http://TFS:8080/tfs/ProjectCollection”));

var sec = teamProjectCollection.GetService<IGroupSecurityService>();

var vcs = teamProjectCollection.GetService<VersionControlServer>();

var teamProjects = vcs.GetAllTeamProjects(false);
foreach (var teamProject in teamProjects)
{

Console.WriteLine(“***{0}”,teamProject.Name);

Identity[] appGroups = sec.ListApplicationGroups(teamProject.ArtifactUri.AbsoluteUri);

foreach (Identity appGroup in appGroups)
{
if (appGroup.DisplayName != “Project Administrators”) continue;

Identity[] groupMembers = sec.ReadIdentities(SearchFactor.Sid, new string[] { appGroup.Sid }, QueryMembership.Expanded);

Console.WriteLine(“+{0} ({1} members)”, appGroup.DisplayName, groupMembers.Count());

string members = string.Empty;
foreach (Identity member in groupMembers)
{
foreach (var memberSid in member.Members)
{
Identity memberInfo = sec.ReadIdentity(SearchFactor.Sid, memberSid, QueryMembership.Expanded);
Console.WriteLine(“-{0}”, memberInfo.DisplayName);
}
}
Console.WriteLine(“{0};{1}”, teamProject.Name, members);
}

}

Enjoy!

Written by Mariusz Gorzoch

19 July 2013 at 10:05

Posted in Bez kategorii

How to enumerate all active builds in TFS 2012

leave a comment »

During migration of TFS 2012 we found that we have couple of inactive build controllers with we can not delete because there are pending builds on theirs queues. Unfortunately the problem was that you can not just simply use some magic option in build menu to find out what are those builds. In order to get that information you need to go project by project and see what builds are pending.  Lucky there is easier way with a little bit of code :). Before you start you need to install “Visual Studio 2012 SDK” (http://visualstudiogallery.msdn.microsoft.com/b2fa5b3b-25eb-4a2f-80fd-59224778ea98?SRC=VSIDE) with you can find thru Visual Studio extension manager.

Once you do above then create new console project and add references to

  • Microsoft.TeamFundation.Client
  • Microsoft.TeamFundation.Common
  • Microsoft.TeamFundation.Build.Client
  • Microsoft.TeamFundation.Build.Common

and past into your main function below code:

            TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://{tfsServer}:8080/tfs/{ProjectCollection}"));
            var buildServer = teamProjectCollection.GetService<IBuildServer>();

            foreach (IBuildController controller in buildServer.QueryBuildControllers(true))
            {
                Console.WriteLine("{0}:{1}",controller.Name, controller.QueueCount);
                var qspec = buildServer.CreateBuildQueueSpec("*", "*");
                var res = buildServer.QueryQueuedBuilds(qspec);

                foreach (var qb in res.QueuedBuilds)
                {
                    Console.WriteLine(qb.TeamProject);
                }
            }

            Console.WriteLine("Done!");
            Console.ReadLine();

Now just replace :

  • {tfsServer} with your tfs server name
  • {projectCollection} with you project collection

and you are done. Once you run above then you should get list of all active builds

Written by Mariusz Gorzoch

17 July 2013 at 09:04

Posted in Bez kategorii

Doing backup of entire SQL at once

leave a comment »

So, I’m working on migration of our intranet based on WSS 3.0 to the latest SharePoint 2013. As part of that process you need to make backup of all databases and move them to new server. Sure, you can do that one by one, but wouldn’t be easier to just do it at once. Here is a script you can use for it :

declare @name varchar(1000)
declare @sql varchar(8000)

declare kur SCROLL cursor for
SELECT name FROM master..sysdatabases
OPEN kur;
FETCH NEXT FROM kur INTO @name;
WHILE @@FETCH_STATUS=0
BEGIN

if (@name<>’tempdb’)
begin
PRINT ‘*** ‘ + @name;
set @sql=’backup database [‘+@name+’]
to disk = ”z:\’+@name+’_20130712_1000.bak”
with copy_only’
exec(@sql)
end

FETCH NEXT FROM kur INTO @name;
END
CLOSE kur
DEALLOCATE kur

If you combine above script with my previous post around mapping network path in SQL session then you can move those backup straight to remote server without storing them locally.

hope that this make you day easier

Written by Mariusz Gorzoch

12 July 2013 at 10:06

Posted in Bez kategorii

How to backup SQL Server database to remote machine

leave a comment »

Ok, so here is scenario : you need to backup quite big database but there is no enough space on your server. Moreover your sql server is configured to run on “Local system” (no access to network drives) account and as this is production installation you can not just simply switch that to some other account and restart machine. How to solve that ? Here is a way = you need to map network drive in SQL session and use the account who have access to destination network location.

1. Map network drive in SQL user account session

Open “SQL managment studio” and use “exec xp_cmdshell ‘net use z: \\{YourRemoteServer}\{SomePath}\{SomePath} {Password} /user:{Domain\userName}” and hit F5

This should map network path under “Z:” drive in SQL session. Please notice that if you get message “” then you need to enable “xp_cmdshell” command. This can be done easily with below script:

exec sp_configure ‘show advanced options’,1
go
reconfigure
go
exec sp_configure ‘xp_cmdshell’,1
go
reconfigure
go

Once operation of mapping drive complete with success then you will get:

2013-07-10 11-15-36

2. Do backup to mapped drive

Now you just need to use mapped drive:

backup database {YourDataBaseName}
to disk = ‘z:\{database_backupname.bak’
with copy_only

3. Unmap network drive

For the sake of pace on the end unmap the drive you mapped in point 1. In order to do it you need to run command

“exec xp_cmdshell ‘net use z: /delete”

 

Written by Mariusz Gorzoch

10 July 2013 at 11:19

Posted in Bez kategorii

How to release RDP session on remote machine from Win8 command line

leave a comment »

Hi

Today I found a need to first find out who is log on remote machine and then kill it so I can access that machine. To my surprise “Terminal services manager” is not installed anymore on Win8 box, so I had to find some other option. Lucky thanks to that blog :

http://anandthearchitect.wordpress.com/2008/08/01/how-to-logoff-remote-desktop-sessions-via-command-line-tools/

I found that this can be easily done with help of two command line calls :

1. Get list of currently logged users : QUser /Server:{Your server name or IP}

2013-07-10 09-56-10

 

2. Logoff user based on session ID : logoff {Session name or ID} /Server:{Your server name or IP}

In case of that one you need to wait an minute till you get response as the call goes to the server and remote machine show log off popup to the user where he have few seconds to respond and cancer your request.

Done.

 

Written by Mariusz Gorzoch

10 July 2013 at 10:00

Posted in Bez kategorii