虽然使用PowerShell运行空间和WSManConnectionInfo在C#开发我从测试的PowerShell命令窗口相同的连接(具有相同的域用户)时,注意到一些奇怪的行为。远程交流PowerShell中使用WSManConnectionInfo或命令窗口(安全)
OK:远程PowerShell使用命令行窗口(用户未经许可)(未能如预期)
# Connecting to a Remote powershell using non authorized domain user.
New-PSSession -ComputerName MY-EXCH-SERVER -Credential $null
New-PSSession : [MY-EXCH-SERVER] Connecting to remote server MY-EXCH-SERVER failed with the following error message :
Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:1
不正常:通过WSManConnectionInfo从VS2015使用相同的用户远程PowerShell连接像以前(成功,但它不应该,因为它的同一个用户)
// When I do the below with the SAME user I am using in Powershell cmd window
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(
new Uri("http://MY-EXCH-SERVER/PowerShell/"),
"http://schemas.microsoft.com/powershell/Microsoft.Exchange",
PSCredential.Empty
);
connectionInfo.SkipCACheck = true; // can be ignored
connectionInfo.SkipCNCheck = true; // can also be ignored
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Default;
this.currentRunspace = RunspaceFactory.CreateRunspace(connectionInfo);
this.currentRunspace.Open();
[...]
// The connection is established, but the user does not have access actually
UPDATE 当我尝试从浏览器中打开网址,我得到401 - Unauthorized
预期。 但尽管如此,它仍然是不可能性通过我已经张贴在这里
更新2 我注意到WSManConnectionInfo
使用了一些Kerberos身份验证(在这种情况下)并获得成功登录。
可以在C#代码任何人都可以解释我CommandLine和WSManConnectionInfo之间有什么区别,以及为什么我使用一个但不使用另一个成功验证身份?
预先感谢您
为什么我得到一个downvote? –