Wednesday, 10 May 2017

Restoring the Windows Installer

If you didn't know this already is a bad idea to delete files from the windows installer folder.
The reason for this is when applying windows updates window will often look to compare the previous version and if those files are missing the patch will fail to install.

Chances are you know this already if you are reading this.

Now the question is how can you fix it... well I'm here to tell you there is no easy way.
you will need to download all the install media and extract all the service packs and hotfixes that are missing, this is not so hard.

then you need to copy the correct one into the windows installer folder with the right name.
This is where a PowerShell script that from Ahmad Adel Gad might just save you allot of time.
https://gallery.technet.microsoft.com/scriptcenter/Restore-the-Missing-d11de3a1

This will tell you what package are missing and when pointed to the media copy it to the Windows installer folder for you with the correct names.

Monday, 8 May 2017

PowerShell From Linux to Windows and Windows to Linux

Great times are coming, Linux can now manage Windows or Windows can manage Linux.
However you look at it having a cross-platform (heterogeneous networks) scripting is always a good thing, now while PowerShell 6 is still in the alpha stage at this moment I have high hopes that it will make my life allot easier when it comes to moving between server.

With that said I'm going to do a step by step install on ubuntu 16.04 and Windows 2016.
Note at the moment ubuntu 17.04 isn't working this might change in near future.

Ubuntu
you'll first need to import the keys and then download the package.

curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list

Now up apt-get
sudo apt-get update

Install PowerShell
sudo apt-get install -y powershell

Start PowerShell
powershell

If you haven't already got ssh server running now's your chance to install it.
sudo apt install openssh-client
sudo apt install openssh-server

You have to now add some lines to the config
sudo nano /etc/ssh/sshd_config

Make sure to enable the following lines:
PasswordAuthentication yes
RSAAuthentication yes
PubkeyAuthentication yes

Add the following line to the Subsystem section:
Subsystem powershell powershell -sshs -NoLogo -NoProfile

Safe the changes and restart ssh server for changes to take effect.
sudo service sshd restart

You are now done with the Ubuntu config, moving on to the windows server.

Windows 2016 or 2012R2

First of all download both the Powershell and the Win32 or Win64 version of OpenSSH
https://github.com/PowerShell/Win32-OpenSSH/releases
https://github.com/PowerShell/PowerShell

Install the Powershell 6 by following the prompts.
For the open-ssh extract to C:\Program Files\OpenSSH or another directory remember the location as you'll need this later.

Inside the extracted Open-ssh folder will be an install-sshd.ps1 script, run it by using the following PowerShell command from the same directory.
powershell -executionpolicy bypass -file install-sshd.ps1

Next while still in the Open-SSH folder create a key.
.\ssh-keygen.exe -A

Now you will need to allow SSH connection into your server.
New-NetFirewallRule -Protocol TCP -LocalPort 22 -Direction Inbound -Action Allow -DisplayName SSH

Next we are setting the Open-SSH to start automatically
Set-Service sshd -StartupType Automatic
Set-Service ssh-agent -StartupType Automatic

Finally, we add some lines to the sshd_config file, open it in notepad and make sure the three following lines are unhashed.
PasswordAuthentication yes
RSAAuthentication yes
PubkeyAuthentication yes

You will also need to add a line under the subsystem next to sftp, now please keep in mind that your powershell 6 path might change if the release is earlier or later than the one I was using so adapt it as needed.
Subsystem powershell C:/Program Files/PowerShell/6.0.0-alpha.18/powershell.exe -sshs -NoLogo -NoProfile

Safe the change and now set a user or system environment variable for Open-SSH
setx PATH "C:\Program Files\OpenSSH" /M

Restart the Open-SSH for changes you've make to take affect
Stop-Service sshd
Start-Service sshd

Now open open Powershell 6 and final step set the remoting by running script
.\Install-PowerShellRemoting.ps1

You can now PowerShell between Linux and windows server without a problem,

Enjoy...