简体   繁体   English

如果没有至少手动登录一次,则无法远程获取计算机的组策略

[英]Unable to get group policy for machine, remotely, without having logged in manually at least once

I have written a C# desktop application, using System.Management.Automation, that remotes over to machines in our network and does diagnostics to make sure that they are all configured per our organization's policies. 我已经使用System.Management.Automation编写了一个C#桌面应用程序,该应用程序可以远程访问我们网络中的计算机,并进行诊断以确保它们均根据组织的策略进行了配置。

PSCredential Credentials = new PSCredential(Username, Password);
WSManConnectionInfo ThisConnection = new WSManConnectionInfo(false, ThisSystem.IpName, 5985, "/wsman",
    "http://schemas.microsoft.com/powershell/Microsoft.PowerShell", Credentials);

using (Runspace ThisRunspace = RunspaceFactory.CreateRunspace(ThisConnection))
{
    ThisRunspace.Open();
    using (PowerShell ThisShell = PowerShell.Create())
    {
        ThisShell.Runspace = ThisRunspace;

To get the banner, which is in the group policy, it does the following code to execute the powershell command 要获取组策略中的标题,它将执行以下代码以执行powershell命令

        ThisShell.Commands.Clear();
        ThisShell.AddScript("echo N | gpupdate /force");
        ThisShell.AddScript("gpresult /h c:\\Windows\\Temp\\gpdata.html /F");
        ThisShell.AddScript("type c:\\Windows\\Temp\\gpdata.html");
        List<String> GroupPolicy = ThisShell.Invoke().Select(x => x.ToString()).ToList();

Which should create that html file with the group policy data for that machine. 哪个应使用该计算机的组策略数据创建该html文件。 And it does, as long as I have manually logged into that machine, with the same credentials. 只要我已经使用相同的凭据手动登录到该计算机,它就可以。 If I have not, I get nothing. 如果没有,我什么也得不到。 I run other powershell commands just like this and get the results just fine, but for some reason this command for getting the group policy will only work for machines where I have logged in manually (using remote desktop) at least once, and with thousands of servers to check, this is not an option. 我像这样运行其他powershell命令并获得了很好的结果,但是由于某种原因,该用于获取组策略的命令仅适用于我手动登录(使用远程桌面)至少一次且有数千次登录的计算机。服务器进行检查,这不是一个选择。

I thought it might be that logging in manually created the home folder for the admin account I am using, but that can't be because I am getting the results of other powershell commands that I piped to files. 我认为可能是登录时为我正在使用的admin帐户手动创建了主文件夹,但这不能是因为我正在获取通过管道传输到文件的其他powershell命令的结果。 I thought it might be that logging in manually updated the group policy on that machine, but that also cannot be, I think, because I added the gpupdate /force , and it made no difference. 我认为可能是在该计算机上手动更新了组策略,但是我认为那也不可能,因为我添加了gpupdate /force ,这没有什么区别。

Any clues? 有什么线索吗?

From the documentation for gpresult : gpresult文档中

Because you can apply overlapping policy settings to any computer or user, the Group Policy feature generates a resulting set of policy settings when the user logs on. gpresult displays the resulting set of policy settings that were enforced on the computer for the specified user when the user logged on.

Since you are talking about enforcing policy on servers, which should not be expected to normally have a user logged in, perhaps you can try adding the /scope computer option to get just the machine policies, which should always be available. 由于您正在谈论在服务器上强制执行策略,通常不应期望该策略使用户登录,因此您可以尝试添加/scope computer选项以仅获取机器策略,该策略应始终可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 确保 Polly 策略至少运行一次 - Ensure Polly Policy Runs at Least Once .NET组策略\\机器文件夹 - .NET Group Policy\Machine folder 如何将ASP.NET应用程序部署到生产计算机,而无需手动更改数据库连接字符串 - How to deploy ASP.NET application to production machine without having to change DB connection string manually 如何使用远程计算机上的状态登录用户 - how to get logged on users with their status on remote machine 如何获取用户登录的计算机的主机名? - How to get hostname of the machine that the user logged in on? .NET MAUI CarouselView 更改 position 不至少滑动一次就不起作用 - .NET MAUI CarouselView changing position is not working without swiping at least once 在目标计算机上运行脚本而不在该计算机上安装SQL Server - Running a script on a target machine without having SQL server installed on that machine 当一组中至少有一个射弹击中目标时,如何每组只调用一次函数? - When at least one projectile out of a group hits the target, how to call a function only once per group? 从Web应用程序获取Windows客户端计算机的登录用户权限 - Get logged in user privileges of a windows client machine from a web application 如何获取登录用户名的客户端计算机 - How can i get the Logged in user Name of Client machine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM