问题标签 [pssnapin]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
2338 浏览

powershell - PowerShell v1 中的等效加载模块

出于脚本可移植性的原因,我需要在 PowerShell 脚本中动态加载管理单元。这很容易在 PowerShell v2 中使用该Load-Module功能完成。我需要在一台机器上运行这个特定的脚本,由于各种原因,我不想安装 PowerShell v2,但有 v1。

PowerShell v1 中是否有Load-Module等价物?

0 投票
2 回答
540 浏览

powershell - Make-Shell 是否已弃用?

几年前,我使用 Make-shell 创建带有自定义 cmdlet 的自定义 shell。后来我使用了管理单元技术,我忘记了那个选项。

现在我应该为一大群客户部署一套自定义的cmdlet,最好提供一个零配置的解决方案;因此,我记得自定义 shell 解决方案,我想知道它是否仍然是这种情况下的最佳解决方案。这也很有帮助,因为我的 cmdlet 使用 WF 4.0,因此 shell 应该在最新的框架版本下运行。无论如何,我对它的支持有点害怕:它仍然可以使用 Powershell 2.0 功能吗?

是否有其他方法可以轻松地在客户的计算机上部署 cmdlet?

谢谢

0 投票
2 回答
2394 浏览

powershell - 在自定义 pssnapin 上运行 install util 时未找到安装程序

我创建了一个非常简单的 PSSnapin,但是当我对程序集运行 IntallUtil 时,我得到以下信息:

在 C:\Tools\PowerShellCommands\SetServerDataSource\bin\Debug\SetServerDataSource.dll 程序集中找不到具有 RunInstallerAttribute.Yes 属性的公共安装程序。删除 InstallState 文件,因为没有安装程序。

但是,我肯定有一个带有 [RunInstaller(true)] 的安装程序(继承自 CustomPSSnapIn):

有任何想法吗?

0 投票
1 回答
2179 浏览

powershell - PowerShell 中的 Add-PSSnapin 和 Import-Module 有什么区别?

可能重复:
Add-PsSnapIn 和 Import-Module 有什么区别

PowerShellAdd-PSSnapin和in有什么区别?Import-Module

最后,两者似乎都提供了相同的结果。

推荐的方法是哪一种?

0 投票
1 回答
171 浏览

powershell - 为自定义 Powershell 提供程序设置一键安装

我创建了一个自定义 Powershell 提供程序。但是,目前人们必须执行几个步骤才能使其在用户的计算机上运行:

  1. 配置 Powershell 以针对 .Net 4 运行(在 c:\Windows\System32\WindowsPowerShell\v1.0 中添加配置文件)
  2. 添加自定义格式化程序(到 System32 的 c:\Windows\System32\WindowsPowerShell\v1.0)。
  3. 注册管理单元。

其余设置步骤由自定义 powershell 脚本完成。

我想知道是否有人可以分享他们在简化流程方面的经验。理想情况下,我希望人们从单个命令运行(理想情况下是完成上述所有步骤的 CommandLet。

有没有人可以分享任何链接或建议或最佳实践?

0 投票
3 回答
69244 浏览

powershell - 没有为 Windows PowerShell 版本 2 注册任何管理单元

我正在尝试在未安装 SQL Server Management Studio 但已安装 Microsoft SQL Server 2008 R2 SP2 Feature Pack 中的所有相关软件包的 Web 服务器上运行 Powershell 脚本。您需要安装这些小部件,以便 Powershell 能够运行 SQL 命令。

然后我运行了这个设置脚本,为使用 Powershell 运行的 SQL Server 命令准备环境:

Add-PSSnapin SqlServerCmdletSnapin100,脚本失败并出现以下错误:

没有为 Windows PowerShell 版本 2 注册任何管理单元。在 C:\Vantiv\Initialize-SqlpsEnvironment.ps1:75 char:13 + Add-PSSnapin <<<< SqlServerCmdletSnapin100 #-ErrorAction SilentlyContinue + CategoryInfo : InvalidArgument: (SqlServerCmdletSnapin100: String) [Add-PSSnapin], PSArgumentException + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

我对这个错误进行了谷歌搜索,我能找到的唯一解决方案是人们说我的 64 位 Powershell 控制台快捷方式指向 SysWOW64 目录而不是 System32。这不是我的情况。我的指向 System32。

有任何想法吗?我需要做什么才能让 Powershell 注册这些管理单元?

0 投票
1 回答
2561 浏览

c# - ImportPSModule 故障检测

我正在尝试使用InitialSessionState.ImportPSModule以导入 Powershell 模块。

我有兴趣知道模块的导入是否由于任何原因(例如找不到文件等)而失败。将此类代码放在 try 块中不会在失败的情况下引发异常,并且该函数似乎会静默失败并在无法导入模块时继续。

如果导入失败,有没有办法在代码中发出警报?

我正在尝试执行以下操作。在下面的代码中,模块“TestModule1234”不存在。catch 块不会捕获异常。

注意:这只是原型测试代码,所以请忽略任何与生产代码相关的违规行为。

0 投票
2 回答
4739 浏览

powershell - PowerShell 模块和管理单元

我创建了几个都依赖于 Microsoft.SharePoint.PowerShell 管理单元的实用程序模块。

当在我的机器上运行时,脚本都正确运行,我的配置文件中没有任何模块或管理单元用于 powershell “默认加载”,但是在其他机器上,它们的配置文件不能保证是干净的。

在我的模块加载器 .psd1 文件中,我使用以下

我使用 ps1 文件来触发这些模块导入,其中包含以下 Import Module 命令

如果我以这种方式运行,我会在配置文件包含 Microsoft.SharePoint.PowerShell 管理单元的计算机上出现名称冲突错误,因为该管理单元已被加载。

我知道我们可以使用 -NoProfile 参数执行 PowerShell 命令,但这在我们的场景中不是一个有效的解决方案。

我还尝试从 NestedModules 部分删除管理单元并在导入模块之前在 .ps1 文件中运行以下命令,但管理单元未显示为已加载,因此模块导入失败。

如何重新设计此解决方案以确保管理单元将正确加载并且模块将成功导入而不管用户配置文件如何?

我的理想情况如下:

0 投票
1 回答
576 浏览

.net - 在 Web 服务中为 Exchange 运行 Powershell 脚本

我正在尝试在 Web 服务中为 Microsoft Exchange 运行一些 Powershell 脚本。下面编写的代码在从控制台应用程序运行时可以正常工作,但是当我将其移动到 Web 服务项目并调用 Web 方法时,它会在调用 AddPSSnapIn 时出错。知道为什么吗?我在 Windows Server 2008 R2 64 位机器上运行它。目标平台已从任何 CPU 更改为 x64,但没有任何运气。

0 投票
1 回答
2709 浏览

powershell - Add Powershell Snapin for Powershell Module and Import Multiple Times

I would like to use the SqlServerCmdletSnapin for my custom Powershell Commandlet I am building. If I add the following code to the beginning of my PSM1:

#xA;

everything works great the first time I run:

Import-Module MyModule -Force

However, the second time I run:

Import-Module MyModule -Force

I get the following error:

Add-PsSnapin : An item with the same key has already been added.

and my code can no longer call Invoke-SqlCmd. What is the best way to add a powershell snapin to my custom module?