无法将值“w”转换为类型“Microsoft.SharePoint.SPFeatureScope”powershell

路易斯瓦伦西亚

我将一个包含 2 个元素的数组传递给我的 powershell 函数,但出现如下错误:

Execute-Safely : Cannot convert value "w" to type "Microsoft.SharePoint.SPFeatureScope". Error: "Invalid cast from 'System.Char' to 'Microsoft.SharePoint.SPFeatureScope'."
At line:71 char:9

这真的很奇怪,在我的代码中找不到错误。

param(
    $vars = @{ 
        "SiteUrl" = "https://hello/"
    }
)

function Upgrade-FeaturesInSite {
    param(
        $site,
        [array]$featureUpgradeOrder
    )


    # Feature to upgrade on site in the specified order
    foreach($featureInfo in $featureUpgradeOrder) {
            $featureName = $featureInfo[0]

        [Microsoft.SharePoint.SPFeatureScope] $featureScope = $featureInfo[1]

        #$featuresToUpgradeInSite = $site.QueryFeatures($featureScope, $true)

        #$featuresToUpgradeInSite.Reset() # reset enumerator for next run
        #$featureToUpgrade = $featuresToUpgradeInSite | ? { $_.Definition.DisplayName -eq $featureName }
        #if($featureToUpgrade -ne $null) {
        #    $featureToUpgrade | % { 
        #        try {
        #            #$_.Upgrade($false)
        #            Write-Host -ForegroundColor Green ("{0}:Feature {1} upgraded successfully, version {2}" -f $_.Parent.ServerRelativeUrl, $featureName, $_.Version)
        #        } catch {
        #            Write-Warning -Message ("{0}:Failed to upgrade feature {1}" -f $_.Parent.ServerRelativeUrl, $featureName)
        #            Write-Warning -Message $_.Exception
        #            Write-Warning -Message ("{0}:Will stop upgrading features on this site" -f $site.ServerRelativeUrl)
        #            return
        #        }
        #    }
        #} else {
        #    $featureDefinition = Get-SPFeature -Identity $featureName
        #    $featureInstance = Invoke-Expression ("Get-SPFeature {0} -{1} {2}" -f $featureDefinition.DisplayName, $featureDefinition.Scope, $site.Url)
        #    Write-Host -ForegroundColor DarkGreen ("{0}:Feature {1} was already up to date, FeatureDefinitionVersion: {2} | FeatureInstanceVersion {3}" -f $site.ServerRelativeUrl,$featureName, $featureDefinition.Version, $featureInstance.Version)
        #}
    }
}

function Execute-Safely {
    param(
        [ScriptBlock]$scriptBlock,
        [string]$action
    )

    try {
        Invoke-Command -ScriptBlock $scriptBlock
    } catch {
        Write-Error ("An error occurred when executing [{0}]" -f $action)
        Write-Error $_
    }

}

$SiteUrl = $vars["SiteUrl"]

$featureUpgradeOrder = @(
    @("awfulfeaturename", [Microsoft.SharePoint.SPFeatureScope]::Web)
)

$site = Get-SPSite $SiteUrl -ErrorAction SilentlyContinue
if($site) {
    try {
        Write-Host "Processing" $site.ServerRelativeUrl

        Execute-Safely -scriptBlock { Upgrade-FeaturesInSite -site $site -featureUpgradeOrder $featureUpgradeOrder } -action "Activating site features"

    } catch {
        Write-Warning ("An error occured while processing web {0}" -f $SiteUrl)
        Write-Warning $_.Exception
    } finally {
        $site.Dispose()
    }
}

对我来说,数组有 2 个项目,一个是功能名称,另一个是功能范围,但似乎有问题

斜角

您的数组数组需要一个逗号。PowerShell 将其转换为单个数组,因此您正在索引字符串而不是您的功能。以下应强制 PowerShell 解释为数组的数组。

$featureUpgradeOrder = @(
    ,@("awfulfeaturename", [Microsoft.SharePoint.SPFeatureScope]::Web)
)

关于数组问题的参考:How to create array of array in powershell?

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

PowerShell-SharePoint 2010-无法找到类型Microsoft.SharePoint

来自分类Dev

PowerShell 5和类-无法将类型“ X”的“ X”值转换为类型“ X”

来自分类Dev

Powershell:无法绑定参数“PercentComplete”。无法将值“GetPercent”转换为类型“System.Int32”

来自分类Dev

C#将Microsoft.Sharepoint.Client.FieldUserValue转换为Microsoft.Sharepoint.Cliend.User

来自分类Dev

从SharePoint的Powershell导入CSV

来自分类Dev

PowerShell:无法将值“ System.Object []”转换为类型“ System.Xml.XmlDocument”

来自分类Dev

SharePoint 网站栏 - 允许在 powershell 脚本中使用多个值

