chocolatey-archive / chocolatey

[DEPRECATED - https://github.com/chocolatey/choco] Chocolatey NuGet - Like apt-get, but for windows.
https://chocolatey.org
Apache License 2.0
2.81k stars 344 forks source link

[Enhancement] Make Chocolatey work with powershell remoting #136

Open zippy1981 opened 12 years ago

zippy1981 commented 12 years ago

If I remotely invoke powershell commands thrugh Enter-PSSession, running cup all or chocolatey update all gives the following:

[remoteServerName]: PS C:\Users\jdearing\Documents> chocolatey update all
chocolatey does not appear to be on the source(s) specified: '-Source "http://chocolatey.org/api/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=230477" ' (if value is empty, using sources in nuget.config file). You have 0.9.8.19 installed. Interesting...
Far-3 does not appear to be on the source(s) specified: '-Source "http://chocolatey.org/api/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=230477" ' (if value is empty, using sources in nuget.config file). You have 3.0.2779.20120727 installed. Interesting...
fiddler does not appear to be on the source(s) specified: '-Source "http://chocolatey.org/api/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=230477" ' (if value is empty, using sources in nuget.config file). You have 2.4.0.0 installed. Interesting...
kdiff3 does not appear to be on the source(s) specified: '-Source "http://chocolatey.org/api/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=230477" ' (if value is empty, using sources in nuget.config file). You have 0.9.95.1 installed. Interesting...
Less does not appear to be on the source(s) specified: '-Source "http://chocolatey.org/api/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=230477" ' (if value is empty, using sources in nuget.config file). You have 3.0 installed. Interesting...
linqpad4 does not appear to be on the source(s) specified: '-Source "http://chocolatey.org/api/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=230477" ' (if value is empty, using sources in nuget.config file). You have 4.42.1 installed. Interesting...
sysinternals does not appear to be on the source(s) specified: '-Source "http://chocolatey.org/api/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=230477" ' (if value is empty, using sources in nuget.config file). You have 1.2012.05.14 installed. Interesting...
Wget does not appear to be on the source(s) specified: '-Source "http://chocolatey.org/api/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=230477" ' (if value is empty, using sources in nuget.config file). You have 1.11.4.1 installed. Interesting...
windirstat does not appear to be on the source(s) specified: '-Source "http://chocolatey.org/api/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=230477" ' (if value is empty, using sources in nuget.config file). You have 1.1.2.1 installed. Interesting...
[remoteServerName]: PS C:\Users\jdearing\Documents>

However, if I RDP into the server and run powershell from the RDP session, it seems to work:

C:\Users\jdearing> cup all
You have the latest version of chocolatey (0.9.8.19) based on: '-Source "http://chocolatey.org/api/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=230477" ' (if value is empty, using sources in nuget.config file).
You have the latest version of Far-3 (3.0.2779.20120727) based on: '-Source "http://chocolatey.org/api/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=230477" ' (if value is empty, using sources in nuget.config file).
You have the latest version of fiddler (2.4.0.0) based on: '-Source "http://chocolatey.org/api/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=230477" ' (if value is empty, using sources in nuget.config file).
You have the latest version of kdiff3 (0.9.95.1) based on: '-Source "http://chocolatey.org/api/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=230477" ' (if value is empty, using sources in nuget.config file).
You have the latest version of Less (3.0) based on: '-Source "http://chocolatey.org/api/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=230477" ' (if value is empty, using sources in nuget.config file).
You have the latest version of linqpad4 (4.42.1) based on: '-Source "http://chocolatey.org/api/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=230477" ' (if value is empty, using sources in nuget.config file).
You have the latest version of sysinternals (1.2012.05.14) based on: '-Source "http://chocolatey.org/api/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=230477" ' (if value is empty, using sources in nuget.config file).
You have the latest version of Wget (1.11.4.1) based on: '-Source "http://chocolatey.org/api/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=230477" ' (if value is empty, using sources in nuget.config file).
You have the latest version of windirstat (1.1.2.1) based on: '-Source "http://chocolatey.org/api/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=230477" ' (if value is empty, using sources in nuget.config file).
C:\Users\jdearing>

I should be able to run chocolatey through powershell remoting.

rismoney commented 12 years ago

it returns "does not appear to be on the source specified" if the $versionlatest is empty.

what happens when you just do a nuget list kdiff3 for example?

What is in the list.log in your chocolateyinstall folder after you run chocolatey update all?

zippy1981 commented 12 years ago

nuget isn't on my path on the remote machine, but this is what I get if I execute C:\Chocolatey\chocolateyInstall\NuGet.exe list kdiff3 locally or remotely:

kdiff3 0.9.95

rismoney commented 12 years ago

list.log should contain the output of all packages like you listed for kdiff. if that file doesn't have the information, you get the errors you see. lets first make sure it is resolving nuget before going into details.

go into C:\chocolatey\chocolateyinstall. type

. .\chocolatey.ps1
$nugetExe

does it return C:\Chocolatey\chocolateyInstall\nuget.exe ?

zippy1981 commented 12 years ago

So it appears that much is working.

[myRemoteMachine]: PS C:\Users\jdearing\Documents> cd  C:\chocolatey\chocolateyinstall
[myRemoteMachine]: PS C:\chocolatey\chocolateyinstall> . .\chocolatey.ps1
Please run chocolatey /? or chocolatey help
[myRemoteMachine]: PS C:\chocolatey\chocolateyinstall> $nugetExe
C:\chocolatey\chocolateyinstall\nuget.exe
[myRemoteMachine]: PS C:\chocolatey\chocolateyinstall>
rismoney commented 12 years ago

didn't forget about this- i will test further, probably next week in my chocolatey lab. the issue is definitely $versionlatest being empty, but need to instrument it first hand.

LCHarold commented 12 years ago

I get inconsistent behavior from Chocolatey when using it in a remote session created using Enter-PSSession.

BUT if I use New-PSSession and then call Chocolatey with Invoke-Command, it works. Why? I have no idea... I'm new to PowerShell remoting. But given the inconsistent results from Chocolatey under Enter-PSSession, the "interactive" nature of the session seems likely to be the culprit.

Here's how I've gotten Chocolatey to work through a remote PowerShell session:

$securePassword = ConvertTo-SecureString "mypassword" -AsPlainText -force
$credential = New-Object System.Management.Automation.PsCredential("domain\login", $securePassword)
$session = New-PSSession -ComputerName server1 -Credential $credential
Invoke-Command -Session $session -Scriptblock { cinst 7zip }
# run other commands remotely using Invoke-Command... remove the session when done
Remove-PSSession $session
zippy1981 commented 12 years ago

So what's the difference between Enter-PSSession and Invoke-Command -Session? Is it a matter of how stdin/stdout/stderr behave?

mzboray commented 11 years ago

I ran into this problem when testing out chocolatey and here's how I solved it. The issue is really the infamous double-hop. Since nuget.exe is going to connect to remote system it will not be able to pass along NTLM credentials. However when I used CredSSP authentication and Invoke-Command I was able to use all of the chocolatey commands (cup, cinst, etc.) remotely. This blog post has a good description of how to set up the CredSSP authetication mechanism.

robianmcd commented 11 years ago

@mzboray Thanks I tried your solution and it works for the most part. But I am still getting the "Your version is newer than the most recent. You must be smarter than the average bear..." error message when I run cver

mwrock commented 11 years ago

I have been doing alot of experimentation lately around remoting and chocolate. My next boxstarter release will support this and auto configure the remoting client as well as the target as long as the wmi ports are open.

most packages will work fine using vanilla remoting but there are some tricky edge cases. One is the double hop scenario mentioned above. The solution there is using credssp. This will solve issues around accessing shares that require your auth token.

the stikiest issue is around windows update. Alot of Ms installs interact with the win update service. Examples are the .net frameworks, ie10, webpi and probably plenty others. Win update will not honor a remote token. The only reliable solution I have found is using scheduled tasks. I create a scheduled task for the choco pkg and forward the output and error streams to a file. I launch the task and use a file stream to stream to the console. Its more painful than I thought it would be.

one other case that simply won't work is most packages that use autoit or anything that interacts with a window.

not sure why there would be issues with enter-possession but I almost always use invoke-command.

mzboray commented 11 years ago

@robianmcd I tried cver and it worked for me. I definitely saw that message a lot when I was trying to figure this out. That seems to be the error path when the output of nuget does not contain the package you are looking for (probably a bug that should be filed). I would take a look at C:\Chocolatey\chocolateyInstall\list.log to see what the output of nuget was on the remote machine.

robianmcd commented 11 years ago

@mzboray The list.log file just listed a bunch of packages but the chocolateyInstall.log outputs this when I run cver:

[DEBUG] Running 'Chocolatey-Version' for chocolatey with source:''. [DEBUG] Running 'Get-ConfigValue' with configValue:'useNuGetForSources' [DEBUG] Running 'Get-UserConfigValue' with configValue:'useNuGetForSources' [DEBUG] After checking the user config the value of 'useNuGetForSources' is '' [DEBUG] Value not found in the user config file - checking the global config [DEBUG] Running 'Get-GlobalConfigValue' with configValue:'useNuGetForSources' [DEBUG] After checking the global config the value of 'useNuGetForSources' is 'false' [DEBUG] Running 'Get-UserConfigValue' with configValue:'sources' [DEBUG] Running 'Get-GlobalConfigValue' with configValue:'sources' [DEBUG] Using global sources [DEBUG] Using '-Source "http://chocolatey.org/api/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=230477 " ' as the source arguments [DEBUG] based on: '-Source "http://chocolatey.org/api/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=23 0477" ' feed [DEBUG] Calling 'C:\Chocolatey\chocolateyinstall\nuget.exe' list "chocolatey" -Source "http://chocolatey.org/a pi/v2/" -Source "https://go.microsoft.com/fwlink/?LinkID=230477" -NonInteractive [DEBUG] Long version of is '000000000000' [DEBUG] Long version of 0.9.8.20 is '000000000000.000000000009.000000000008.000000000020'

Any idea what's going on? Thanks!

mzboray commented 10 years ago

@robianmcd As you might have guessed I have no idea what's wrong. list.log will have a bunch of packages, but it should have chocolatey in it. If it doesn't something is wrong with how nuget is getting the chocolatey package from its sources. Perhaps try pinging chocolatey.org (or using something like (new-object System.Net.WebClient).DownloadString("http://chocolatey.org/api/v2/") ) in the remote session and see if you can at least reach it.

robianmcd commented 10 years ago

@mzboray - the list.log file has all these chocolatey packages: chocolatey 0.9.8.20 ChocolateyPackageUpdater 0.6.1.0 ChocolateyDeploymentUtils 1.0.3 chocolatey.dev 1.0 ChocolateyGUI 0.11.1

Also running the command that pings chocolatey seems to work fine. I get this back: `<?xml version="1.0" encoding="utf-8" standalone="yes"?>

Default Packages

`

I tried remoting into several computers and I get the error message on 3 of them (including my own computer). I get the expected results on another 3 computers and I get: "chocolatey does not appear to be on the source(s) specified" on the last computer?!? Note that the list.log file is empty on the last computer.

I've tried installing stuff with cinst and it seems to work fine though so maybe this isn't that big of a deal.

Thanks for your help!

spjeff commented 10 years ago

I work on many SharePoint servers and created a PowerShell remoting "wrapper" to help automate tasks just like this. Basically, put your favorite PowerShell into the "verb" CSV and servers into the "noun" CSV and crank it up. HUGE time saver for me and I wanted to share with other PS remote admins. http://splaunch.codeplex.com/

splaunch