2015-11-10 116 views
2

以下是我一直在使用1.7.2流浪漢,Ruby和PowerShell中的問題,但是我認爲這是使用PowerShell版本中的一個普遍問題。PowerShell不識別模塊

當我從Cmd的或Poweshell控制檯或ISE運行此命令時,它的工作原理

powershell -version 4.0 -command {import-module C:\windows\system32\windowspowershell\v1.0\Modules\SmbShare\SmbShare.psd1} 

當我運行紅寶石IRB裏面如下它也可以

system('powershell -version 4.0 -noprofile -file PsTest.ps1') 

然而,當我跑了在使用紅寶石的Vagrant內

-version : The term '-version' is not recognized as the name of a cmdlet, function, script file, or operable program 
Check the spelling of the name, or if a path was included, verify that the path is correct and try again. 
At line:1 char:1 

如果我拿出-version參數,我得到

import-module : The specified module 'C:\windows\system32\windowspowershell\v1.0\Modules\SmbShare\SmbShare. 
psd1' 

我認爲是它試圖使用PowerShell 1.0,但是從劇本中我使用$PSVersionTable而這一切情況下,我在我包括

(get-process -id $pid).Path 
#In all cases (even the one that fails) it returns 
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe 
腳本得到了相同的

Key : PSVersion 
Value : 4.0 

Key : WSManStackVersion 
Value : 3.0 

Key : SerializationVersion 
Value : 1.1.0.1 

Key : CLRVersion 
Value : 4.0.30319.42000 

Key : BuildVersion 
Value : 6.3.9600.17400 

Key : PSCompatibleVersions 
Value : {1.0, 2.0, 3.0, 4.0} 

Key : PSRemotingProtocolVersion 
Value : 2.2 

而且

不知道什麼是執行不允許從3.0版本開始加載模塊之間的不同,這就是我想這是運行PowerShell 1.0中雖然PSVersionTable清楚地表明它是4.0

只注意到了同樣的事情發生時,我在Visual Studio 2013更新4項目

任何想法,使用相同的腳本作爲預生成事件?

+1

'C:\ WINDOWS \ SYSTEM32 \ windowspowershell \ v1.0'是* *所有版本的PowerShell安裝的主目錄,不要讓'v1.0'文件夾名稱欺騙您。 –

+0

正如你所說的使用(get-process -id $ pid).Path我看到所有的PowerShell的執行指向C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ powershell.exe – jleyva

+0

你能告訴我們適當的片段VagrantFile?去年,我加入了對Vagrant的提供者的shell爭論的支持。請參閱:https://github.com/mitchellh/vagrant/pull/4548 – Eris

回答

0

這是幾乎可以肯定的意外把-version-command後,大概是這樣一個結果:

powershell -command -version 4.0 {import-module C:\windows\system32\windowspowershell\v1.0\Modules\SmbShare\SmbShare.psd1} 

你並不確切說在哪裏或如何你使用它從無業遊民,所以我不能肯定地說,但檢查它正在執行的地方,看看你是否與訂單不匹配。

Mathias是正確的關於路徑;每個版本都是一樣的,所以不用擔心。

+0

不幸的是,在所有場景中,我使用'powershell -version 4.0 -command {import-module C:\ windows \ system32 \ windowspowershell \ v1.0 \ Modules \ SmbShare \ SmbShare.psd1}' – jleyva

+0

In vagrant I正在使用'config.trigger.before:up do provider = ['hyperv'] \t run「powershell -version 4.0 -file'PsTest.ps1'」\t ' – jleyva