来自分类Dev

使用Powershell将数据从SharePoint文档库提取到CSV

来自分类Dev

Powershell - 无法将“System.Management.Automation.PSCustomObject”类型的值转换为“System.Management.Automation.PSCustomObject”类型

来自分类Dev

Powershell 5:无法将值转换为System.String

来自分类Dev

Powershell正确关闭Sharepoint文档

来自分类Dev

从SharePoint的Powershell导入CSV文件

来自分类Dev

Powershell正确关闭Sharepoint文档

来自分类Dev

比较 PowerShell / SharePoint 列表日期

来自分类Dev

Powershell 和 Sharepoint - 更新列表

来自分类Dev

使用 powershell 安装 Sharepoint 2016

来自分类Dev

此计算机上未安装 PSSnapin Microsoft.Sharepoint.Powershell

来自分类Dev

无法将类型“ System.Reflection.Missing”的“ System.Reflection.Missing”值转换为类型“ System.Int32”。-PowerShell PPT打印

来自分类Dev

如何使用CAML查询(PowerShell)使用户字段类型限制为SharePoint组

来自分类Dev

使用PowerShell和OData API将文件上传到SharePoint 2010

来自分类Dev

使用PowerShell使用元数据将文件上传到SharePoint Online

来自分类Dev

Powershell:使用System.Net.WebClient.UploadFile将文件上传到SharePoint时出现WriteErrorException

来自分类Dev

将SSRS从纯模式转换为SharePoint集成模式

来自分类Dev

sharepoint使用JavaScript将文本输入转换为Select

来自分类Dev

[Powershell / Sharepoint]有人可以查看我的脚本以删除7天以上的Sharepoint列表项吗?获取“无法索引为空数组”

来自分类Dev

使用PowerShell从SharePoint Online下载文件

来自分类Dev

从PowerShell读取Sharepoint List Calculated字段

来自分类Dev

Azure功能:与SharePoint Online交互的PowerShell脚本

来自分类Dev

Azure功能:与SharePoint Online交互的PowerShell脚本

Related 相关文章

  1. 1

    PowerShell-SharePoint 2010-无法找到类型Microsoft.SharePoint

  2. 2

    PowerShell 5和类-无法将类型“ X”的“ X”值转换为类型“ X”

  3. 3

    Powershell:无法绑定参数“PercentComplete”。无法将值“GetPercent”转换为类型“System.Int32”

  4. 4

    C#将Microsoft.Sharepoint.Client.FieldUserValue转换为Microsoft.Sharepoint.Cliend.User

  5. 5

    从SharePoint的Powershell导入CSV

  6. 6

    PowerShell:无法将值“ System.Object []”转换为类型“ System.Xml.XmlDocument”

  7. 7

    SharePoint 网站栏 - 允许在 powershell 脚本中使用多个值

  8. 8

    使用Powershell将数据从SharePoint文档库提取到CSV

  9. 9

    Powershell - 无法将“System.Management.Automation.PSCustomObject”类型的值转换为“System.Management.Automation.PSCustomObject”类型

  10. 10

    Powershell 5:无法将值转换为System.String

  11. 11

    Powershell正确关闭Sharepoint文档

  12. 12

    从SharePoint的Powershell导入CSV文件

  13. 13

    Powershell正确关闭Sharepoint文档

  14. 14

    比较 PowerShell / SharePoint 列表日期

  15. 15

    Powershell 和 Sharepoint - 更新列表

  16. 16

    使用 powershell 安装 Sharepoint 2016

  17. 17

    此计算机上未安装 PSSnapin Microsoft.Sharepoint.Powershell

  18. 18

    无法将类型“ System.Reflection.Missing”的“ System.Reflection.Missing”值转换为类型“ System.Int32”。-PowerShell PPT打印

  19. 19

    如何使用CAML查询(PowerShell)使用户字段类型限制为SharePoint组

  20. 20

    使用PowerShell和OData API将文件上传到SharePoint 2010

  21. 21

    使用PowerShell使用元数据将文件上传到SharePoint Online

  22. 22

    Powershell:使用System.Net.WebClient.UploadFile将文件上传到SharePoint时出现WriteErrorException

  23. 23

    将SSRS从纯模式转换为SharePoint集成模式

  24. 24

    sharepoint使用JavaScript将文本输入转换为Select

  25. 25

    [Powershell / Sharepoint]有人可以查看我的脚本以删除7天以上的Sharepoint列表项吗?获取“无法索引为空数组”

  26. 26

    使用PowerShell从SharePoint Online下载文件

  27. 27

    从PowerShell读取Sharepoint List Calculated字段

  28. 28

    Azure功能:与SharePoint Online交互的PowerShell脚本

  29. 29

    Azure功能:与SharePoint Online交互的PowerShell脚本

热门标签

归档