Tag: powershell

Replace registry keys

I was recently tasked with migrating a software which had all of it’s configuration stored in the registry. The only way to update it “officially” was by uninstalling and reinstalling the whole suite, since this would take too long for 30 machines, I decided to script it to quicken things up.

The way this works is by using the PowerShell functionality to search the registry –

foreach ($a in Get-ChildItem -Path ‘HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer’ -Recurse) {
  $a.Property | Where-Object {
    $a.GetValue($_) -Like “*value123*”
  } | ForEach-Object {
    $CurrentValue = $a.GetValue($_)
    $ReplacedValue = $CurrentValue.Replace(“value123", “value1234”)
    Write-Output “Changing value of $a\$_ from ‘$CurrentValue’ to ‘$ReplacedValue’”
    Set-ItemProperty -Path Registry::$a -Name $_ -Value $ReplacedValue
  }
}

The script explained –

i) It is searching in the Installer path with -Recurse, this means all the folder underneath it also.

ii) GetValue – This is going to first build the search index with any registry key containing value123. It will find values such as https://value123.domain.com or just value123 alone.

iii) ReplacedValue – We are giving it the value123 to identify and then replace it with value1234. It will not replace the whole string https://value123.domain.com, it will just replace it to https://value1234.domain.com

I hope this comes in handy for anyone searching to do something similar!

Powershell to Exchange Cloud (O365)

Connecting to Exchange on Office 365. There are two methods, one from the Azure portal and one from your local PC.

Azure method –

Log into portal.azure.com and use your administrator account. Fire up the cloud powershell and execute the below command –

 Connect-EXOPSSession 

This will authenticate you to Exchange services without needing to input any further credentials or options. You will have full access to all the commands related to exchange online services.

Local PC method –

Download and install the “Microsoft Online Services Sign-In Assistant
Edit the below registry key on your PC to allow basic authentication.

HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WinRM\Client
Allow basic - decimal 1

Once that has been done, run the below commands after each other. You will be prompted to enter your administrator credentials in the second command which will store them temporarily in a variable.

Set-ExecutionPolicy RemoteSigned

$UserCredential = Get-Credential

 $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

 Import-PSSession $Session

Note the 3rd command should be in a single entry.

Re-install Windows 10 Store

We recently switched domains to have a central domain name instead of a location dependent setup. Whilst using a user profile migration tool, we came across a bug where the Windows Store would either disappear or just be unusable. This means that several useful applications for the end-users would stop working, for example : Sticky Notes, Calculator and even Microsoft Photos.

The solution was to download all the packages again and reset the store.

Run the below from powershell (run as admin) to download/install all packages

Get-AppxPackage -AllUsers| Foreach {Add-AppxPackage -DisableDevelopmentMode -Register “$($_.InstallLocation)\AppXManifest.xml”} 

The above command might throw a few errors, but will still complete. Once done, run the below from a command prompt ( run as admin )

wsreset

Once you have run the wsreset, you should either see the Store open up automatically or you’ll be able to find it to install all the applications required again.