2015-10-20 353 views
0

虽然使用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 

From Console - Powershell command

不正常:通过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 

From Visual Studio using WSManConnectionInfo

UPDATE 当我尝试从浏览器中打开网址,我得到401 - Unauthorized预期。 但尽管如此,它仍然是不可能性通过我已经张贴在这里

更新2 我注意到WSManConnectionInfo使用了一些Kerberos身份验证(在这种情况下)并获得成功登录。

可以在C#代码任何人都可以解释我CommandLine和WSManConnectionInfo之间有什么区别,以及为什么我使用一个但不使用另一个成功验证身份?

预先感谢您

+1

为什么我得到一个downvote? –

回答

1

New-PSSession -ComputerName MY-EXCH-SERVER -Credential $null不能在Visual Studio WSManConnectionInfo比较。

New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://MY-EXCH-SERVER/PowerShell/一样。

我也注意到,几乎每个用户(域内)都可以使用我提到的命令访问Exchange Powershell - 但他们的访问受限(例如,他们无法运行“Get-TransportAgent”)。

换句话说,域用户都依赖于他们的Active Directory权限访问Exchange外壳的cmdlet,但通常都可以连接到它