本文介绍了使用SharePoint 2013中的PowerShell管理Web应用程序功能下的Fearutes激活的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 $ ErrorActionPreference =" Stop" cls ############################# Feature Names ###### ######################### $ WebApplicationScopedFeature1 =" External Feature1" #Target Web Application $ WebApplicationScopedFeature2 =" External Feature2" #Target Web Application $ WebApplicationScopedFeature3 =" External Feature3" #Target Web Application ############################################## ################################################ $ $ b $ args = new-object string [] 1 $ args [0] =" Cloud" 函数AddPowerShellSnapin() { try { Write-Host"添加PowerShell管理单元' -ForegroundColor Green #尝试获取PowerShell Snappin。如果没有,那么在Catch Block上添加PowerShell snappin Get-PSSnapin" Microsoft.SharePoint.PowerShell" } catch { if($ Error [0] .Exception.Message.Contains(" No Windows PowerShell管理单元匹配模式'Microsoft.SharePoint.PowerShell '被发现')) { Add-PSSnapin" Microsoft.SharePoint.PowerShell" } } 写主机"完成添加PowerShell管理单元" -ForegroundColor Green } 函数ActivateFeature($ DisplayName,$ siteurl) { Write-Host" Activating" $ DisplayName" In Site Collection" $ siteurl $ TempCount =(Get-SPSite $ siteurl |%{Get-SPFeature -Site $ _} | Where-Object {$ _。DisplayName -eq $ DisplayName})。Count if($ TempCount -eq 0) {#如果没有,启用功能。 Get-SPFeature $ DisplayName | Enable-SPFeature -Url $ siteurl } else {#如果已经激活,则取消激活并再次激活。 Disable-SPFeature $ DisplayName -Url $ siteurl -Confirm:$ false Get-SPFeature $ DisplayName | Enable-SPFeature -Url $ siteurl } } 函数ActivateFeatureInWebApplicationScope($ DisplayName,$ siteurl) { Write-Host "激活" $ DisplayName"在Web应用程序中" $ siteurl $ TempCount =(Get-SPWebApplication $ siteurl |%{Get-SPFeature -WebApplication $ _} | Where-Object {$ _.DisplayName -eq $ DisplayName})。Count if($ TempCount -eq 0) {#如果没有,启用功能。 Get-SPFeature $ DisplayName -WebApplication $ siteurl | Enable-SPFeature -Url $ siteurl } else {#如果已经激活,则取消激活并再次激活。 Disable-SPFeature $ DisplayName -Url $ siteurl -Confirm:$ false Get-SPFeature $ DisplayName |启用-SPFeature -Url $ siteurl } } 尝试 { AddPowerShellSnapin #Read争论和商店环境URL if($ args [0] -eq'Cloud') {#$ SiteCollectionURL =" http:// SathishServer:1001 / sites / Test" $ WebApplicationURL =" https://qa-testportal." } elseif($ args [0] -eq'DEV') {#适当地给出URL } elseif ($ args [0] -eq'INT') {#恰当地给出URL } else {写-Host -f Yellow"未指定环境 - 请通过适当的环境进行部署(可能的值为DEV INT QA PROD)" Log-Message $ logFilePath"未指定环境 - 请通过适当的环境进行部署(可能的值为DEV INT QA PROD)" exit } ActivateFeatureInWebApplicationScope $ WebApplicationScopedFeature1 $ WebApplicationURL ActivateFeatureInWebApplicationScope $ WebApplicationScopedFeature2 $ WebApplicationURL ActivateFeatureInWebApplicationScope $ WebApplicationScopedFeature3 $ WebApplicationURL 写主机"脚本执行成功完成" -ForegroundColor Green } catch { Write-Host" Custom Exception Happened on Main:" + $ Error [0] .Exception.Message -ForegroundColor Red } 脚本仅在需要激活所有功能时才有效。 但是如果某些功能已经激活它不检查ELSE部分 else { #如果已经激活,则取消激活并再次激活。 禁用 - SPFeature $ DisplayName - Url $ siteurl - 确认 : $ false 获取 - SPFeature $ DisplayName | 启用 - SPFeature - Url $ siteurl } ex : 1 ) if feature1 = 已经 in active - 脚本应检查 for feature 2 和 激活feature2 2 ) if feature2 = 已经 in active - 脚本应检查 for feature3 和 激活feature3 ... etc 和 显示消息 as feature1 feature activated , feature2已经 in active 请建议 解决方案 由于该功能已经激活,为什么要停用它并再次激活?  运行脚本时,我的环境中会激活所有功能。 祝你好运, Allen Bai $ErrorActionPreference = "Stop" cls ############################# Feature Names ############################### $WebApplicationScopedFeature1 = "External Feature1" #Target Web Application $WebApplicationScopedFeature2 = "External Feature2" #Target Web Application $WebApplicationScopedFeature3 = "External Feature3" #Target Web Application ###################################################################################### $args = new-object string[] 1 $args[0] = "Cloud" function AddPowerShellSnapin() { try { Write-Host "Adding PowerShell Snap-in" -ForegroundColor Green # Try to get the PowerShell Snappin. If not, then adding the PowerShell snappin on the Catch Block Get-PSSnapin "Microsoft.SharePoint.PowerShell" } catch { if($Error[0].Exception.Message.Contains("No Windows PowerShell snap-ins matching the pattern 'Microsoft.SharePoint.PowerShell' were found")) { Add-PSSnapin "Microsoft.SharePoint.PowerShell" } } Write-Host "Finished Adding PowerShell Snap-in" -ForegroundColor Green } function ActivateFeature($DisplayName, $siteurl) { Write-Host "Activating " $DisplayName "In Site Collection " $siteurl $TempCount = (Get-SPSite $siteurl | %{ Get-SPFeature -Site $_ } | Where-Object {$_.DisplayName -eq $DisplayName} ).Count if($TempCount -eq 0) { # if not, Enable the Feature. Get-SPFeature $DisplayName | Enable-SPFeature -Url $siteurl } else { # If already Activated, then De-Activate and Activate Again. Disable-SPFeature $DisplayName -Url $siteurl –Confirm:$false Get-SPFeature $DisplayName | Enable-SPFeature -Url $siteurl } } function ActivateFeatureInWebApplicationScope($DisplayName, $siteurl) { Write-Host "Activating " $DisplayName "In Web Application " $siteurl $TempCount = (Get-SPWebApplication $siteurl | %{ Get-SPFeature -WebApplication $_ } | Where-Object {$_.DisplayName -eq $DisplayName} ).Count if($TempCount -eq 0) { # if not, Enable the Feature. Get-SPFeature $DisplayName -WebApplication $siteurl | Enable-SPFeature -Url $siteurl } else { # If already Activated, then De-Activate and Activate Again. Disable-SPFeature $DisplayName -Url $siteurl –Confirm:$false Get-SPFeature $DisplayName | Enable-SPFeature -Url $siteurl } } try { AddPowerShellSnapin #Read arguement and store environment URL if($args[0] -eq 'Cloud') { #$SiteCollectionURL ="http://SathishServer:1001/sites/Test" $WebApplicationURL ="https://qa-testportal." } elseif($args[0] -eq 'DEV') { # Give the URLs appropriately } elseif ($args[0] -eq 'INT') { # Give the URLs appropriately } else { Write-Host -f Yellow "Environment not specified - please pass appropriate environment to deploy (Possible values are DEV INT QA PROD)" Log-Message $logFilePath "Environment not specified - please pass appropriate environment to deploy (Possible values are DEV INT QA PROD)" exit } ActivateFeatureInWebApplicationScope $WebApplicationScopedFeature1 $WebApplicationURL ActivateFeatureInWebApplicationScope $WebApplicationScopedFeature2 $WebApplicationURL ActivateFeatureInWebApplicationScope $WebApplicationScopedFeature3 $WebApplicationURL Write-Host "Script Execution Completed Successfully" -ForegroundColor Green } catch { Write-Host "Custom Exception Happened on Main : " + $Error[0].Exception.Message -ForegroundColor Red }The Script working only when all features need to activate.But if some features already activated its not checking ELSE part else { # If already Activated, then De-Activate and Activate Again. Disable-SPFeature $DisplayName -Url $siteurl –Confirm:$false Get-SPFeature $DisplayName | Enable-SPFeature -Url $siteurl }ex:1) if feature1=already in active--the script should check for feature 2 and activate feature22) if feature2=already in active--the script should check for feature3 and activate feature3 ...etcand display message as feature1 feature activated, feature2 already in activePlease suggest 解决方案 Hi,Since the feature is already activated, why you want to deactivate it and activate again? When I run your script, all the features are activated in my environment.Best regards,Allen Bai 这篇关于使用SharePoint 2013中的PowerShell管理Web应用程序功能下的Fearutes激活的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 06:46