【问题标题】:set-spphrase asks for confirmation even if -confirm switch is not used即使未使用 -confirm 开关,set-spphrase 也会要求确认
【发布时间】:2012-08-16 18:45:35
【问题描述】:

我们试图通过 powershell cmdlet 在 sharepoint 中设置密码。

当我们在下一行提到开关 -confirm 时,它要求确认

Set-SPPassPhrase -PassPhrase $passphrase

然后我们删除了 -confirm 开关,因为我们在脚本本身中传递了密码 [虽然这是安全风险,但对于测试环境他们需要它],但它仍然要求确认。是否默认确认?

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$passphrase = ConvertTo-SecureString "MyPass#$#@" -asPlainText –Force 

Set-SPPassPhrase -PassPhrase $passphrase

如何绕过确认?

【问题讨论】:

    标签: powershell sharepoint-2010 powershell-2.0


    【解决方案1】:

    试试这个(无法测试...)

    Set-SPPassPhrase -PassPhrase $passphrase -confirm:$false
    

    【讨论】:

      【解决方案2】:

      Cmdlet 开发人员可以声明其 cmdlet 的影响是低、中还是高。在您的会话中,有一个自动变量$ConfirmPreference,它设置了自动提示您确认的级别,即使您没有通过-Confirm

      大多数 cmdlet 都提供了一个 -Force 开关,它会跳过所有确认,但似乎 Set-SPPassPhrase 没有。您可以尝试显式设置-Confirm:$false

      您也可以尝试设置$ConfirmPreference = 'None'

      http://blogs.msdn.com/b/powershell/archive/2006/12/15/confirmpreference.aspxhttp://msdn.microsoft.com/en-us/library/windows/desktop/bb204629(v=vs.85).aspx

      【讨论】:

        猜你喜欢
        • 2013-05-28
        • 1970-01-01
        • 1970-01-01
        • 2014-02-05
        • 2013-06-22
        • 1970-01-01
        • 2013-08-13
        • 1970-01-01
        • 2011-10-11
        相关资源
        最近更新 更多