I have a powershell script that I'm attempting to execute over SSH. The command works perfectly when I run it from the server's powershell commandline.
Here is my Powershell script:
ImportSystemModules
$vms = Get-ClusterResource | Where-Object{$_.ResourceType -like "Virtual Machine"}
foreach ($vm in $vms)
{
if ($vm -eq "Virtual Machine server-name")
{
Echo "Stop $vm"
Stop-ClusterGroup $vm.OwnerGroup
}
}
Here is the command that I am executing:
C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe -file "C:\Scripts\VMShutDown.ps1"
However, when I run this from a remote machine (Ubuntu 12.04). I get the following error:
Get-ClusterResource : The term 'Get-ClusterResource' is not recognized
as thename of a cmdlet, function, script file, or operable program. Check
thespelling of the name, or if a path was included, verify that the path
iscorrect and try again.
Any thoughts to what I might be doing wrong?
Operating Systems:
Windows Server 2012 Standard – 64 Bit Operating System
Ubuntu 12.04.4 LTS
Best Answer
Problem:
Remote power shell executes 32 bit power shell, even on a 64 bit machine. This causes issues loading modules that are only installed and able to be executed using 64 bit process (Failover Clustering for example)
I created a .bat file which executed the ps1 script from the command line:
Inside this script, you have to create an alias to point to the native 64 bit executable for powershell:
Once you do this, you can execute another file from within this file:
Here, it will load all the proper modules, and execute your 64 bit script.
After doing that, I was able to execute my PS command from Linux and it worked like a charm.
Reference to solution:
http://karlprosser.com/coder/2011/11/04/calling-powershell-64bit-from-32bit-and-visa-versa/