Script to enable systemd support on current Ubuntu WSL2 images from the Windows store. Tested on 18.04 and the versionless (current) version of Ubuntu from the Windows Store. I am not responsible for broken installations, fights with your roommates and police ringing your door ;-).
Instructions from the snapcraft forum turned into a script. Thanks to Daniel on the Snapcraft forum!
git clone https://github.com/DamionGans/ubuntu-wsl2-systemd-script.git
cd ubuntu-wsl2-systemd-script/
sudo bash ubuntu-wsl2-systemd-script.sh
# Enter your password and wait until the script has finished
cmd.exe /C setx WSLENV BASH_ENV/u
cmd.exe /C setx BASH_ENV /etc/bash.bashrc
systemctl
If you don't get an error and see a list of units, the script worked.
Have fun using systemd on your Ubuntu WSL2 image. You may use and change and distribute this script in whatever way you'd like.