Thursday, May 17, 2018

Digging through a lot of files

I have a scenario where I need to scan a lot of xmlfiles from elmah-logs in the size of 300 000 files.

Powershell was a fun project for this but couldn't really do the job due to performance issues.
When reading 300 000 files using powershell like example below, the script ran for 368 minutes.


I tried running parallell jobs and using dotnet to read files instead but nothing could complete with using MS Logparser.
So enter Log Parser Studio.
This neat tool managed to comb through 300 000 files in 47 minutes instead!
It is a bit tricky to formulate the queries however. Heres an example of getting elmah logs where a variable named HTTP_REFERER contains a key value

select * FROM '[LOGFILEPATH]' where  string like '%http://www.mycompany.com/subsite%' and name like 'HTTP_REFERER'

So in conclusion for same set of 300 000 files
Powershell took 368 minutes
Log Parser Studio took 47 minutes

References:

Thursday, May 03, 2018

Using hashtables to combine values

For a job I needed a good way of combining a primary value with optional subvalues in a xml-file.
Below is an example of how to extract attributes from a xmlelement into a hashtable and then join two hashtables into one. I couldn't find a method for extracting elements on the web, folks usually goes with subnodes instead of attributes. I'm partial to attributes and had to get creative, but the solution was quite simple. The Attributes from the element only show the actual elements from the xmlfile. Its not obvious when browsing the object that -name property can be lifted, but here it's used for creating a new hashtable-row



Samplescript for proof of concept


This eventually led to createwebsFromStructure.ps1 that uses powershell splatting to build commands with the resulting hashtable.



References:
https://powershell.org/2013/01/23/join-powershell-hash-tables/ - source for join-hashtable function
https://technet.microsoft.com/en-us/library/gg675931.aspx - source for details on splatting

Friday, January 12, 2018

Powershell and jobs

Powershell jobs are a bit of blunt instrument.

Here's two options for sending inputs for them
Scenario 1: Sending a string with all of our values and splitting them to an array when inside the scriptblock.


Scenario2: Sending an object as input. Handy for configs and saves the need to define variablenames.

powershell assisting with mails

ExtractAttachedMails.ps1 is used for extracted alla attached mails in a outlook .msg-file to specified folder.
CatalogueMails.ps1 is used for indexing the mails to more easily filter on timestamps and senders.

This came in handy when a happy user sent me 45 attached mails with the same subjectline so the extractionprocess also throws in an indexnumber to avoid namingconflicts.

Wednesday, December 20, 2017

Remove iislogs

Built a nice script to remove older files from IISLogs.
It has two retentionmodes. Either clear based on number of last changed files or for specific days.

Thursday, November 23, 2017

Installing workflow manager on sharepoint 2016

Scenario:
Sharepoint 2016 needs workflow supports since 2010 workflows now seems dead.
This needs to be done offline

Overview of steps

  1. Download all programs from internet-enabled client with getOfflinePackages
  2. Install packages on server in correct order
  3.  Configure workflow manager
  4.  Register workflow service in sharepoint

Step 1 - Download necessary files for offlineinstallationen

On client with webaccess
  1. Install WebPlattformInstaller
  2. Download packages with getOfflinePackages.ps1

Step 2 - Install packages on server in correct order

  1. Install packages with InstallWFM.ps1 to get correct order

Step 3 - Configure Workflow Manager

  1. Update wfmconfig.xml with credentials and databasename
  2. Configure with configureWFM.ps1
  3. Update siteaddress and run registerWFOnsite
References:
https://www.helloitsliam.com/2014/11/06/sharepoint-2013-workflow-manager-woes/ - source for the order of installation
http://blog.robgarrett.com/2014/05/12/install-workflow-manager-with-powershell/ - original script for configuring workflow manager
https://blogs.msdn.microsoft.com/laleh/2014/09/03/sharepoint-2013-workflow-troublehsooting/ - troubleshooting workflow manager
https://social.technet.microsoft.com/wiki/contents/articles/34407.sharepoint-2016-step-by-step-installation-of-workflow-manager.aspx - another installationguide
https://knowledge.zomers.eu/SharePoint/Pages/How-to-install-and-configure-Workflow-Manager-on-Windows-2012-R2.aspx - more updated information on how to configure worklow manager
https://docs.microsoft.com/en-us/iis/install/web-platform-installer/web-platform-installer-direct-downloads - webplattforminstaller

Monday, November 20, 2017

Sharepoint and alternate languages

So what happens when a column is created and then changed.
And then, possible, changed again in an alternate language?

First created, staticName is set and the cultured name
image
When names is changed, only the culturename is changed
clip_image001
When and alternate language is added, and copy of the culturename appears.
image
When name is changed again to doktor2, only the current language version is changed. Swedish 1053.
clip_image001[6]
Now we have 3 version to manage.
When we choose overwrite language specific version the values dont change.
clip_image002
When we now change the column to Doktor3, only the 1053 version change when we’re using the alternate languagebrowser.
clip_image003
But if we change using the default language (1033) to doktor4, all local variants are overwritten
clip_image004
But then a local editor is at it again, setting doktor5 in swedish and the values are off.
clip_image005
But what happens if we now remove local variants? Then we're down to only the default columns
clip_image006
Changing from swedish gui to doktor6 and the english 1033 is changed.
clip_image007
But what happens if language is enabled again? Well, the old value is still there…
clip_image008
The lesson here?
Stay away from alternate languages!
And also a fun script for checking all the versions of a fields on a list.