首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当作为登录脚本运行时,PowerShell中的cmdkey不工作吗?

当作为登录脚本运行时,PowerShell中的cmdkey不工作吗?
EN

Stack Overflow用户
提问于 2014-08-19 12:45:06
回答 3查看 7.2K关注 0票数 5

尝试在PowerShell登录脚本中使用cmdkey在凭据管理器中存储凭据。当脚本从PowerShell运行时,一切都正常,但是当它作为登录脚本通过组策略运行时,一切都正常。我无法理解为什么cmdkey会在任何地方工作,除非脚本在登录时运行。

代码语言:javascript
复制
# Checks if CRM for Outlook is isntalled by checking the folder path
$installed = Test-Path "C:\Program Files (x86)\Microsoft Dynamics CRM"
# Checks if the CRM has already been configured using the CoreConfigured registry entry
$configured = Get-ItemProperty -Path HKCU:\software\Microsoft\MSCRMClient -Name     "CoreConfigured"

# If CRM is installed and not configured, configure it, if CRM is not installed or     installed and configured, exit
If ($installed -eq "True" -and $configured.CoreConfigured -ne 1) { 

    $message1 = New-object -ComObject Wscript.Shell
    $message1.Popup("Preparing to configure Microsoft CRM for Outlook, please make sure     Outlook is closed.",10,"Systems")

    # Prompts user for email address and Password to configure CRM for Outlook
    $c = Get-Credential -Message "To confgiure CRM, please enter your email address and password:"

    # puts user credentials into Windows Credential Manager using required CRM URLs 
    cmdkey /generic:Microsoft_CRM_https://disco.crm.dynamics.com/ /user: $c.Username  /pass: $c.Password | Out-Null
    cmdkey /generic:Microsoft_CRM_https://disco.crm4.dynamics.com/ /user: $c.Username /pass: $c.Password | Out-Null


    $message2 = New-Object -ComObject Wscript.Shell
    $message2.Popup("Please wait, a notification will appear when the configuration is complete.",10,"Systems")

    # Silenty runs the CRM configuration Wizard with custom XML file
    $exe = "C:\Program Files (x86)\Microsoft Dynamics CRM\Client\ConfigWizard\Microsoft.Crm.Application.Outlook.ConfigWizard.exe"
   &$exe -p /Q /i 'C:\Program Files (x86)\Microsoft Dynamics CRM\Default_Client_Config.xml' /xa /l 'c:\temp\crminstall.txt' | Out-Null

    $message3 = New-Object -ComObject Wscript.Shell
    $message3.Popup("Configuration complete! You may now open Outlook!",10,"Systems")

} 
else {
    exit    
}
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-09-01 03:14:28

我猜想cmdkey正在使用Microsoft的数据保护API (DPAPI)加密凭据,因此只有当前用户才能检索它们。除非加载了用户的会话,否则不能使用此API。当您的脚本运行时,在登录过程中加载DPAPI所需的安全信息可能为时尚早。我不确定登录脚本是如何工作的,但是尝试在登录脚本中添加一个延迟,直到您得到一个值。

下面是使用DPAPI加密的PowerShell代码:

代码语言:javascript
复制
$scope = [Security.Cryptography.DataProtectionScope]::CurrentUser
$encryptedBytes = [Security.Cryptography.ProtectedData]::Protect( $plainBytes, $null, $scope )
$decryptedBytes = [Security.Cryptography.ProtectedData]::Unprotect( $encryptedBytes, $null, 0 )

在logn脚本中添加一个循环,该循环试图加密/解密一些随机字节数组,直到成功为止。

票数 1
EN

Stack Overflow用户

发布于 2016-06-23 12:40:33

我也有同样的问题:在作为用户登录脚本运行时,cmdkey没有在Powershell中工作。

在我的例子中,这个问题与用户的组成员身份有关。用户是“超级用户”组的成员,但是“用户”组(或任何其他组)的成员。

这篇文章来自微软称,“超级用户”组没有“默认用户权限”,而组“用户”有权“执行常见任务,如使用本地和网络打印机运行应用程序”。

解决方案是将我的用户添加到“用户”组中。这立即解决了问题,并允许cmdkey在Powershell登录脚本中工作。

票数 1
EN

Stack Overflow用户

发布于 2017-08-01 17:38:10

在调用PowerShell GPO登录脚本cmdkey.exe时,我也遇到了同样的问题。凭据填充到用户的凭据管理器中,但管理员没有显示凭据。我发现凭据保存在凭据管理器中,但用于提升的用户。如果在提升的命令提示符中运行cmdkey /list,您将在其中看到凭据。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25383773

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档