Powershell isn't in the path by default (on Win2008 at least) #18

Closed
hh opened this Issue Dec 12, 2011 · 6 comments

Comments

Projects
None yet
3 participants
Contributor

hh commented Dec 12, 2011

Against a fresh Windows Server 2008 R2 w/SP1 from http://technet.microsoft.com/en-us/evalcenter/dd459137.aspx (which includes powershell v2.0)

>> winrm.cmd ("powershell") {|stdout,stderr| puts stderr}
'powershell' is not recognized as an internal or external command,
operable program or batch file.
=> {:data=>[{:stderr=>"'powershell' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n"}], :exitcode=>1}                                                                                                                             
>> winrm.run_powershell_script('echo foo')
=> {:data=>[{:stderr=>"'powershell' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n"}], :ex
itcode=>1}                                                                                                                             
>> winrm.cmd ("%systemroot%\\system32\\WindowsPowerShell\\v1.0\\Powershell.exe -c echo $PSVersionTable::PSVersion") {|stdout,stderr| put
s stdout}                                                                                                                              

Major  Minor  Build  Revision

-----  -----  -----  --------
2      0      -1     -1      


=> {:data=>[{:stdout=>"\r\n"}, {:stdout=>"Major  Minor  Build  Revision"}, {:stdout=>"\r\n-----  -----  -----  --------\r\n2      0     
 -1     -1      \r\n\r\n\r\n"}], :exitcode=>0}                                                                                         
Contributor

hh commented Dec 13, 2011

Might be interesting to locate the powershell binary and it's version via winrm...
I also noted that I had to add an extra "\x00" to the end of the command around the join to make it encode properly.

class WinRM::WinRMWebService
  def powershell_version
    shell_id = open_shell
    command_id = run_command(shell_id, '%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell -c echo $PSVersionTable')
    command_output = get_command_output(shell_id, command_id) #, &block)
    cleanup_command(shell_id, command_id)
    close_shell(shell_id)
    command_output
    /PSVersion\W*(\d+.\d+)/.match(command_output[:data].map {|x| x[:stdout]}.join) do |m|
      puts m[1]
    end
  end
  def hardcoded_powershell_script(script_file, &block)
    # if an IO object is passed read it..otherwise assume the contents of the file were passed
    script = script_file.kind_of?(IO) ? script_file.read : script_file
    script = script.chars.to_a.join("\x00") + "\x00" #### Extra \x00 added
    puts script.inspect
    if(defined?(script.encode))
      script = script.encode('ASCII-8BIT')
      script = Base64.strict_encode64(script)
    else
      script = Base64.encode64(script).chomp
    end

    shell_id = open_shell
    command = "%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell -encodedCommand #{script}"
    puts command
    command_id = run_command(shell_id, command)
    command_output = get_command_output(shell_id, command_id, &block)
    cleanup_command(shell_id, command_id)
    close_shell(shell_id)
    command_output
  end
end
Owner

zenchild commented Dec 14, 2011

I'm not able to reproduce your issue. My shell seems to be finding the powershell binary correctly. I'll run the test on a couple other boxes to see if I can find a misbehaving system, but so far I can't find one.

winrm.cmd 'powershell -c echo $PSVersionTable::PSVersion'
 => {:data=>[{:stdout=>"\r\n"}, {:stdout=>"Major  Minor  Build  Revision"}, {:stdout=>"\r\n-----  -----  -----  --------\r\n2      0      -1     -1      \r\n\r\n"}, {:stdout=>"\r\n"}], :exitcode=>0} 
Contributor

hh commented Dec 14, 2011

Download Windows Server 2008 R2 with Service Pack 1:
http://technet.microsoft.com/en-us/evalcenter/dd459137.aspx
Resulting in
7601.17514.101119-1850_x64fre_server_eval_en-us-GRMSXEVAL_EN_DVD.iso

Boot and install taking all defaults for windows server 2008 standard.
Just enable winrm.

Check you path via winrm, mine only includes c:\windows\system32.

On Thu, Dec 15, 2011 at 6:02 AM, Dan Wanek <
reply@reply.github.com

wrote:

I'm not able to reproduce your issue. My shell seems to be finding the
powershell binary correctly. I'll run the test on a couple other boxes to
see if I can find a misbehaving system, but so far I can't find one.

Contributor

pmorton commented Jun 8, 2012

Chris - I too have been unable to confirm this bug. Can you confirm that this is still an issue?

Contributor

pmorton commented Jun 8, 2012

@hh I think that this is a bi-product of the veewee build process. The default installation of windows does not seem to have this problem, thought the veewee build does.

Contributor

pmorton commented Mar 22, 2013

@hh I strongly believe that this was due to the use of SETX in the veewee provisioning process. Please feel free to re-open if you are able to re-pro this issue without the use of veewee

@pmorton pmorton closed this Mar 22, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment