Exemple #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;
                    }

                    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);
            }
        }
Exemple #2
0
        public override void RunCommand(string rawDeviceList)
        {
            var devlist    = ParseDeviceList(rawDeviceList);
            var failedlist = new List <string>();

            try
            {
                Parallel.ForEach(devlist, (device) =>
                {
                    CancellationToken.Token.ThrowIfCancellationRequested();

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

                    if (FileAndFolderServices.ValidateDirectoryExists(device, CcmCachePath, ActionName, Logger))
                    {
                        FileAndFolderServices.CleanDirectory(device, CcmCachePath, Logger);
                    }

                    if (FileAndFolderServices.ValidateDirectoryExists(device, WindowsTemp, ActionName, Logger))
                    {
                        FileAndFolderServices.CleanDirectory(device, WindowsTemp, Logger);
                    }

                    var userDirPaths = Directory.EnumerateDirectories($"\\\\{device}\\C${UsersDirectory}").ToList();
                    var userFolders  = new List <string>();

                    // Create useable paths
                    foreach (var userDir in userDirPaths)
                    {
                        var cleanedPath = $"{UsersDirectory}\\{userDir.Substring(userDir.LastIndexOf("\\") + 1)}";
                        userFolders.Add(cleanedPath);
                    }

                    foreach (var userFolder in userFolders)
                    {
                        if (FileAndFolderServices.ValidateDirectoryExists(device, userFolder, ActionName, Logger))
                        {
                            // Validate and Clean User Temp Folder at "C:\users\[user]\appdata\local\temp"
                            if (FileAndFolderServices.ValidateDirectoryExists(device, userFolder + UserTemp, ActionName, Logger))
                            {
                                FileAndFolderServices.CleanDirectory(device, userFolder + UserTemp, Logger);
                            }

                            // Validate and Clean User Temporary Internet Files at "C:\Users\[user]\AppData\Local\Microsoft\Windows\Temporary Internet Files"
                            if (FileAndFolderServices.ValidateDirectoryExists(device, userFolder + UserTempInternetFiles, ActionName, Logger))
                            {
                                FileAndFolderServices.CleanDirectory(device, userFolder + UserTempInternetFiles, Logger);
                            }

                            // Validate and Clean User Java Cache Files at "C:\Users\[user]\AppData\Local\Microsoft\Windows\Temporary Internet Files"
                            if (FileAndFolderServices.ValidateDirectoryExists(device, userFolder + JavaCache, ActionName, Logger))
                            {
                                FileAndFolderServices.CleanDirectory(device, userFolder + JavaCache, Logger);
                            }
                        }
                    }
                });
            }
            catch (OperationCanceledException e)
            {
                ResetCancelToken(ActionName, e);
            }

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