How should I be saving files from Get-DbaXESessionTargetFile? #9706
-
Suppose that I want to copy all of the Extended Events files for a particular session from their default location on my Windows Microsoft SQL Server to a folder on my local machine. How should I do it? I get the uncanny feeling that my solution to this problem isn't the intended one. My currently solution is to open up PowerShell on my local machine as my account with strong Windows permissions on the SQL Server's machine and run this. $FileTargets = (Get-DbaXESession -SqlInstance sql2019 -Session deadlocks | Get-DbaXESessionTarget | Get-DbaXESessionTargetFile)
foreach ($file in $FileTargets) {
$file.CopyTo("C:\Users\Me\MyPlace\$($file.Name)")
} How can I improve on it? I ideally wanted something that I could just tag on to the end of the pipeline. Neither |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I don't see any faster way to copy a binary file to your pc (maybe Copy-Item is more straightforward than the method .CopyTo()) . |
Beta Was this translation helpful? Give feedback.
I don't see any faster way to copy a binary file to your pc (maybe Copy-Item is more straightforward than the method .CopyTo()) .
Get-Content will pipe the content, out-file will receive the content . What renders it "unusable" is probably the encoding(s) but ... why ?
You need the file copied to somewhere (opposed to the file CONTENTS), just use copy-item ^_^