powershell导入psd1并使用命令?

时间:2017-03-21 09:46:39

标签: powershell centos

我正在尝试从Centos框中运行一些PowerShell脚本。我已经成功安装了powershell,然后进一步获得了我希望运行的脚本。

在powershell中我已经运行了

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

然后我尝试使用:

Get-DhcpServerv4Scope -ComputerName 10.66.56.66

我已将以下内容导入我的文件夹/ tools / powershell:

DhcpServer.psd1
DhcpServerPSProvider.Format.ps1xml
PS_DhcpServerv4Lease_v1.0.0.cdxml
PS_DhcpServerV4Scope_v1.0.0.cdxml

我编辑了DhcpServer.psd1以删除除Get-DhcpServerv4Scope和Get-DhcpServerv4Lease之外的所有函数,这些是我需要的唯一这个工具。

继承我尝试的输出:

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>

任何人都可以帮助我吗? 感谢

1 个答案:

答案 0 :(得分:2)

.psd1文件是Module Manifest文件。还应该有一个包含代码的.psm1文件(除非它是一个已编译的模块)。

要加载您需要使用的模块:

Import-PowershellDataFile

{{1}}只是将数据文件的内容读入哈希表,它不会加载函数/ cmdlet。