I have tried to create an Active Directory user with SSH commands from a PHP page:
include('Net/SSH2.php');
$path = "OU=HRTest,OU=Israel,OU=Users,OU=Solaredge,DC=solaredge,DC=local";
$name = "Test User2";
$title = "Some Position";
$password = "Welcome!";
$department = "IS";
$POBox = "01/05/2020";
$Company = "SolarEdge Technologies LTD.";
$GivenName = "Test";
$DisplayName = "Test User2";
$SamAccountName = "Test.u2";
$Enabled = "$true";
$server = "MyServerName";
$username = "MyUserName";
$pwd = "MyPassword";
$command = 'powershell New-ADUser -Path "'.$path.'" -Name "'.$name.'" -Title "'.$title.'" -Department "'.$department.'" -POBox "'.$POBox.'" -AccountPassword $("'.$password.'" | ConvertTo-SecureString -AsPlainText -Force) -Company "'.$Company.'" -GivenName "'.$GivenName.'" -DisplayName "'.$DisplayName.'" -SamAccountName "'.$SamAccountName.'" -Enabled '.$Enabled;
$ssh = new Net_SSH2($server);
if (!$ssh->login($username, $pwd)) {
exit('Login Failed');
}
echo $ssh->exec($command);
The SSH connection works, but PowerShell generates this error:
New-ADUser : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Path'. Specified
method is not supported.
At line:1 char:18
+ ... DUser -Path OU=HRTest,OU=Israel,OU=Users,OU=Solaredge,DC=solaredge,DC ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-ADUser], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.ActiveDirectory.Management.Commands.NewADUser
Edit - New error:
'ConvertTo-SecureString' is not recognized as an internal or external command,
operable program or batch file.