July 29, 2019 at 8:40 pm
Below is my sample powershell code. Can i take output of an array and insert into a table in sql server.
cls
$filepath='C:\Temp\Backup'
#Get-ChildItem -path $filepath -Recurse -Include *.bak
#$allfiles=@(Get-ChildItem -path $filepath -Recurse -Include *.bak | select name,length ,lastwritetime )
$allfiles=@(Get-ChildItem -path $filepath -Recurse -Include *.bak | sort LastWriteTime -Descending | select name,length ,lastwritetime | select -First 2 )
$allfiles
July 29, 2019 at 9:24 pm
A few different ways. One quick way using the SQLServer module is to just add a Write-SqlTableData cmdlet at the end of the script you started:
Write-SqlTableData -serverInstance YourInstanceName -database YourDatabaseName -TableName YourTableName -SchemaName YourSchemaName -InputData $allfiles
You can find examples of different methods in the following article:
6 methods to write PowerShell output to a SQL Server table
Sue
July 30, 2019 at 4:16 pm
Works. Thank you
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy