gpt4 book ai didi

powershell 导入 psd1 并使用命令?

转载 作者:太空宇宙 更新时间:2023-11-03 17:19:05 28 4
gpt4 key购买 nike

我正在尝试从 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>

谁能帮帮我?谢谢

最佳答案

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

加载你需要使用的模块:

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

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

关于powershell 导入 psd1 并使用命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42923390/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com