Run powershell from SQL SERVER

0

I am trying to obtain a PowerShell query, where I get back the free space in all the disks of my linked servers, this by means of a distributed query, nevertheless when executing this query with the xp_cmdshell I get an error, I will leave the query that I am trying to make and the error that returns me. I hope you can help me. Thank you very much.

The query is as follows:

declare @cmd varchar(200)
set @cmd = 'xp_cmdshell ''powershell $discos = Get-WmiObject -Class 
win32_logicaldisk -Filter "VolumeName = ''Respaldos''"'''
print @cmd

exec (@cmd).

And the error returned is as follows:

Mens. 102, Nivel 15, Estado 1, Línea 1
Sintaxis incorrecta cerca de 'Respaldos'.

Thank you very much for your answers

    
asked by 05.10.2018 в 17:04
source

1 answer

0

After much searching, I found the answer here: link

I leave this in case someone serves you.

Greetings

    
answered by 05.10.2018 / 19:28
source