Author Archives: Andrew

Using OpenSSH and SSH on Windows

Published by:

Secure Shell software allowing connections between clients and servers for remote administration.

Related Powershell Commands:
Check the installation status
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'

Start the service
Start-Service sshd

Change the service startup behaviour
Set-Service -Name sshd -StartupType 'Automatic'

Add/Install the service
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Local Tunneling allows a port on your local client machine to act as a port on the remote server.
Jump to remote tunnel at 7m 43 secs
Useful Commands to show the logged in user account etc:

tasklist /s <pcname> /fi "imagename eq explorer.exe" /v

wmic /node: <pcname> computersystem get username

wmic /node: <pcname> computersystem get manufacturer, model, username

Or locally:
wmic computersystem get manufacturer, model, username

Change the Network Hostname (Requires Admin account)
Using CMD
wmic computersystem where name="%COMPUTERNAME%" rename "NewName"

Use Powershell and CMD to switch between sessions on either command line  

Using Powershell
Rename-Computer "NewName" -Restart

Windows cURL on the command line

Published by:

Command line and scripting tool for transferring data with URLs see the website Curl.se

curl -L -A "Mozilla" http://website.com

This follows re-directs and uses a dummy header to anticipate 406 Not Acceptable errors then returns the page content, you can use a full header string to represent other browsers

This YouTube video is presented by the cURL creator

Windows Robocopy command common usage issues problems & gotchas

Published by:

Enclosing the source or destination in double quotes allows the use of paths with spaces in the folder names but DO NOT end with a trailing backslash ‘\’ as this will be interpreted as an escape character.

When using the task scheduler to run a robocopy command script be aware that using the account credentials of the logged-in user may be necessary for access to network drives referred to by the command. An administrator account may not have the necessary permissions.

Syntax
      ROBOCOPY Source_folder Destination_folder [files_to_copy] [options]

      ROBOCOPY "M:\" "X:Destination Folder\" DON'T USE EITHER OF THESE

      ROBOCOPY M:\ "X:Destination Folder" THIS WORKS

Windows Batch File – Copy Folder from an Existing Template with User Input

Published by:

Paste the following code into a .bat text file to create a runnable script that copies an example template folder with contents to a new folder with a name entered by the user. There are an additional couple of lines that then rename and delete files in the new folder as an example of further customisation that could be automated.

@echo off
pushd %~dp0
REM request a Directory Name
set /p UserInput= "Create Directory: "
REM create directory using a source folder template
if not exist "%UserInput%" (
mkdir "%UserInput%"
xcopy /e SourceTemplateFolder "%UserInput%"
REM customise contents
rename "%UserInput%\Content.txt" NewContent.txt
del "%UserInput%\FileToDelete.txt"
)
popd