Archivi tag: script

How to fix Windows 10 Broken Search Bar

If your Windows 10 Search Bar is broken you’re encountering an issue that is spreading to many Windows 10 users at the time of this writing.

This is NOT an official statement (I’m not responsible for any side effects caused by this) about how to fix but running this script inside a PowerShell session with administrator privileges and restarting the machine can solve your issue (it worked on my machine).

Get-AppXPackage -Name Microsoft.Windows.Cortana | Foreach {Add-AppxPackage -DisableDevelopmentMode -Register "$($_.InstallLocation)\AppXManifest.xml"}   

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 -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.


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(‘′))” && SET “PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin”

choco install notepadplusplus -y

choco install vlc -y

choco install 7zip -y

choco install ultrasearch -y

choco install -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.


It is based on the Azure RunAs automation account.

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

        Turns of virtual machines only office days.

        AUTHOR: Michele Ferracin

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

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

$connectionName = "AzureRunAsConnection"
    # 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 -Status Stopped

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

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