First, let's connect to your Raspberry Pi 2 with a Power Shell, so then we can execute commands remotely on the device.
- Run PowerShell as an Administrator
- Start WinRM service to enable remote connections:
net start WinRM
- Add your Raspberry Pi 2 in a trusted device list:
Set-Item WSMan:\localhost\Client\TrustedHosts -Value <IP Address>
- Disable psreadline module. It might cause StackOverflowException
remove-module psreadline -force
- Connect to the remote device. Default password: p@ssw0rd
Enter-PsSession -ComputerName <IP Address> -Credential <IP Address or localhost>\Administrator
Now you have PowerShell console access to the Raspberry Pi 2. All commands that you type in a terminal will be executed on the remote device. It is time to switch to the headless mode.
In PowerShell type following:
setbootoption.exe headless shutdown /r /t 0
After reboot, your device will be in the headless mode. To switch back connect with PowerShell and execute following commands:
setbootoption.exe headed shutdown /r /t 0
In the next part we will see how to create simple service for Raspberry Pi 2.