2016-09-26 12 views
0

UNCパスから実行する必要があるPowerShellスクリプトがあります。すなわち\\ myserver \ folder \ a.ps1。スクリプトはパラメータをとります。スクリプトの最初の数行がパラメーターを使用してUNCパスにあるPowershellスクリプトファイルを実行します。

param(
[Parameter(Mandatory)] 
[ValidateSet('DEV','TEST','STAGING')]  
[String]$Server 
) 

以下の通りです。しかし、私は\\ MYSERVER \ folderA \ a.ps1 -S自分のコンピューター上のPowerShellウィンドウ内とヒットタブ自動補完を入力すると動作しませんやvalidate set(Serverパラメータは引数パスにバインドされません)。スクリプトをローカルにコピーして、この自動補完を試して、validatesetが機能するかどうか。 UNCパスでスクリプトを呼び出しても、有効になるように設定するにはどうしたらよいですか?ありがとう。

答えて

0

私のテストスクリプト:

param(
[Parameter(Mandatory)] 
[ValidateSet('DEV','TEST','STAGING')]  
[String]$Server 
) 
echo $server 

マイ結果:

PS Z:\> \\net-02\shares\test.ps1 

cmdlet test.ps1 at command pipeline position 1 
Supply values for the following parameters: 
Server: server 
\\net-02\shares\test.ps1 : Cannot validate argument on parameter 'Server'. The argument "server" does not belong to 
the set "DEV,TEST,STAGING" specified by the ValidateSet attribute. Supply an argument that is in the set and then try 
the command again. 
At line:1 char:1 
+ \\net-02\shares\test.ps1 
+ ~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidData: (:) [test.ps1], ParameterBindingValidationException 
    + FullyQualifiedErrorId : ParameterArgumentValidationError,test.ps1 

あなたが検証作品を見ることができるように。

PS Z:\> \\net-02\shares\test.ps1 

cmdlet test.ps1 at command pipeline position 1 
Supply values for the following parameters: 
Server: dev 
dev 

実行ポリシーに問題があると思われます。制限を解除して再度テストしてください。

Set-ExecutionPolicy -ExecutionPolicy Unrestricted 

remotesignedに変更してスクリプトに署名してください。

+0

ありがとうFarhad。私がしたかったのは、タブを押したときにユーザーに値を表示するための検証セットでした。このスクリプトをローカルに置いて、PS Z:\> Desktop \ shares \ test.ps1 -Serverと入力して、有効な設定値をユーザーに表示します。 – yonaire

関連する問題