• Thanks for your reply.
    I wrote the following script:
    $server = get-content "C:\Users\sql_dba_test\Desktop\servers.txt"
    Foreach ($s in $server)
    {

    Invoke-Sqlcmd -Query "
    SELECT host_name,COUNT(*) AS [Connections]
    FROM sys.dm_exec_sessions
    WHERE database_id > 0
    GROUP BY host_name;" | 
    Write-SqlTableData -ServerInstance "HQ-SQLDEVAPP00\DB06" -DatabaseName "SQL_App_Repository" -SchemaName "dbo" -TableName "sql_sessions" -Force
     
    }

    But I am getting the following error:
    "Write-SqlTableData : The term 'Write-SqlTableData' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again"

    Is there something I need to install first?