How can I execute PowerShell commands using MSBuild?
You can execute PowerShell commands via MSBuild by leveraging the 'Inline Tasks' feature in .NET Framework 4.0. The trick is to craft an XML file that defines a task using the `CodeTaskFactory` and includes C# code that calls PowerShell. Casey Smith provided a public POC that converts C# invocations into an XML format executable by `msbuild.exe`, as detailed in the article Use MSBuild To Do More. This technique bypasses application whitelisting because MSBuild is a trusted Microsoft binary.
MSBuildInline TasksCodeTaskFactoryPowerShellAppLocker bypass
Source:Use MSBuild To Do More