As part of my project to create a blog, I want to be able to easily create markdown (.md) files and upload them to web server.
There are a number of ways to do this. I could just add them to my web site code and re-publish the code each time. I could set up an FTP process. I could use the "Local Resources" feature via Remote Desktop (RDP).
Each of these are fine but more effort than I wanted for a simple file upload. On Linux there is this handy utility called scp (secure copy) that makes this pretty simple. I'm sure there is a third-party something for this on Windows but now we are back to more effort...
I use Powershell at work for some basic tasks, so I decided to see if I could make make Powershell Remoting work.
Powershell Remoting allows you to make a remote connection to a server via the command line - similar to RDP but command line based instead of GUI based.
Here is what I've done:
Enable-PSRemoting -SkipNetworkProfileCheck -Force
(The -Force bypasses the "are you sure prompts", the -SkipNetworkProfileCheck allows it to work if your "network category" your you PC is "public")
Set-Item WSMan:localhost\client\trustedhosts -value "[IP address of the VM]"
Get-Item WSMan:\localhost\Client\TrustedHosts
Now the local PC is configured. Let's work on the server.
On the Azure VM Server:
If you are running the software based Windows Firewall on your VM, you will also want to allow inbound connections on ports 5985-5986 (not covered here).
Enable-PSRemoting -Force
You should see some status/config text. If you see a red error message something isn't configured correctly.
That's it. Now Windows Remoting is configured. Test it on your local PC with this command in Powershell:
Test-WsMan [IP address of the VM]
Now connect to your VM via the command line:
Enter-PSSession -cn "[IP address of the VM]" -credential [your server login]
You will then be prompted with a Windows dialog to enter your password for the remote server. If successful you will then see the command prompt in Powershell change to something like:
[IP address of the VM]: PS C:\Users\your login\Documents>
Note that you are now executing command on the remote VM. Enter "dir" for example. Enter "exit" to exit.
Powershell scripting is another topic, but I use the Powershell ISE to then transfer files with a script like this:
$creds = Get-Credential $session = New-PSSession -ComputerName "IP address of the VM" -Credential $creds Copy-Item "C:\localpath\powershellremoting.md" -Destination "C:\remotepath\blog" -ToSession $session -Force