Untitled

mail@pastecode.io avatar
unknown
csharp
a year ago
930 B
11
Indexable
Never
using System;
using System.IO;
using System.Reflection;
using System.Management.Automation;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            // Get the current assembly
            Assembly assembly = Assembly.GetExecutingAssembly();

            // Get the clean.ps1 script as an embedded resource
            Stream stream = assembly.GetManifestResourceStream("cleanscript.clean.ps1");

            // Read the contents of the script
            string script;
            using (StreamReader reader = new StreamReader(stream))
            {
                script = reader.ReadToEnd();
            }

            // Create a PowerShell instance and run the script
            using (PowerShell ps = PowerShell.Create())
            {
                ps.AddScript(script);
                ps.Invoke();
            }
        }
    }
}