当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 默认情况下将 SharePoint 管理单元加载到 PowerShell ISE

作者:精品下载站 日期:2024-12-14 14:01:00 浏览:12 分类:玩电脑

默认情况下将 SharePoint 管理单元加载到 PowerShell ISE


问题:如果您使用 PowerShell ISE 编辑 SharePoint-PowerShell 脚本,您可能会注意到 SharePoint cmdlet 默认情况下不可用,除非您使用“Add-PSSnapin”cmdlet 显式加载它们。这是因为 ISE 默认情况下不加载 SharePoint PowerShell 管理单元。

解决方案:这是默认在 PowerShell ISE 中加载 SharePoint 管理单元的巧妙技巧!您所要做的就是:将 SharePoint 管理单元添加到您的 PowerShell ISE 配置文件中,每次启动 PowerShell ISE 时都会执行该文件!具体方法如下:

要确保创建配置文件,请运行:


#Check if the profile file exists already  
if (test-path $profile)
{
    write-host "profile file already exists at: $profile"
}
else
{
    #Create the profile file
    New-Item -type file -path $profile -force
    write-host "profile file has been created!"
}

如果尚未创建,此脚本将创建一个新的配置文件!你的输出将是这样的:

[玩转系统] 默认情况下将 SharePoint 管理单元加载到 PowerShell ISE

打开从上述脚本收到的配置文件并添加以下行。 (在我的例子中,它是:C:\Users\salaudeen\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1),保存并关闭。


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

因此,从现在开始,您不需要显式加载 SharePoint PowerShell 管理单元作为脚本的第一行!这肯定会节省您的时间并增强您的脚本编写体验。要对所有用户进行此更改,请在上述脚本中使用:$profile.AllUsersAllHosts 而不是 $profile。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