U2U Blog

for developers and other creative minds

Creating A Self-Signed Code Signing Certificate from PowerShell

In PowerShell, being able to execute scripts depends on the execution policy of your machine. You might be able to change the execution policy yourself and set it to Unrestricted, meaning you can execute scripts without signing them. If you are not an administrator, or your group policy defines the execution policy, you will need to sign your script. To see your current execution policy, execute the following command:

Get-ExecutionPolicy -List

To create a self-signed code signing certificate for PowerShell, makecert used to be the best solution. In PowerShell we have a cmdlet called New-SelfSignedCertificate which we can also use for this purpose. Since V5 this cmdlet has been updated to make it easier to do so. To create a Code Signing certificate execute the following command:

$cert = New-SelfSignedCertificate -CertStoreLocation 
Cert:\CurrentUser\My -Type CodeSigningCert -Subject "U2U Code Signing"

To verify that the certificate has been generated, run this command:

Get-ChildItem -Path Cert:\CurrentUser\My | ? Subject -EQ "CN=U2U Code Signing"

The result should look like this.

Great! Now use the certificate to sign your script:

Set-AuthenticodeSignature -FilePath .\signedscript.ps1 -Certificate $cert

Oops! That didn't work!

Our certificate is not trusted as it is in the personal store. Let's move it to a better location:

Move-Item -Path $cert.PSPath -Destination "Cert:\CurrentUser\Root"

Make sure you confirm the installation of the certificate.

Now try again!

Set-AuthenticodeSignature -FilePath .\signedscript.ps1 -Certificate $cert

Better! You should now be able to execute the signed script!

The full script looks like this:

$cert = New-SelfSignedCertificate -CertStoreLocation Cert:\CurrentUser\My -Type CodeSigningCert -Subject "U2U Code Signing"
Move-Item -Path $cert.PSPath -Destination "Cert:\CurrentUser\Root"
Set-AuthenticodeSignature -FilePath .\signedscript.ps1 -Certificate $cert

Deciding when to do a differential backup

SQL Server allows for differential backups, which only backups extends modified since the last full backup. The advantage of these differential backups is that if only a small portion of your data has changed since the last full backup, you need less time and storage for your backups! The disadvantage however is that the time needed for a restore increases: We must first restore the full backup, then restore the last differential backup.
So when few extends have changed since the last full backup, the gain on the backup is huge, and the pain when restoring is limited. But as more and more extends are being modified, the pain grows and the gain shrinks. So to decide whether we go for a full or differential backup we need to know the number of extends modified since the last full backup. But on SQL Server 2016 and earlier the only easy way to figure out was… by taking a differential backup.

SQL Server 2017 offers a nice improvement on this. In the sys.dm_db_file_space_usage dynamic management view an extra column modified_extent_page_count has been added which provides this information. So if you’re willing to stick to differential backups till they are 70% of the size of your full database, you could use this script to get the backup advice:

SELECT total_page_count, allocated_extent_page_count, modified_extent_page_count
, modified_extent_page_count * 100 / allocated_extent_page_count AS [% changed]
, CASE WHEN modified_extent_page_count * 100 / allocated_extent_page_count > 70
    END AS Advice
FROM sys.dm_db_file_space_usage

An example:


So with this we can improve our maintenance plan. Next step: convince Ola to include this in his maintenance script Smile

Angular Language Service

One of the best extensions you can find for your Angular programming needs is called the "Angular Language Service", especially if you're using VS Code.

What is the Angular Language Service?

The Angular Language Service is a plugin built for the TypeScript [TS] language. It allows to evaluate the templates (inline and html files) at development time, from your IDE. In other words you will get "true" autocompletion when trying to use properties from an interpolation directive or red squiggly lines if you made a mistake in your template.

How does it work (without going into too much detail)?

On 27 April 2017, the TS team made an announcement for version 2.3 of the language. The team states that together with the Angular team they were able to create a public Language Server Plugin API. This allows people to augment their editing experience by creating plugins that make use of the Language Server.

The internal name for the Language Server is called "tsserver" which stands for "TypeScript standalone server". It is a node executable that includes the TypeScript compiler and language services. "tsserver" exposes an API through a JSON protocol.

In other words, the Angular Language Service will talk to this tsserver executable in JSON to get tsserver to compile and evaluate the templates so that we can make use of TypeScript in those same templates! Which is a great step forward for us as an Angular Developer - or teacher!

How do I make use of it in VS Code?

Open your extensions menu and look for "Angular Language Service". The author is Angular, it is pretty hard to miss ;-).

What about other editors?

Some editors don't make use of the tsserver when evaluating TS code, so it might be that your editor already supports template evaluation! I've found a blog post from Brian Love explaining how to install it for WebStorm and Sublime right here

Enjoy coding!

PS: This is a full copy of my blog post at: https://diedrikdm.github.io/2017/05/01/angular-language-service.html