connect C main.exe with powershell

Viewed 55

I'm creating a C program to join several powershell scripts to facilitate their execution.

But before I run the scripts I need to connect with powersheel.

I need to run these commands:

$Session, $Credentials = C:\PowerShell\connect.ps1 | 
Connect-AzureAD -Credential $Credentials |
Import-PSSession $Session -DisableNameChecking |
Set-ADServerSettings -ViewEntireForest $true

I tried to run the powershell command at the beginning of my C program but it opens a new powershell: system("powershell");

How can I connect my main.exe to powershell and then run the commands?

1 Answers

Dear try de following simple example:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main ()
{
   system("start powershell.exe mkdir c://test_2");
   return(0);
}
Related