Home Forums Programming Powershell Write PowerShell Output to SQL Server Table RE: Write PowerShell Output to SQL Server Table

  • The simplest way is to build up a string to execute:

    $commandText = "INSERT DiskSpace VALUES ('" + $wmiObject.GetValue(0)["SystemName"] + "')"

    $command = $conn.CreateCommand()

    $command.CommandText = $commandText

    $command.ExecuteNonQuery()

    This way is not necessarily ideal as it is a little bit verbose, however, I would recommend building up the text as a separate string because you can always output it to the console before using it in anger:

    Write-Output $commandText

    Just say if you need more or if this is not what you were looking for.

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!