question

tpez avatar image
tpez asked

I have a powershell script below that imports data from a filepath to a table in sql server management studio. It runs painfully slow. Is there anyway that is recommended to speed it up?

$insert=@'

INSERT INTO FileAuthor(FilePath, FileAuthor)

VALUES ('{0}','{1}')

'@

$FolderPath="\\INSERT File path HERE\*"

$connectionString='Data Source=CBYLAW1HCX093\NetDocs;Initial Catalog=ND_Cokinos;Integrated Security=SSPI'

$conn=New-ObjectSystem.Data.SqlClient.SqlConnection($connectionString)

$conn.Open()

$cmd=$conn.CreateCommand()

Get-ChildItem$FolderPath|Get-ChildItem-recurse-file|% {

# Retrieves File Author

$folderObj= (New-Object-ComObjectShell.Application).namespace((Split-Path-Path$_.FullName))

$fileAuthor=$folderObj.getDetailsOf($folderObj.items().item($_.Name),20)

#Gather metadata and write to SQL

$FilePath=$_.FullName -replace"'","''"

$cmd.CommandText =$insert-f$FilePath,$fileAuthor

$cmd.ExecuteNonQuery()

}

sqlpowershellimport-dataexport-data
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.