C# – SecurityException when writing to the Windows Event Log

Problem When your application tries to write to the Windows Event Log, you get the following exception: System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. To create the source, you need permission to read all event logs to make sure that the new source name is unique. … Read more

PowerShell – How to use Select-String to search files for a pattern

In this article, I’ll show how to use the Select-String PowerShell command to search files in a directory for a regex pattern. I’ll first explain the basic syntax, and then I’ll show a few common search scenarios. Pattern, path, and alias Select-String has two main parameters: pattern and path. The pattern is what you want … Read more

PowerShell – Get a file’s MD5 checksum

To get a file’s MD5 checksum, you can use Get-FileHash. This has been available since PowerShell v4. Use it like this: This file’s MD5 checksum is AE34D271ACC9C242BC9EED2E0EA72093. If Get-FileHash isn’t available Get-FileHash was put in PowerShell v4. If you’re on an earlier version, you’ll get following error when you try to use this: Get-FileHash is … Read more

PowerShell – Saving SQL query results to a CSV file

Here’s how to execute a SQL query and export the results to a CSV file: If Invoke-SqlCmd is missing, install the SqlServer module If it’s complaining about not having Invoke-SqlCmd available, you will need to install the SQL Server PowerShell module. 1 – Run PowerShell as administrator 2 – Add Microsoft’s PSGallery as a trusted … Read more

.NET – How to sign your code with a code signing certificate

You’re given .PFX code signing certificate and told to sign your code. What does this mean, and how do you do it? What is code signing? Signing code means creating a digital signature on an executable file by using a code signing certificate. When your code is executed, your organization’s security software will check that … Read more