Bonjour à tous,

Je dois éxecuter une commande Powershell à l'aide de xp_cmdshell pour écrire une requête XMLA dans un fichier. Le problème est que dans cette commande Powershell, j'ai besoin de simples quotes et de doubles quotes.

Voici mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
                declare @xmla varchar(max)
		set @xmla = '<Discover xmlns='+char(39)+'urn:schemas-microsoft-com:xml-analysis'+char(39)+'><RequestType>MDSCHEMA_CUBES</RequestType><Restrictions /><Properties><PropertyList><Catalog>'+'GTB2_v1'+'</Catalog></PropertyList></Properties></Discover>'
		print @xmla 
 
		declare @cmdxmla varchar(max)
		set @cmdxmla = 'Powershell -command "C:\scripts\parseXMLA.ps1 -Argument1 "'+@xmla+'" -Argument2 C:\scripts\QueryCubes.xmla'
		print @cmdxmla 
 
 
		exec xp_cmdshell @cmdxmla
Qui donne comme résultat :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
Powershell -command "C:\scripts\parseXMLA.ps1 -Argument1 "<Discover xmlns='urn:schemas-microsoft-com:xml-analysis'><RequestType>MDSCHEMA_CUBES</RequestType><Restrictions /><Properties><PropertyList><Catalog>GTB2_v1</Catalog></PropertyList></Properties></Discover>" -Argument2 C:\scripts\QueryCubes.xmla
Msg 214, Level 16, State 201, Procedure xp_cmdshell, Line 1
Procedure expects parameter 'command_string' of type 'varchar'.
J'ai besoin de quotes après "-command", avant "<Discover...>" et avant "urn...".

Dans l'interpreteur de commande Powershell, la commande ci-dessous marche, c'est le fait de l'adapter avec xp_cmdshell et de devoir rajouter encore des quotes qui me pose problème
Code : Sélectionner tout - Visualiser dans une fenêtre à part
C:\scripts\parseXMLA.ps1 -Argument1 "<Discover xmlns='urn:schemas-microsoft-com:xml-analysis'><RequestType>MDSCHEMA_CUBES</RequestType><Restrictions /><Properties><PropertyList><Catalog>GTB2_v1</Catalog></PropertyList></Properties></Discover>" -Argument2 C:\scripts\QueryCubes.xmla
Quelqu'un aurait une idée pour que cette commande soit correctement interprétée ?

Merci d'avance