Wednesday, 13 June 2018

Forcing Synchronization of Display Name and Email from Active Directory without User Profile Synchronization - PowerShell Script

Just made this script to Synchronize Display Name and Email for all users in a root web if they have been updated in AD and aren't flowing through to your display name in SharePoint. This may be required if the user profile service is not set up or is failing. This problem is discussed in more detail at https://gallery.technet.microsoft.com/office/User-Information-List-in-8b420e8c

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
#As discussed in https://gallery.technet.microsoft.com/office/User-Information-List-in-8b420e8c 

Write-Host  -ForegroundColor Yellow "-------------------Process Start---------------------------------------------------------------"
Write-Host  -ForegroundColor Yellow "This script will sync the AD display name and email from AD without running a user profile sync"
Write-Host  -ForegroundColor Yellow "As discussed in https://gallery.technet.microsoft.com/office/User-Information-List-in-8b420e8c" 
Write-Host  -ForegroundColor Yellow "-------------------Process Start---------------------------------------------------------------"

$stopWatch = [Diagnostics.Stopwatch]::StartNew()

$rootWeb = Get-SPWeb "https://demo01.berkeleyit.com/"
ForEach ($user in $rootWeb.AllUsers)
{
    Write-Host  -ForegroundColor Green "Syncing Email and DisplayName with Active Directory... for $user" 
    Set-SPUser -Web $rootWeb -identity $user.UserLogin -SyncFromAD
}

$stopWatch.Stop()

$timeTaken = $stopWatch.Elapsed

Write-Host  -ForegroundColor Yellow "-------------------Process Completed in $timeTaken second(s)------------------"

Wednesday, 28 March 2018

TypeScript - Importing jQuery TypeScript Definitions (d.ts) for Visual Studio 2017

TypeScript is building in popularity and JQuery is remains one of the most popular JavaScript frameworks. Consequently you will typically want to use them together in the same project at one stage or another.
If you do want to use JQuery within your TypeScript files in Visual Studio 2017, you need a "DefinitelyTyped" definition specifically for jQuery. This will allow Visual Studio to correctly recognise jQuery objects when validating and compiling (or transpiling based on your preferred terminology).


To do this, just download the TypeScript definitions (d.ts) for jQuery through the Nuget Package Manager (npm) UI or with the Nuget package manager console, use the following command:

Install-Package jquery.TypeScript.DefinitelyTyped

Now the typescript compiler will recognise your jQuery calls:


DDK

Friday, 1 September 2017

BOSE QuietComfort 35 - How to Tell You Have a Fake set of BOSE Headphones

I've had fake MicroSD cards sent to me previously when bought online - but the attention to detail in the fake BOSE QC35 headphones I recently received was amazing.

After ordering my Bose QuietComfort 35 noise-cancelling headphones off Ebay, I was surprised how slick they looked - but the positive impression did not last. Once I plugged them in and charged them up it became painfully apparent that the electronics inside them were not up to scratch:

1) They would cut out intermittently from the Bluetooth connection.
2) The noise cancellation was ineffective. I've used the QC25 headphones before and it is clear when the noise cancellation is turned on and off (thinking night and day). When noise cancellation is on, it reminds me of when people go deaf (in movies like "Saving Private Ryan" or "Dunkirk") from the concussive effects of a grenade or bomb (yes they're that good!).

I contacted Bose (Report_Counterfeits@bose.com) and they confirmed that they were in fact very well done fakes and they didn't exhibit most of the superficial faults that most fakes have. In particular, the "BOSE" writing on the headphones was embossed perfectly and there was no clear marks where the ear cups had been glued together. All the serial numbers on the headphones and on the box also matched. The box, plastic and packaging was also hard to fault.

The only issue was that the serial number was invalid - the number after the Z is meant to be a date.

S/N:072536Z08231568AE

So it seems that the most important (and most expensive components) - the internal chips and electronics - are the part you are probably paying for and the part that is hardest to reproduce accurately by the guys making the yum-cha/knock-off copies.

So the simplest way to check for a fake is to attempt to register you headphones online at:
https://www.bose.com.au/en_au/support/product_registration.html


The guy I was dealing with on Ebay even tried to negotiate the refund to 30% of the original price before I told him how it is meant to work. Make sure you demand a 100% refund including the return postage cost on a fake substandard item like this. The guys at BOSE will also help you to get a refund if needs be.

Hope this helps!
DDK

Monday, 13 March 2017

Fix - Error in lc.exe when Compiling Solution upgraded to Visual Studio 2017 RTM from Visual Studio 2015

Upgraded our product solution today to the latest Visual Studio 2017 RTM and everything seemed to work fine - until I started getting the following error in the build:

"The specified task executable "lc.exe" could not be run. The filename or extension is too long"

What is this lc.exe command and why is it running? It is used by the standard .NET licensing mechanism and is maintained by Visual Studio for information about all licensed components.

In my case, the error was occurring in "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets" Line 2975 according to my error log.

Clearly this problem was related to the fact we are using Telerik Controls which require a licx file to compile (or so I thought).

I turned on full diagnostics in Visual Studio 2017 to help get to the bottom of the issue:




This showed the full path that was being passed to lc.exe is over 42000 characters long (!):
1> C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\lc.exe /target:ESSP.ApplicationPages.dll /complist:Properties\licenses.licx /outdir:obj\Debug_SP2013\ ....[SNIP]
 


