├── .gitattributes ├── .gitignore ├── LICENSE ├── PSInvoker.sln ├── PSInvoker ├── App.config ├── Costura32 │ └── CommandLine.dll ├── Costura64 │ └── CommandLine.dll ├── FodyWeavers.xml ├── FodyWeavers.xsd ├── Logger.cs ├── Logo.ico ├── Options.cs ├── PSInvoker.csproj ├── Program.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 MSEndpointMgr 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /PSInvoker.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.9.34728.123 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PSInvoker", "PSInvoker\PSInvoker.csproj", "{2283FD77-FFA9-424D-B1CA-9D887B2D283E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {2283FD77-FFA9-424D-B1CA-9D887B2D283E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {2283FD77-FFA9-424D-B1CA-9D887B2D283E}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {2283FD77-FFA9-424D-B1CA-9D887B2D283E}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {2283FD77-FFA9-424D-B1CA-9D887B2D283E}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {1A76C0E2-6DD2-4C68-9299-B72F57283FED} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /PSInvoker/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /PSInvoker/Costura32/CommandLine.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MSEndpointMgr/PSInvoker/89fdc0b01b45dc55135820ed6c90860b711247c7/PSInvoker/Costura32/CommandLine.dll -------------------------------------------------------------------------------- /PSInvoker/Costura64/CommandLine.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MSEndpointMgr/PSInvoker/89fdc0b01b45dc55135820ed6c90860b711247c7/PSInvoker/Costura64/CommandLine.dll -------------------------------------------------------------------------------- /PSInvoker/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | CommandLine 5 | 6 | 7 | CommandLine 8 | 9 | 10 | -------------------------------------------------------------------------------- /PSInvoker/FodyWeavers.xsd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks 13 | 14 | 15 | 16 | 17 | A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks. 18 | 19 | 20 | 21 | 22 | A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks 23 | 24 | 25 | 26 | 27 | A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks. 28 | 29 | 30 | 31 | 32 | A list of unmanaged 32 bit assembly names to include, delimited with line breaks. 33 | 34 | 35 | 36 | 37 | A list of unmanaged 64 bit assembly names to include, delimited with line breaks. 38 | 39 | 40 | 41 | 42 | The order of preloaded assemblies, delimited with line breaks. 43 | 44 | 45 | 46 | 47 | 48 | This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file. 49 | 50 | 51 | 52 | 53 | Controls if .pdbs for reference assemblies are also embedded. 54 | 55 | 56 | 57 | 58 | Controls if runtime assemblies are also embedded. 59 | 60 | 61 | 62 | 63 | Controls whether the runtime assemblies are embedded with their full path or only with their assembly name. 64 | 65 | 66 | 67 | 68 | Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option. 69 | 70 | 71 | 72 | 73 | As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off. 74 | 75 | 76 | 77 | 78 | Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code. 79 | 80 | 81 | 82 | 83 | Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior. 84 | 85 | 86 | 87 | 88 | A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with | 89 | 90 | 91 | 92 | 93 | A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |. 94 | 95 | 96 | 97 | 98 | A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with | 99 | 100 | 101 | 102 | 103 | A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with |. 104 | 105 | 106 | 107 | 108 | A list of unmanaged 32 bit assembly names to include, delimited with |. 109 | 110 | 111 | 112 | 113 | A list of unmanaged 64 bit assembly names to include, delimited with |. 114 | 115 | 116 | 117 | 118 | The order of preloaded assemblies, delimited with |. 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. 127 | 128 | 129 | 130 | 131 | A comma-separated list of error codes that can be safely ignored in assembly verification. 132 | 133 | 134 | 135 | 136 | 'false' to turn off automatic generation of the XML Schema file. 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /PSInvoker/Logger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.IO; 5 | 6 | namespace PSInvoker 7 | { 8 | public static class Logger 9 | { 10 | public static void WriteLogFile(string message) 11 | { 12 | string logPath = Environment.ExpandEnvironmentVariables("%TEMP%\\PSInvoker.log"); 13 | 14 | using (StreamWriter writer = new StreamWriter(logPath, true)) 15 | { 16 | writer.WriteLine($"{DateTime.Now}: {message}"); 17 | } 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /PSInvoker/Logo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MSEndpointMgr/PSInvoker/89fdc0b01b45dc55135820ed6c90860b711247c7/PSInvoker/Logo.ico -------------------------------------------------------------------------------- /PSInvoker/Options.cs: -------------------------------------------------------------------------------- 1 | using CommandLine; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace PSInvoker 5 | { 6 | public sealed class Options 7 | { 8 | [Value(0, Required = true, HelpText = "Input full path to PowerShell script file.")] 9 | public string FilePath { get; set; } 10 | 11 | [Option('e', "ExecutionPolicy", Required = false, HelpText = "Input PowerShell process execution policy.")] 12 | public string ExecutionPolicy { get; set; } 13 | 14 | [Option('w', "Wait", Required = false, HelpText = "Wait until the PowerShell process completes.")] 15 | public bool Wait { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /PSInvoker/PSInvoker.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {2283FD77-FFA9-424D-B1CA-9D887B2D283E} 9 | WinExe 10 | PSInvoker 11 | PSInvoker 12 | v4.7.2 13 | 512 14 | true 15 | true 16 | 17 | 18 | 19 | 20 | AnyCPU 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | 29 | 30 | AnyCPU 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | 38 | 39 | 40 | 41 | 42 | Logo.ico 43 | 44 | 45 | 46 | 47 | ..\packages\CommandLineParser.2.9.1\lib\net461\CommandLine.dll 48 | 49 | 50 | ..\packages\Costura.Fody.5.7.0\lib\netstandard1.0\Costura.dll 51 | 52 | 53 | ..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll 54 | True 55 | True 56 | 57 | 58 | 59 | ..\packages\System.AppContext.4.3.0\lib\net463\System.AppContext.dll 60 | True 61 | True 62 | 63 | 64 | 65 | ..\packages\System.Console.4.3.0\lib\net46\System.Console.dll 66 | True 67 | True 68 | 69 | 70 | 71 | ..\packages\System.Diagnostics.DiagnosticSource.4.3.0\lib\net46\System.Diagnostics.DiagnosticSource.dll 72 | 73 | 74 | ..\packages\System.Diagnostics.Tracing.4.3.0\lib\net462\System.Diagnostics.Tracing.dll 75 | True 76 | True 77 | 78 | 79 | ..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll 80 | True 81 | True 82 | 83 | 84 | ..\packages\System.IO.4.3.0\lib\net462\System.IO.dll 85 | True 86 | True 87 | 88 | 89 | ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll 90 | True 91 | True 92 | 93 | 94 | 95 | ..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll 96 | True 97 | True 98 | 99 | 100 | ..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll 101 | True 102 | True 103 | 104 | 105 | ..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll 106 | True 107 | True 108 | 109 | 110 | ..\packages\System.Linq.4.3.0\lib\net463\System.Linq.dll 111 | True 112 | True 113 | 114 | 115 | ..\packages\System.Linq.Expressions.4.3.0\lib\net463\System.Linq.Expressions.dll 116 | True 117 | True 118 | 119 | 120 | ..\packages\System.Net.Http.4.3.0\lib\net46\System.Net.Http.dll 121 | True 122 | True 123 | 124 | 125 | ..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll 126 | True 127 | True 128 | 129 | 130 | 131 | ..\packages\System.Reflection.4.3.0\lib\net462\System.Reflection.dll 132 | True 133 | True 134 | 135 | 136 | ..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll 137 | True 138 | True 139 | 140 | 141 | ..\packages\System.Runtime.Extensions.4.3.0\lib\net462\System.Runtime.Extensions.dll 142 | True 143 | True 144 | 145 | 146 | ..\packages\System.Runtime.InteropServices.4.3.0\lib\net463\System.Runtime.InteropServices.dll 147 | True 148 | True 149 | 150 | 151 | ..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll 152 | True 153 | True 154 | 155 | 156 | ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net463\System.Security.Cryptography.Algorithms.dll 157 | True 158 | True 159 | 160 | 161 | ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll 162 | True 163 | True 164 | 165 | 166 | ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll 167 | True 168 | True 169 | 170 | 171 | ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll 172 | True 173 | True 174 | 175 | 176 | ..\packages\System.Text.RegularExpressions.4.3.0\lib\net463\System.Text.RegularExpressions.dll 177 | True 178 | True 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | ..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll 187 | True 188 | True 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | False 211 | Microsoft .NET Framework 4.7.2 %28x86 and x64%29 212 | true 213 | 214 | 215 | False 216 | .NET Framework 3.5 SP1 217 | false 218 | 219 | 220 | 221 | 222 | 223 | 224 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 225 | 226 | 227 | 228 | 229 | 230 | 231 | -------------------------------------------------------------------------------- /PSInvoker/Program.cs: -------------------------------------------------------------------------------- 1 | using CommandLine; 2 | using PSInvoker; 3 | using System.Configuration; 4 | using System.Diagnostics; 5 | using System.IO; 6 | using System.Linq; 7 | 8 | 9 | namespace Invoker 10 | { 11 | internal class Program 12 | { 13 | private readonly static string processName = "powershell.exe"; 14 | 15 | static void Main(string[] args) 16 | { 17 | Parser.Default.ParseArguments(args) 18 | .WithParsed(options => 19 | { 20 | Logger.WriteLogFile($"File path argument: {options.FilePath}"); 21 | RunProcess(options); 22 | }) 23 | .WithNotParsed(errors => 24 | { 25 | Logger.WriteLogFile("Provided command line arguments could not be parsed"); 26 | }); 27 | } 28 | 29 | private static void RunProcess(Options commandLine) 30 | { 31 | // Retrieve file path for PowerShell script file passed as argument 32 | string filePath = commandLine.FilePath; 33 | 34 | // Determine execution policy from arguments are valid, if not, fall back to Bypass 35 | string executionPolicy; 36 | string[] exePolicies = new string[] { "AllSigned", "Bypass", "RemoteSigned", "Restricted", "Unrestricted" }; 37 | if (exePolicies.Any(policy => policy == commandLine.ExecutionPolicy)) 38 | { 39 | executionPolicy = commandLine.ExecutionPolicy; 40 | } 41 | else 42 | { 43 | executionPolicy = "Bypass"; 44 | } 45 | 46 | // Verify that the file exists 47 | if (File.Exists(filePath)) 48 | { 49 | Logger.WriteLogFile($"Found script file: {filePath}"); 50 | 51 | // Build arguments based on command line arguments 52 | string arguments = $"-NoProfile -ExecutionPolicy {executionPolicy}" + " -File \"" + filePath + "\""; 53 | Logger.WriteLogFile($"Invoking process command: {processName} {arguments}"); 54 | 55 | // Construct new powershell.exe process for the PowerShell script file 56 | Process process = new Process(); 57 | process.StartInfo.FileName = processName; 58 | process.StartInfo.Arguments = arguments; 59 | process.StartInfo.UseShellExecute = false; 60 | process.StartInfo.RedirectStandardOutput = true; 61 | process.StartInfo.CreateNoWindow = true; 62 | process.Start(); 63 | 64 | Logger.WriteLogFile("Invoked process successfully"); 65 | 66 | if (commandLine.Wait == true) 67 | { 68 | process.WaitForExit(); 69 | Logger.WriteLogFile($"PowerShell process completed with exit code: {process.ExitCode}"); 70 | } 71 | } 72 | else 73 | { 74 | Logger.WriteLogFile($"Invalid file path: {filePath}"); 75 | } 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /PSInvoker/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("PSInvoker")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("MSEndpointMgr")] 12 | [assembly: AssemblyProduct("PSInvoker")] 13 | [assembly: AssemblyCopyright("Copyright © 2024")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("2283fd77-ffa9-424d-b1ca-9d887b2d283e")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.1")] 37 | -------------------------------------------------------------------------------- /PSInvoker/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PSInvoker 2 | 3 | PSInvoker serves as a small utility application to allow for silently running PowerShell scripts without having a flashing window appearing. This comes in handy when administrators would like make use of PowerShell scripts running as scheduled tasks, without dealing a devastating blow to the end-user with annoying windows flashing by. To overcome this behavior, in the past it's been widely known to wrap the invocation of a PowerShell script in a VBScript, however Microsoft is now deprecating VBScript in Windows, leaving us without any non-intrusive way of automating tasks on our endpoints. 4 | 5 | # Usage 6 | 7 | PSInvoker is very simple to use. First of all, either clone this repository and build the executable yourself through e.g. Visual Studio, or download the compiled executable from the Releases section. 8 | For any command line, e.g. in a scheduled task usage scenario, simply call PSInvoker.exe with the proper arguments. 9 | 10 | ## Command line arguments 11 | 12 | PSInvoker supports two command line arguments. The first argument is the full path of the PowerShell script file, e.g. C:\Scripts\Script.ps1. By default, PSInvoker is set to invoke the PowerShell script file using 'Bypass' as the execution policy. This can be overridden by using the -e (--ExecutionPolicy) command line argument, and pass in any of the supported values: AllSigned, Bypass, RemoteSigned, Restricted, Unrestricted. If you're keen on waiting for the PowerShell process to complete executing, use the -w (--Wait) switch. 13 | 14 | ## Examples 15 | ```cmd 16 | > PSInvoker.exe 17 | > PSInvoker.exe -w 18 | > PSInvoker.exe -e RemoteSigned 19 | > PSInvoker.exe --ExecutionPolicy RemoteSigned 20 | > PSInvoker.exe --ExecutionPolicy RemoteSigned --Wait 21 | ``` 22 | 23 | ## Logging 24 | 25 | PSInvoker writes to a log file placed in the %TEMP% folder called PSInvoker.log. 26 | 27 | ## Dependencies 28 | 29 | PSInvoker requires .NET Framework 4.7.2 runtime. 30 | 31 | ## PowerShell support 32 | 33 | It's currently only supported to invoke PowerShell 5.1 processes. 34 | --------------------------------------------------------------------------------