示例#1
0
        internal void CompareTwoPolicies(PowerShellPolicies a, PowerShellPolicies b)
        {
            // Compare 'ScriptExecution' settings
            CompareScriptExecution(a.ScriptExecution, b.ScriptExecution);

            // Compare 'ScriptBlockLogging' settings
            CompareScriptBlockLogging(a.ScriptBlockLogging, b.ScriptBlockLogging);

            // Compare 'ModuleLogging' settings
            CompareModuleLogging(a.ModuleLogging, b.ModuleLogging);

            // Compare 'ProtectedEventLogging' settings
            CompareProtectedEventLogging(a.ProtectedEventLogging, b.ProtectedEventLogging);

            // Compare 'Transcription' settings
            CompareTranscription(a.Transcription, b.Transcription);

            // Compare 'UpdatableHelp' settings
            CompareUpdatableHelp(a.UpdatableHelp, b.UpdatableHelp);

            // Compare 'ConsoleSessionConfiguration' settings
            CompareConsoleSessionConfiguration(a.ConsoleSessionConfiguration, b.ConsoleSessionConfiguration);
        }
示例#2
0
        public PowerShellPolicyFixture()
        {
            systemWideConfigDirectory  = Utils.DefaultPowerShellAppBase;
            currentUserConfigDirectory = Platform.ConfigDirectory;

            if (!Directory.Exists(currentUserConfigDirectory))
            {
                // Create the CurrentUser config directory if it doesn't exist
                Directory.CreateDirectory(currentUserConfigDirectory);
            }

            systemWideConfigFile  = Path.Combine(systemWideConfigDirectory, ConfigFileName);
            currentUserConfigFile = Path.Combine(currentUserConfigDirectory, ConfigFileName);

            if (File.Exists(systemWideConfigFile))
            {
                systemWideConfigBackupFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
                File.Move(systemWideConfigFile, systemWideConfigBackupFile);
            }

            if (File.Exists(currentUserConfigFile))
            {
                currentUserConfigBackupFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
                File.Move(currentUserConfigFile, currentUserConfigBackupFile);
            }

            var settings = new JsonSerializerSettings()
            {
                TypeNameHandling  = TypeNameHandling.None,
                MaxDepth          = 10,
                Formatting        = Formatting.Indented,
                NullValueHandling = NullValueHandling.Ignore
            };

            serializer = JsonSerializer.Create(settings);

            systemWidePolicies = new PowerShellPolicies()
            {
                ScriptExecution = new ScriptExecution()
                {
                    ExecutionPolicy = "RemoteSigned", EnableScripts = true
                },
                ScriptBlockLogging = new ScriptBlockLogging()
                {
                    EnableScriptBlockInvocationLogging = true, EnableScriptBlockLogging = false
                },
                ModuleLogging = new ModuleLogging()
                {
                    EnableModuleLogging = false, ModuleNames = new string[] { "PSReadline", "PowerShellGet" }
                },
                ProtectedEventLogging = new ProtectedEventLogging()
                {
                    EnableProtectedEventLogging = false, EncryptionCertificate = new string[] { "Joe" }
                },
                Transcription = new Transcription()
                {
                    EnableInvocationHeader = true, EnableTranscripting = true, OutputDirectory = @"c:\tmp"
                },
                UpdatableHelp = new UpdatableHelp()
                {
                    DefaultSourcePath = @"f:\temp"
                },
                ConsoleSessionConfiguration = new ConsoleSessionConfiguration()
                {
                    EnableConsoleSessionConfiguration = true, ConsoleSessionConfigurationName = "name"
                }
            };

            currentUserPolicies = new PowerShellPolicies()
            {
                ScriptExecution = new ScriptExecution()
                {
                    ExecutionPolicy = "RemoteSigned"
                },
                ScriptBlockLogging = new ScriptBlockLogging()
                {
                    EnableScriptBlockLogging = false
                },
                ModuleLogging = new ModuleLogging()
                {
                    EnableModuleLogging = false
                },
                ProtectedEventLogging = new ProtectedEventLogging()
                {
                    EncryptionCertificate = new string[] { "Joe" }
                }
            };

            // Set the test hook to disable policy caching
            originalTestHookValue = InternalTestHooks.BypassGroupPolicyCaching;
            InternalTestHooks.BypassGroupPolicyCaching = true;
        }