Пример #1
0
        protected override void ProcessRecord()
        {
            Functions.CheckAdmin();

            if (!string.IsNullOrEmpty(ImportFilePath))
            {
                Class.GPO.GroupPolicy groupPolicy = DataSerializer.Deserialize <Class.GPO.GroupPolicy>(ImportFilePath);

                if (!string.IsNullOrEmpty(TargetPolFile))
                {
                    if (groupPolicy.Machine != null && groupPolicy.Machine.Count > 0)
                    {
                        Class.GPO.PolFile pol = new Class.GPO.PolFile();
                        foreach (Class.GPO.GroupPolicyObject gpo in groupPolicy.Machine)
                        {
                            pol.Entries[gpo.Path + "\\" + gpo.Name] = gpo.ConvertToPolEntry();
                        }
                        if (!Directory.Exists(Path.GetDirectoryName(TargetPolFile)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(TargetPolFile));
                        }
                        pol.Save(TargetPolFile);
                    }
                }
                else
                {
                    if (!IgnoreMachine && groupPolicy.Machine != null && groupPolicy.Machine.Count > 0)
                    {
                        Class.GPO.PolFile pol = new Class.GPO.PolFile();
                        foreach (Class.GPO.GroupPolicyObject gpo in groupPolicy.Machine)
                        {
                            pol.Entries[gpo.Path + "\\" + gpo.Name] = gpo.ConvertToPolEntry();
                        }
                        if (!Directory.Exists(Path.GetDirectoryName(Class.GPO.Item.MACHINE_POL_PATH)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(Class.GPO.Item.MACHINE_POL_PATH));
                        }
                        pol.Save(Class.GPO.Item.MACHINE_POL_PATH);
                    }
                    if (!IgnoreUser && groupPolicy.User != null && groupPolicy.User.Count > 0)
                    {
                        Class.GPO.PolFile pol = new Class.GPO.PolFile();
                        foreach (Class.GPO.GroupPolicyObject gpo in groupPolicy.User)
                        {
                            pol.Entries[gpo.Path + "\\" + gpo.Name] = gpo.ConvertToPolEntry();
                        }
                        if (!Directory.Exists(Path.GetDirectoryName(Class.GPO.Item.USER_POL_PATH)))
                        {
                            Directory.CreateDirectory(Path.GetDirectoryName(Class.GPO.Item.USER_POL_PATH));
                        }
                        pol.Save(Class.GPO.Item.USER_POL_PATH);
                    }
                }
            }
        }
Пример #2
0
        protected override void ProcessRecord()
        {
            var gp = new Class.GPO.GroupPolicy();

            if (!string.IsNullOrEmpty(TargetPolFile))
            {
                //  指定したファイルを「コンピュータの構成」として取得
                if (File.Exists(TargetPolFile))
                {
                    gp.SetMachine(Class.GPO.PolFile.Create(TargetPolFile));
                }
            }
            else
            {
                //  「コンピュータの構成」を取得
                if (!IgnoreMachine && File.Exists(Class.GPO.Item.MACHINE_POL_PATH))
                {
                    gp.SetMachine(Class.GPO.PolFile.Create(Class.GPO.Item.MACHINE_POL_PATH));
                }

                //  「ユーザーの構成」を取得
                if (!IgnoreUser && File.Exists(Class.GPO.Item.USER_POL_PATH))
                {
                    gp.SetUser(Class.GPO.PolFile.Create(Class.GPO.Item.USER_POL_PATH));
                }
            }

            if (string.IsNullOrEmpty(ExportFilePath))
            {
                WriteObject(gp);
            }
            else
            {
                DataSerializer.Serialize <Class.GPO.GroupPolicy>(gp, ExportFilePath);
            }
        }
