2017-03-21 3 views
1

私はCentosボックスからいくつかのPowerShellスクリプトを実行しようとしています。私はpowershellをうまくインストールして、実行したいスクリプトをさらに入手しました。 PowerShellでpowershell psd1をインポートしてコマンドを使用しますか?

私が実行した:

DhcpServer.psd1 
DhcpServerPSProvider.Format.ps1xml 
PS_DhcpServerv4Lease_v1.0.0.cdxml 
PS_DhcpServerV4Scope_v1.0.0.cdxml 
:私は私のフォルダ/ツール/ PowerShellのに次のようにインポートした

Get-DhcpServerv4Scope -ComputerName 10.66.56.66 

を:

Import-PowershellDataFile ./tools/powershell/DhcpServer.psd1 

は、私は使用しようとしました

IveはDhcpServer.psd1を編集して、Get-DhcpServerv4ScopeおよびGet-DhcpServerv4Lease以外のすべての機能を削除しました。これらは私がこのツールに必要な唯一の2つです。

HERESに私の試みの出力:

PS /root/itapp> Import-PowershellDataFile ./tools/powershell/DhcpServer.psd1 

Name       Value 
----       ----- 
TypesToProcess     DhcpServerPsProvider.Types.PS1XML 
ClrVersion      4.0 
NestedModules     {PS_DhcpServerv4Lease_v1.0.0.cdxml, PS_DhcpServerV4Scope_v1.0.0.cdxml} 
Author       Microsoft Corporation 
CompanyName     Microsoft Corporation 
Copyright      © Microsoft Corporation. All rights reserved. 
FunctionsToExport    {Get-DhcpServerv4Scope, Get-DhcpServerv4Lease} 
FormatsToProcess    DhcpServerPsProvider.Format.ps1xml 
HelpInfoUri     http://go.microsoft.com/fwlink/?linkid=285742 
GUID       90eaa9df-133a-450c-8728-91055cd946a1 
ModuleVersion     2.0.0.0 
PowerShellVersion    3.0 


PS /root/itapp> Get-DhcpServerv4Scope -ComputerName 10.66.56.66 
Get-DhcpServerv4Scope : The term 'Get-DhcpServerv4Scope' 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 
+ Get-DhcpServerv4Scope -ComputerName 10.10.10.10 
+ ~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : ObjectNotFound: (Get-DhcpServerv4Scope:String) [], CommandNotFoundException 
    + FullyQualifiedErrorId : CommandNotFoundException 

PS /root/itapp> 

は、誰も私を助けることができますか? ありがとう

+0

私はpsd1ファイルにimport-moduleを使用するべきだと思います。 –

答えて

2

.psd1ファイルはモジュールマニフェストファイルです。コンパイルされたモジュールでない限り、コードを含む.psm1ファイルも存在する必要があります。あなたが使用する必要があるモジュールをロードするには

Import-Module ./tools/powershell/DhcpServer.psd1 

Import-PowershellDataFileをちょうどそれが機能/コマンドレットをロードしない、ハッシュテーブルにして、データ・ファイルの内容を読み取ります。

+1

ありがとう、それはそれをした、私は今他のエラーがあるが、それらの最初の研究を病気 – AlexW

関連する問題