使用cmdkey发出问题 [英] Issue using cmdkey

查看:98
本文介绍了使用cmdkey发出问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是域名管理员。我使用20个域并且必须RDP登录到其中任何一个服务器。我通常只获取使用的主机名而不是FQDN。使用RDP管理器仍然效率低下,更不用说烦人了。

I am a Domain Admin. I work with 20 domains and have to RDP login to servers on any of them. I usually only get the hostname to work with rather than an FQDN. Using an RDP manager was still inefficient, not to mention annoying.




所以我写了一个基于GUI的PowerShell执行以下操作的脚本。

So I wrote a GUI based powershell script that does the following.

1。在给定主机名的情况下查找FQDN。 [写了一个自定义函数来从任何输入返回FQDN]

1. Finds FQDN given a hostname. [wrote a custom function to return FQDN from any input]

2。基于FQDN创建PScredential对象(使用以加密形式存储的磁盘上保存的凭据)[写了一个自定义函数来执行此操作]

2. Creates a PScredential object based on the FQDN (Using saved credential on disk stored in encrypted form) [Wrote a custom function to do that too]

3。使用cmdkey创建mstsc缓存凭证并启动RDP。

3. Uses cmdkey to create an mstsc cached credential and launch RDP.

我面临的问题如下。在某些服务器(并非所有服务器)上,在法律通知窗口上单击"确定"后,配置文件开始加载,然后我收到此提示。当我点击确定时,它会将我注销。我不知道如何绕过它。根据我的研究
到目前为止,这是因为我试图通过我的MSTSC请求传递可选参数。但是我没有看到它是如何发生的,因为我没有为它编码。这是我需要帮助的地方。如何抑制/避免/解决它。

The issue I face is below. On some servers (not all of them), after clicking OK on the legal notice window, the profile starts loading and then I get this prompt. When I click ok, it logs me off. I dont know how to get around it. According to my research so far, this is caused because I am trying to pass optional parameters through my MSTSC request. But I don't see how it happens as i have not coded for it. This is where I need help. How to suppress/avoid/work-around it.

 

----------------------- ---------------------------------------------错误味精--- -------------------------------------------

访问被拒绝。

无法启动此初始程序:

C:\ Windows\syswow64 \ WindowsPowershell\v1.0\powershell.exe -version 2 -command" $ {Set-ExecutionPolicy -ExecutionPolicy RemoteSigned}"

请参阅帮助以获取更多信息。

------------------------------ --------------------------------------错误味精结束--------- ----------- ----------------------



[GUI基本上收集主机名并调用下面的函数]。它很直接。

[The GUI basically collects the Hostname and calls the function below]. Its pretty straight forward.

<#
.Synopsis
   Short description
.DESCRIPTION
   Long description
.EXAMPLE
   Example of how to use this cmdlet
.EXAMPLE
   Another example of how to use this cmdlet
#>
function Get-AutoRDP
{
    [CmdletBinding()]
    [OutputType([int])]
    Param
    (
        # Param1 help description
        [Parameter(Mandatory=$true,
                   ValueFromPipelineByPropertyName=$true,
                   Position=0)]
        $Server
    )

    Begin
    {
        $Server = $Server.ToString().Trim()
        Import-Module .\Get-FQDN.ps1 -Force
        Import-Module .\Get-PSCredential.ps1 -Force
        $FQDN = Get-FQDN -Server $Server #This is a custom function that returns an FQDN.
    }
    Process
    {
        $PSCredential = Get-PSCredential -FQDN $FQDN #This is a custom function that returns a PScredential object.
        $DomainUser = $PSCredential.UserName
        $PlainPassword = $PSCredential.GetNetworkCredential().Password
        
        #Creating cached Creds
        cmdkey.exe /add:$FQDN /user:$DomainUser /pass:$PlainPassword 1>$cmdkey
        mstsc /v:"$FQDN" /w:1200 /h:768
    }
    End
    {
    }
}

推荐答案

您不能在脚本中使用Set-ExecutionPolicy。 从管理员提示中设置一次,它将被记住。

You cannot use Set-ExecutionPolicy in a script.  Set it once from an admin prompt and it will be remembered.

您不需要在每个连接上执行CmdKey。 只需设置一次。 检查CmdKey以获取凭证,以便在信用证存在时跳过它。

You do not need to execute CmdKey on every connection.  Just set it once.  Check CmdKey for the credential so you can skip it when the cred exisits.


这篇关于使用cmdkey发出问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