PHP calling powershell with variables

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
Simon771
New php-forum User
New php-forum User
Posts: 2
Joined: Wed Mar 14, 2018 4:17 am

Tue Mar 20, 2018 4:58 am

I'm in need of local website, that would allow me to unlock and/or reset user password from certain domain. I have made script that is working great in powershell, but need to put it on website, so user operator can select domain, type in username and new password to be set.

I have no idea how to pass variables from PHP to powershell and execute it.

Powershell script:

Code: Select all

$user = Read-Host "User:"

$output = (Get-ADUser $user -Properties * |Select-Object LockedOut).lockedout

if($output -like "False")
{Write-Host -ForegroundColor Green "User not locked!"

$Action2 = Read-Host "RESET PASSWORD ? y/n :"

if($Action2 -like "y")
{
$password = Read-Host "New Password:" -AsSecureString

Set-ADAccountPassword $user -NewPassword $password -Reset

pause -t 30
exit
}
if ($action2 -like "n")
{
pause -t 30
exit
}}

if($output -like "True")
{Write-Host -ForegroundColor Red "User is locked!!!"

$Action = Read-Host "Unlock it? y/n :"

if($Action -like "y")
{
Unlock-ADAccount $user
write-host -ForegroundColor Green "User in unlocked ... do you want to change password?"

$Action = Read-Host "Change password ? y/n :"

if($Action -like "y")
{
$password = Read-Host "New Password" -AsSecureString

Set-ADAccountPassword $user -NewPassword $password -Reset
}
pause -t 30
exit
}}

Post Reply