Exemplo n.º 1
0
        public override void RunCommand(string rawDeviceList)
        {
            var devlist    = ParseDeviceList(rawDeviceList);
            var failedlist = new List <string>();

            try
            {
                foreach (var device in devlist)
                {
                    CancellationToken.Token.ThrowIfCancellationRequested();

                    if (!NetworkServices.VerifyDeviceConnectivity(device))
                    {
                        failedlist.Add(device);
                        ResultConsole.Instance.AddConsoleLine($"Device {device} failed connection verification. Added to failed list.");
                        continue;
                    }

                    _psExecServices.RunOnDeviceWithoutAuthentication(device, "cmd.exe /C echo n | gpupdate.exe /force");
                }
            }
            catch (OperationCanceledException e)
            {
                ResetCancelToken(ActionName, e);
            }

            if (failedlist.Count > 0)
            {
                WriteToFailedLog(ActionName, failedlist);
            }
        }
Exemplo n.º 2
0
        public override void RunCommand(string rawDeviceList)
        {
            var devlist    = ParseDeviceList(rawDeviceList);
            var failedlist = new List <string>();

            try
            {
                foreach (var device in devlist)
                {
                    CancellationToken.Token.ThrowIfCancellationRequested();

                    if (!NetworkServices.VerifyDeviceConnectivity(device))
                    {
                        failedlist.Add(device);
                        ResultConsole.Instance.AddConsoleLine($"Device {device} failed connection verification. Added to failed list.");
                        continue;
                    }

                    if (FileAndFolderServices.ValidateDirectoryExists(device, GpoCacheDir, ActionName, Logger))
                    {
                        var dirtyContents = Directory.EnumerateDirectories($"\\\\{device}\\C${GpoCacheDir}").ToList();
                        var contents      = new List <string>();

                        foreach (var directory in dirtyContents)
                        {
                            var cleanedPath = $"{GpoCacheDir}\\{directory.Substring(directory.LastIndexOf("\\") + 1)}";
                            contents.Add(cleanedPath);
                        }

                        foreach (var dir in contents)
                        {
                            FileAndFolderServices.CleanDirectory(device, dir, Logger);
                        }

                        _psExecServices.RunOnDeviceWithoutAuthentication(device, "cmd.exe /C gpupdate.exe /force");
                    }
                    else
                    {
                        ResultConsole.AddConsoleLine(
                            "Unable to validate the directory for the GPO cache. Please delete manually.");
                    }
                }
            }
            catch (OperationCanceledException e)
            {
                ResetCancelToken(ActionName, e);
            }

            if (failedlist.Count > 0)
            {
                WriteToFailedLog(ActionName, failedlist);
            }
        }