Пример #3
0
        protected override void ProcessRecord()
        {
            if ((this.GroupPolicyObject == null || this.GroupPolicyObject.Length == 0) &&
                !string.IsNullOrEmpty(RegistryPath) &&
                !string.IsNullOrEmpty(RegistryName) &&
                !string.IsNullOrEmpty(RegistryType) &&
                !string.IsNullOrEmpty(RegistryValue))
            {
                this.GroupPolicyObject = new Class.GPO.GroupPolicyObject[1]
                {
                    new Class.GPO.GroupPolicyObject()
                    {
                        Path  = RegistryPath,
                        Name  = RegistryName,
                        Type  = RegistryType,
                        Value = RegistryValue,
                    }
                };
            }

            Class.GPO.GroupPolicy gp = new Class.GPO.GroupPolicy();

            Func <List <Class.GPO.GroupPolicyObject>, bool> checkContain = (gpoList) =>
            {
                if (gpoList.Count > 0)
                {
                    bool result = true;
                    foreach (Class.GPO.GroupPolicyObject paramGPO in this.GroupPolicyObject)
                    {
                        result &= gpoList.Any(x =>
                                              x.Path.Equals(paramGPO.Path, StringComparison.OrdinalIgnoreCase) &&
                                              x.Name.Equals(paramGPO.Name, StringComparison.OrdinalIgnoreCase) &&
                                              x.Value == paramGPO.Value &&
                                              x.Type == paramGPO.Type);
                    }
                    return(result);
                }
                else
                {
                    return(false);
                }
            };

            if (!string.IsNullOrEmpty(TargetPolFile))
            {
                if (File.Exists(TargetPolFile))
                {
                    gp.SetMachine(Class.GPO.PolFile.Create(TargetPolFile));
                    WriteObject(checkContain(gp.Machine));
                }
            }
            else if (Machine)
            {
                if (File.Exists(Class.GPO.Item.MACHINE_POL_PATH))
                {
                    gp.SetMachine(Class.GPO.PolFile.Create(Class.GPO.Item.MACHINE_POL_PATH));
                    WriteObject(checkContain(gp.Machine));
                }
            }
            else if (User)
            {
                if (File.Exists(Class.GPO.Item.USER_POL_PATH))
                {
                    gp.SetUser(Class.GPO.PolFile.Create(Class.GPO.Item.USER_POL_PATH));
                    WriteObject(checkContain(gp.User));
                }
            }
        }
Пример #4
0
        protected override void ProcessRecord()
        {
            Class.GPO.GroupPolicy gp = new Class.GPO.GroupPolicy();

            Action <List <Class.GPO.GroupPolicyObject> > returnObject = (gpoList) =>
            {
                var cmdletList = new List <string>();

                if (ToSetCmdlet)
                {
                    foreach (Class.GPO.GroupPolicyObject gpo in gpoList)
                    {
                        cmdletList.Add(string.Format(
                                           "Set-LocalGPO -Path \"{0}\" -Name \"{1}\" -Value {2} -Type {3}",
                                           gpo.Path,
                                           gpo.Name,
                                           (gpo.Type == Class.GPO.RegistryControl.REG_DWORD || gpo.Type == Class.GPO.RegistryControl.REG_QWORD) ? gpo.Value : "\"" + gpo.Value + "\"",
                                           gpo.Type));
                    }
                    WriteObject(string.Join("\r\n", cmdletList));
                }
                else if (ToNewCmdlet)
                {
                    foreach (Class.GPO.GroupPolicyObject gpo in gpoList)
                    {
                        cmdletList.Add(string.Format(
                                           "New-LocalGPO -Path \"{0}\" -Name \"{1}\" -Value {2} -Type {3}",
                                           gpo.Path,
                                           gpo.Name,
                                           (gpo.Type == Class.GPO.RegistryControl.REG_DWORD || gpo.Type == Class.GPO.RegistryControl.REG_QWORD) ?
                                           gpo.Value :
                                           "\"" + gpo.Value + "\"",
                                           gpo.Type));
                    }
                    WriteObject(string.Join("\r\n", cmdletList));
                }
                else
                {
                    WriteObject(gpoList.ToArray());
                }
            };

            if (!string.IsNullOrEmpty(TargetPolFile))
            {
                //  指定のPolファイルから読み込み
                if (File.Exists(TargetPolFile))
                {
                    gp.SetMachine(Class.GPO.PolFile.Create(TargetPolFile));
                    returnObject(gp.Machine);
                }
            }
            else if (Machine)
            {
                //  コンピュータの構成
                if (File.Exists(Class.GPO.Item.MACHINE_POL_PATH))
                {
                    gp.SetMachine(Class.GPO.PolFile.Create(Class.GPO.Item.MACHINE_POL_PATH));
                    returnObject(gp.Machine);
                }
            }
            else if (User)
            {
                //  ユーザーの構成
                if (File.Exists(Class.GPO.Item.USER_POL_PATH))
                {
                    gp.SetUser(Class.GPO.PolFile.Create(Class.GPO.Item.USER_POL_PATH));
                    returnObject(gp.User);
                }
            }
        }