w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Powershell - Insert into MySQL database table errors?

I see two things. first, this line:

$username = Get-WMIObject -ComputerName $workstation -Class
Win32_ComputerSystem | Select-Object Username #-ExpandProperty

Should probably be this:

$username = Get-WMIObject -ComputerName $workstation -Class
Win32_ComputerSystem | Select-Object -ExpandProperty Username 

Second, you didn't use any quotes when embedding the username variable in the SQL String. Try this. I quoted all three values since I don't know what types the other columns are.

$command.CommandText = "INSERT INTO workstation_userlogged
                                    (username,hostname,online)
                                    VALUES
('$username','$pc_db','$ping_status')";




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.