I have this Powershell V2.0 script that pings every computer on the database server and if it pings succesfully it will return the usernames that are logged on. Now, with my PHP I am displaying the computer names but I need to execute the Powershell script in order to display the usernames. How Can I achieve this?
Working fiddle click on the box it displays the computer name
thanks in advance!
Powershell script:
#call procedure to execute the command
$command.CommandText = "SELECT w.ws FROM
sandbox_maesc4.coordinates c
INNER JOIN
softphone_materials_updater.workstations w
ON c.station_number = w.pod";
#Execute the Command by reading each row
$reader = $command.ExecuteReader();
#Read values from database
$workstation_list = $( while ($reader.Read() ){
$reader.GetValue(0)
})
#close reader
$reader.Close()
#ping each computer if online, obtain information about the local hard drives only
try{
foreach($pc_db in $workstation_list){
if(Test-Connection -ComputerName $pc_db -Count 1 -ErrorAction SilentlyContinue){
$username = Get-WMIObject -ComputerName $pc_db -Class Win32_ComputerSystem | Select-Object Username #-ExpandProperty
#Get-WMIObject -ComputerName $pc_db -Class Win32_ComputerSystem -Property Username
Write-host "$username is logged into $pc_db";
} #end if
else{
Write-Host "$pc_db is Offline" -ForegroundColor Red
}#end else
}#end for each loop
}#end try
catch{
Write-Host "Caught the exception";
Write-Host "$_";
throw $error[0].Exception
}#end catch
$connection.Close()
}#end ping_test function
ping_getUser #execute function
PHP:
<?
//query to show workstation/desks information from DB for the DESKS
$station_sql = "SELECT coordinate_id, section_name, x_coord, y_coord, w.ws, w.pod FROM
sandbox_maesc4.coordinates c
INNER JOIN
softphone_materials_updater.workstations w
ON c.station_number = w.pod";
$station_result = mysqli_query($conn,$station_sql);
//see if query is good
if($station_result === false) {
die(mysqli_error());
}
//display hidden DIV when toggle with information inside
while($row = mysqli_fetch_assoc($station_result)){
//naming values
//coordinates table
$id = $row['coordinate_id'];
$x_pos = $row['x_coord'];
$y_pos = $row['y_coord'];
$sec_name = $row['section_name'];
//workstations table
$workstations = $row['ws'];
$pod = $row['pod'];
//display DIV with the content inside
echo '<div class="station_info_" id="station_info_' . $id . '" style="left:' . $x_pos . 'px;top:' . $y_pos . 'px;"><p class="numb">Section:' . $sec_name . '<br>Station:' . $workstations . '<br>Pod:' . $pod . '</p></div>' . "\n";
}//end while loop for station_result
?>