How to find candidates for implicit usings in C#

Implicit using is a feature which comes with C# 10. The question is how to find candidates for implicit usings in some C# project. For this task following PowerShell snippet can be used:

Get-ChildItem *.cs -Exclude *assembly* -Recurse `
 | Get-Content `
 | Select-String using `
 | Group-Object `
 | Sort-Object -Property Count -Descending

After running this command in folder with some C# files you can discover repeating usings, for example that in unit tests are repeating using of FluentAssertions and Xunit which can be added into .csproj file as implicit usings:

<Project Sdk="Microsoft.NET.Sdk">
    <Using Include="FluentAssertions" />
    <Using Include="Xunit" />

Convert Excel to HTML using PowerShell

Conversion from Excel to HTML can be done by combination of Import-Excel from PowerShell module ImportExcel and ConvertTo-Html cmdlet. Lets use Excel file generated in previous post. Conversion is done by one-liner:

Import-Excel .\Services.xlsx | ConvertTo-Html

Output is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "">
<html xmlns="">
<title>HTML TABLE</title>
<tr><td>AMD Crash Defender Service</td><td>Running</td><td>Automatic</td></tr>
<tr><td>AMD External Events Utility</td><td>Running</td><td>Automatic</td></tr>

If we want to save HTML directly into file, Out-File cmdlet is added:

Import-Excel .\Services.xlsx | ConvertTo-Html | Out-File Services.html -Encoding utf8

Convert to Base64 encoded string using PowerShell one-liner

PowerShell doesn’t provide built-in cmdlets for conversion from string to Base64 encoded string. This task can be done by combination of .NET methods Encoding.GetBytes and Convert.ToBase64String. PowerShell one-liner is then simple:


We can even omit System namespace to simplify one-liner:


Output is Base64 encoded string:


More about using .NET in PowerShell can be found in documentation.

Deploy Windows service using Terraform

Terraform can be used for deployment of Windows service by combination of provisioner together with PowerShell cmdlets.

Udemy course: Migrate Windows service to Azure

Following Terraform code placed in file can be used to install and uninstall of Windows service:

variable "binary_path" {
  type = string
  description = "Binary path"

variable "service_name" {
  type = string
  description = "Service name"

resource "null_resource" "win_service" {
  triggers = {
    service_name = var.service_name
  provisioner "local-exec" {
    when = create
    command = "New-Service -BinaryPathName ${var.binary_path} -Name ${var.service_name} -StartupType Automatic; Start-Service -Name ${var.service_name}"
    interpreter = ["PowerShell", "-Command"]
  provisioner "local-exec" {
    when = destroy
    command = "Stop-Service -Name ${self.triggers.service_name}; (Get-WmiObject -Class Win32_Service -Filter \"Name='${self.triggers.service_name}'\").Delete()"
    interpreter = ["PowerShell", "-Command"]

Install Windows service using:

terraform apply -var 'binary_path={binary_path}' -var 'service_name={service_name}' -auto-approve

Uninstall Windows service using:

terraform destroy -var 'binary_path={binary_path}' -var 'service_name={service_name}' -auto-approve

Before running this commands replace variables {binary_path} and {service_name} with required values.

Convert CSV to Excel using PowerShell

There are many posts explaining how to convert CSV to Excel using PowerShell, but most of them requires Microsoft Office to be installed on the machine. I try to find most simple solution and it is by using of combination Import-Csv and Export-Excel from PowerShell module ImportExcel.

Sample CSV file is created by exporting top 10 services:

Get-Service | Select-Object Name,Status,StartType -First 10 | Export-Csv Services.csv -NoTypeInformation

Content of created CSV file:

"AMD External Events Utility","Running","Automatic"

Udemy course: Improve your productivity with PowerShell

Next step is to install PowerShell module ImportExcel:

Install-Module ImportExcel

After this step in everything prepared for the conversion. Conversion from CSV to Excel is very easy:

Import-Csv Services.csv | Export-Excel Services.xlsx

Converted file opened in Excel:

Converted file opened in Excel

If you are interested in PowerShell automation, take my Udemy course Improve your productivity with PowerShell.