我创建了一些psm1文件,并将以下行放在每个psm1文件的顶部,
Set-StrictMode -Version 2
Add-PSSnapin SqlServerCmdletSnapin*
Add-PSSnapin SqlServerProviderSnapin*
然而,它得到了警告
WARNING: The names of some imported commands from the module 'mymodule' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.
如果多次导入模块,会出现以下错误。
Add-PSSnapin : An item with the same key has already been added. At line:1 char:1 + Add-PSSnapin SqlServerCmdletSnapin* + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Add-PSSnapin], ArgumentException + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.AddPSSnapinCommand Add-PSSnapin : An item with the same key has already been added. At line:2 char:1 + Add-PSSnapin SqlServerProviderSnapin* + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Add-PSSnapin], ArgumentException + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.AddPSSnapinCommand
或者有没有办法在系统启动时为每个用户加载这些管理单元?
答案 0 :(得分:1)
警告只是说SqlServerCmdletSnapin
和SqlServerProviderSnapin
的作者使用了一些“未经批准”的名称来表示其功能。但是这些功能可以正常工作,不过MS认为它们可以“不易被发现”(当用户搜索命令如写“Get-”并从PS控制台按Tab-Tab-Tab ...时)。
所以你把它们放在首位是正确的,只需添加-ErrorAction SilentlyContinue
即可消除警告:
Add-PSSnapin SqlServerCmdletSnapin* -ErrorAction SilentlyContinue
Add-PSSnapin SqlServerProviderSnapin* -ErrorAction SilentlyContinue
至于为每个用户加载这些管理单元,有几个选项可以使用配置文件来完成。阅读Understanding the Six PowerShell Profiles文章。