Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke-SQLUploadFileOle on SQL linked servers #83

Open
MuhoX opened this issue Dec 25, 2024 · 0 comments
Open

Invoke-SQLUploadFileOle on SQL linked servers #83

MuhoX opened this issue Dec 25, 2024 · 0 comments

Comments

@MuhoX
Copy link

MuhoX commented Dec 25, 2024

Hello,

The function Invoke-SQLUploadFileOle does not have an option to use it on linked servers. I've modified the code slightly so that it can be used on linked servers.

I'd like to request a new feature or function to be able to upload and download files with OLE on linked servers. Below is an example code which can be implemented into the upload function:

 [Parameter(Mandatory = $true,
        HelpMessage = 'Linked server name string')]
        [String]$LinkedServer = "",
...
		write-verbose "$instance : Uploading $($FileBytes.Length) bytes to: $OutputFile"           
		$QueryFileUpload = @"
EXEC ('
DECLARE @ob INT;
EXEC sp_OACreate ''ADODB.Stream'', @ob OUTPUT;
EXEC sp_OASetProperty @ob, ''Type'', 1;
EXEC sp_OAMethod @ob, ''Open'';
EXEC sp_OAMethod @ob, ''Write'', NULL, 0x$FileData;
EXEC sp_OAMethod @ob, ''SaveToFile'', NULL, ''$OutputFile'', 2;
EXEC sp_OAMethod @ob, ''Close'';
EXEC sp_OADestroy @ob;') AT [$LinkedServer];
"@
		# Execute query    
		$null = Get-SQLQuery -Instance $Instance -Path $LinkedServer -Query $QueryFileUpload -Username $Username -Password $Password -Credential $Credential -SuppressVerbose 	
...	

For me editing this part of the code it was possible to upload and download files through linked SQL servers, but it's not perfect. If needed I can further modify both the upload and download functions and make a Pull Request.

Regards,

MuhoX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant