Hello @Elmata ,
A very simple method is combin HTAs with PowerShell scripts.
While you can't include PowerShell script code directly into your HTA, you can use VBScript to launch external processes.
------------------------
Note:
To run PowerShell scripts from VBScript code, you need to set the execution policy on your computer to enable this activity. For example, Set-ExecutionPolicy Unrestricted enables all PowerShell scripts to run on your system.
----------------------
More information, please refer to this article:
Thanks,
Echo Du
======================
Updated Answer ======================
Hi @Elmata ,
You could create a Custom Web Part. A simple button Handler could execute the under given code to fire your PowerShell script.
private string RunScript(string scriptText)
{
// create Powershell runspace
Runspace runspace = RunspaceFactory.CreateRunspace();
// open it
runspace.Open();
// create a pipeline and feed it the script text
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(scriptText);
// add an extra command to transform the script
// output objects into nicely formatted strings
// remove this line to get the actual objects
// that the script returns. For example, the script
// "Get-Process" returns a collection
// of System.Diagnostics.Process instances.
pipeline.Commands.Add("Out-String");
// execute the script
Collection<psobject /> results = pipeline.Invoke();
// close the runspace
runspace.Close();
// convert the script result into a single string
StringBuilder stringBuilder = new StringBuilder();
foreach (PSObject obj in results)
{
stringBuilder.AppendLine(obj.ToString());
}
return stringBuilder.ToString();
}
Note:
The scriptText parameter is the script which you should pass. You can HardCode it or load it from any file
Script Reference
Thanks,
Echo Du
=====================
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.