Share via

How to write to SQL Server using Powershell?

Naomi Nosonovsky 8,906 Reputation points
2024-02-23T21:24:04.1933333+00:00

When I try this script in Windows Powershell I'm getting 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. What am I missing to get it to work? The script is taken directly from https://learn.microsoft.com/en-us/powershell/module/sqlserver/write-sqltabledata?view=sqlserver-ps

(Get-Process | Select-Object -Property Id,ProcessName,StartTime,UserProcessorTime,WorkingSet,Description) |
         Write-SqlTableData -ServerInstance "MyServerName" -DatabaseName "VA_Repository" -SchemaName "dbo" -TableName "TaskManagerDump" -Force
Windows for business | Windows Server | User experience | PowerShell
SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories

0 comments No comments

1 answer

Sort by: Most helpful
  1. Erland Sommarskog 134.3K Reputation points MVP Volunteer Moderator
    2024-02-23T22:37:33.68+00:00

    So did you install the SQL Server Powershell module?

    Then again, you can do the normal ADO .Net stuff with SqlConnection and SqlCommand objects from PowerShell too.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.