Several places such as on Microsoft Connect - suggested that the "solution" (pardon the pun) is just to delete the licx file (also as per http://docs.telerik.com/devtools/aspnet-ajax/licensing/license-file) I could then recompile without any build exceptions.

This issue comes about because the lc.exe executable can only handle a parameter length of 32000 characters or less - and the full path is used for all references. Needless to say this is a restrictive limitation in the licensing mechanism!

So the possible alternatives to fix this issue:
1) Remove the licx file if possible when you don't need the full licensed functionality (in my case this was fine - as we don't need design mode for the Telerik controls).
2) Reduce the length of your references by adding a shared drive or logical redirect to a shorter path e.g. c:\references instead of c:\src\DDK\product name\releases\ etc)
3) Reduce the number of references that you have in the project that has issues with lc.exe

DDK

Wednesday, 23 March 2016

How to identify the application pool for a worker process (Windows Server 2012 and 2012 R2 using IIS 8)

Use the following command to determine which application pool maps to your w3wp.exe worker instance. This is particularly handy with SharePoint as it has 3 w3wp.exe processes running at any one time by default.
cd %windir%\system32\inetsrv
appcmd list wp

This will give you an output similar to the following:

C:\Windows\System32\inetsrv>appcmd list wp
WP "21192"  (applicationPool:SharePoint - 80)
WP "12256" (applicationPool:SecurityTokenServiceApplicationPool)
WP "19972" (applicationPool:5f2e9be121504641ae144bcae3b8cf6e)
DDK

Tuesday, 22 September 2015

Impersonation of Web Users in ASP.NET/SharePoint 2013 without a password

There seemed to be a lack of samples available to demonstrate how Windows impersonation can be done within the context of a web application (such as SharePoint 2013 or ASP.NET). Most of the examples use the "LogonUser" Windows API call to get a user token. e.g. https://msdn.microsoft.com/en-us/library/chf6fbt4.aspx. However - that call requires a password to work. You don't really want all your user passwords to have to sit in a secure store to enable impersonation!

In my scenario, I had to write to a file through an existing COM Component via a .NET COM Interop library. It depended on the write operation being done from the context of a valid user - otherwise the file wouldn't be stamped correctly with author metadata.

To do this, I had to use an overload of the WindowsIdentity constructor which accepts a UPN (User Principal Name). From there, you can impersonate users within your code at will.

NOTE: the account that is doing the impersonation (e.g. svcSP) will need to have the "Act as Part of the Operating System" right as defined in your Local User Policy for this to work.

Code Sample:


void Main()
{
 var userName = "LOCALDEV\\david.klein";
 PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

 var user = UserPrincipal.FindByIdentity(ctx, userName);

 if (user != null)
 {
 var upn = user.UserPrincipalName;
 Debug.Print(upn); 
 WindowsIdentity id = new WindowsIdentity(upn);
 WindowsImpersonationContext wic = id.Impersonate();    
 try
  {
   // Do what you need here under the impersonation context.
   var currentId = WindowsIdentity.GetCurrent().Name; 
   Debug.Print(currentId);
  }
  finally
  {
   wic.Undo();
  }
 }
}

Monday, 20 April 2015

Microsoft Team Foundation Server 2013 Update - Error When Installing - "SQL Server Reporting Services is configured to require a secure connection."

You may get the following exception when upgrading to Team Foundation Server 2013 (TFS 2013) or update packages - when you are using self-signed certificates or your SQL Report server runs unsecured (not using SSL):

TF255455: SQL Server Reporting Services is configured to require a secure connection. However, no HTTPS URL is configured with a valid certificate. Use the Reporting Services Configuration Manager to configure or remove HTTPS support. For more information see http://go.microsoft.com/fwlink/?LinkId=179982


To resolve this issue (without getting valid certificates or securing your site), you can go to your Microsoft SQL Server Reporting Services (SSRS) folder and find the rsreportserver.config  file. This is typically in:

C:\Program Files\Microsoft SQL Server\MSRSXX.<ServerInstance>\Reporting Services\ReportServer\rsreportserver.config             

Update the "SecureConnectionLevel" from 2 to 0 - and you will be able to run the update. Change it back after the update has completed.



DDK

Friday, 23 January 2015

How can I easily have different app.config files for different build configurations in MSBUILD?

There are a few different proposed solutions I have seen suggested, some including recommendations involving 3rd party tools and Visual Studio Transformation Extensions. The following is the simplest method I have found. It involves a violation of the DRY principle (Don't Repeat Yourself) as the app.config files are duplicated (due to the lack of transforms) - but I considered this to be a small sacrifice based on the simplicity of the solution.

Steps:
1) Unload your Project file (csproj) file in Visual Studio and Right click and select "Edit {My Project Name}.csproj" on that same file to edit it.
2) Add a folder for each MSBUILD configuration that you want and put your different App.Config files in those subfolders e.g. \Release\App.config and \Debug\App.Config
2) Find the section in your csproj project file <None Include="App.config" /> and replace it with the following conditional Include statements for each of your MSBUILD configurations:
<None Condition=" '$(Configuration)' == 'Debug' " Include="Debug\App.config" />
<None Condition=" '$(Configuration)' == 'Release' " Include="Release\App.config" />

When you build, it will use either of the application configuration files that you have created and put them in the relevant build configuration output directory.

DDK