To demonstrate how powerful the IIS Odata extension for PowerShell is, I’ve tweaked the SSH PowerShell module that I published previously for use with Azure Pack. By doing so, as long as I can connect to my Windows IIS web server, I can relay SSH commands from any other physical environment.
You will need to have setup the Odata IIS server extension as described in http://www.laurierhodes.info/?q=node/111
Download the SSH module from http://www.laurierhodes.info/?q=node/109
The files need to be extracted to the PowerShell Modules folder of the IIS server. As with the previous example, the RbacConfiguration.xml will need to be amended to include the newly downloaded module.
As I will be passing Passwords across the Odata interface, I need to at least ensure that I’m using a secure transport (https)
Using IIS Manager, I locate the MODataSCV site and first need to edit the bindings. This gives me the ability to associate an https port (with a port number of my choosing) to the site.
I’ve already had a certificate issued from my Certificate Authority from the web server template. (I will assume that you have a usable certificate issued as setting up an Authority and enrollment is a bigger topic).
Don’t forget to open a port on your firewall!
Using the Module
I’ll start with a GET request against the Odata interface to see what functions are currently exposed. By using PowerShell’s Select with Odata, I can easily see which modules are now available for use over that interface.
Using an almost identical script to that used in the previous example, I’ll use the Invoke-SSHCommand that’s being hosted through the IIS web server. This time, the script uses https on my new port of 7001.
[[powershell]] cls $server = "smaserver.domain.com" $cred = New-Object System.Management.Automation.PSCredential ` ("localadmin",(ConvertTo-SecureString "Password1234" -AsPlainText -Force)) # Create the Request $Headers = @{“Accept” = “application/atom+xml,application/xml”} $body = @{ "OutputFormat" = "json"; "Command" = "Invoke-SSHCommand -HostName Oracle7.domain.com -Password MyPassword -SSHCommand `"-t sudo /sbin/ifconfig `" -UserName laurie -AcceptHostKey"; "WaitMsec"= 7000 } $JSON = $body | convertto-json [[/powershell]]
The returned result is the text output of the command on the remote machine.
In this Series:
Calling PowerShell Modules with the REST / ODATA IIS Server extension
Calling PowerShell Modules with the REST / ODATA IIS Server extension (Example 2 - SSH)
Calling PowerShell Modules with the REST / ODATA IIS Server extension (Example 3 - WinRM)
- Log in to post comments