Archivi categoria: script

How to fix 8000000A error when building VDPROJ

The Microsoft Visual Studio Setup Project is an old technology to create installer developed by Microsoft. It is out of support from nearly a decade and not present in Visual Studio anymore but when I visit customer sites I find legacy technologies and I need to deal with it on the short-term.

A couple of days ago I was working on an automated CI build on Azure DevOps and we hit an issue when trying to compile an old VDPROJ (migration to Wix in progress, btw ☺). We encountered an HRESULT 8000000A error.

Continua a leggere How to fix 8000000A error when building VDPROJ

Docker PowerShell commands and AutoHotKey

Commands

I’m doing quite a few exercies with Docker in the last fiew days. I start to notice that I need a toolkit of useful commands to cleanup all the containers or images that I move around.

I record here, for future memory, a collection of useful PowerShell script.

Bonus point: an AHK (AutoHotKey) script to be able to rapidly insert those commands with just a few chars!


# Maintenance commands or utils
docker container prune # Remove all stopped containers
docker volume prune # Remove all unused volumes
docker image prune # Remove unused images
docker system prune # All of the above, in this order: containers, volumes, images
docker ps -a -q | % { docker rm $_ } # Remove all containers
docker images -q | % { docker rmi $_ } # Remove all images
docker volume rm $(docker volume ls -f dangling=true -q) # Remove all volumes
https://gist.github.com/phenixita/6b3b65e58cf19ff38d9e4f44e6f79a54.js

How to create a self-signed certificate with PowerShell

When we develop web-application or experiment with some technologies it’s quite common to need a certificate. A certificate for real world scenarios can be expensive and it’s over-engineering for testing purposes. So with this simple PowerShell script (on Windows) we can create a self-signed certificate for development enviroments.

$cert = New-SelfSignedCertificate -DnsName mydemowebapp.net -CertStoreLocation cert:\LocalMachine\My

$pwd = ConvertTo-SecureString -String "MyPassword" -Force -AsPlainText

Export-PfxCertificate -Cert $cert -FilePath C:\temp\cert.pfx -Password $pwd

With these few line of codes we create and store a self-signed certificate in the Windows Certificate Store. With the last line (Export-PfxCertificate) we export the certificate for furher use for example to do some experiments with cloud providers.

Reference

GitHub Gist

Toolbox al cioccolato

Per rendere utilizzabile ogni PC come si deve con tutta una serie di tools che a mio avviso ritengo indispensabili, utilizzo da qualche settimana uno script PowerShell.

Si basa su Chocolatey e infatti la prima riga dello script permette di installarlo.

Richiede di essere eseguito con PowerShell come Amministratore.

Ecco la mia lista di programmi di cui non posso fare a meno, ma soprattutto, lo script:

#Uncomment the following line to install Chocolatey.
#@powershell -NoProfile -ExecutionPolicy Bypass -Command “iex ((New-Object System.Net.WebClient).DownloadString(‘https://chocolatey.org/install.ps1′))” && SET “PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin”

choco install notepadplusplus -y

choco install vlc -y

choco install 7zip -y

choco install ultrasearch -y

choco install paint.net -y

choco install vim -y

choco install google-chrome-x64 -y

choco install windirstat -y

choco install autohotkey -y

choco install sysinternals -y

choco install teamviewer -y

choco install tor-browser  -y

#Less useful

#choco install ultravnc -y

#choco install ammyy -y

#choco install gitkraken -y

#choco install DotNet35 -y

#choco install DotNet45 -y

#choco install crystalreports-for-visualstudio -y

Azure PowerShell Start Virtual Machine

This is the script I use to start virtual machines in our cloud environment. I write it down here for archive and sharing purposes.

1.png

It is based on the Azure RunAs automation account.

The only thing thing you need to do is to schedule this script daily.


<#
    .DESCRIPTION
        Turns of virtual machines only office days.

    .NOTES
        AUTHOR: Michele Ferracin
#>


# No Sunday, no Saturday.
$wd = (Get-Date).DayOfWeek

if ($wd -eq "Sunday" -or $wd -eq "Saturday") {
 exit 0;
}

$connectionName = "AzureRunAsConnection"
try
{
    # Get the connection "AzureRunAsConnection "
    $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName        

    "Logging in to Azure..."
    Add-AzureRmAccount `
        -ServicePrincipal `
        -TenantId $servicePrincipalConnection.TenantId `
        -ApplicationId $servicePrincipalConnection.ApplicationId `
        -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint 
}
catch {
    if (!$servicePrincipalConnection)
    {
        $ErrorMessage = "Connection $connectionName not found."
        throw $ErrorMessage
    } else{
        Write-Error -Message $_.Exception
        throw $_.Exception
    }
}

Start-AzureRmVM -Name "YourVM1" -ResourceGroupName "YourResourceGroup"

Start-AzureRmVM -Name "YourVM2" -ResourceGroupName "YourResourceGroup"


Aggiornare un servizio di Windows via Powershell

Avete implementato un servizio di Windows e, come è consuetudine, avete scoperto un bug e lo avete risolto.

Ora bisogna aggiornare il servizio.

Siccome il mio codice ha spesso dei bug mi è capitato di dover ripetere più volte questo processo:

  • Compila la dll con la correzione;
  • Spegni il servizio nel server;
  • Sostituisci la dll;
  • Riavvia il servizio.

All’n-esima volta mi sono stufato e ho creato uno script powershell che recita:

Set-Service -Name MadLab.Router -ComputerName 125.0.0.254 -Status Stopped

Copy-Item -Path .\MadLab.Router.Servizio\bin\Release\* -Destination \\125.0.0.254\madlab-ame\MadLab.Router\ -Exclude *config*,*vshost*, *.pdb

Set-Service -Name MadLab.Router -ComputerName 125.0.0.254 -Status Running