Powershell 开机自动加载Snapin 和module

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Powershell 开机自动加载Snapin 和module相关的知识,希望对你有一定的参考价值。

以前只知道在Powershell的默认路径下面添加第三方的module就可以开机自动加载了

PS C:\WINDOWS\system32> $env:PSModulePath -split ";"
C:\Users\yli\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\ModulesC:\Program Files (x86)\NetApp\NetApp PowerShell Toolkit\Modules\.


但是其他路径的Module怎么处理?Snapin怎么处理,今天终于知道可以配置profile script来配置了。


方法很简单。


PowerShell的用户档案的WindowsPowerShell文件夹里面添加一个新的 profile.ps1 文件,然后在这个文件里面执行import-module和add-pssnapin等命令就可以了。开机的时候会自动执行该文件。


技术分享

例如 开机自动加载对应的一些模块和插件等等


import-module dataontap
Add-PSSnapin VMware.VimAutomation.Core
$cred = Get-Credential 
Import-Module MSOnline
Set-ExecutionPolicy remotesigned
Connect-MsolService -Credential $cred
 
#连接到Office365
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell/ -Credential $Cred -Authentication Basic -AllowRedirection
Import-PSSession $session


本文出自 “麻婆豆腐” 博客,请务必保留此出处http://beanxyz.blog.51cto.com/5570417/1742094

以上是关于Powershell 开机自动加载Snapin 和module的主要内容,如果未能解决你的问题,请参考以下文章

powershell分享5--AD中常用的小语句

特定的 PowerShell 模块未自动加载

使用 PowerShell 自动登录Azure

使用 PowerShell 自动登录 Azure

重置root密码和Linux启动故障排除-开机自动加载服务

Azure 基础:用 PowerShell 自动登录