I want to call 2 commands in Powershell with Xp_cmdshell

  • Hi all,

    I'm new to powershell and found 2 powershell comands to open a file encoded in UTF-8 and transforms it to unicode encoding... Which is exactly what I was looking for.

    I tried it directly in a powershell window and it works perfectly.

    $Content = get-content d:\VisualCronTemp\testExport.csv

    $Content | out-file -filepath d:\VisualCronTemp\Output.csv -encoding Unicode

    Now, I'm trying to automate this using a stored procedure that would do these 2 commands

    Is it even possible? Does anyone know how?

    thanks in advance

    JG

  • figured it out...

    To convert a UTF8 file to unicode (this helps when you want to Bulk insert a UTF8 file which is no longer supported by MS SQL server since SQL 2005)

    Declare @SQLStr varchar(8000), @SourcePathFile varchar(300), @DestinationPathFile varchar(300)

    set @SourcePathFile = 'd:\VisualCronTemp\testExport.csv'

    set @DestinationPathFile = 'd:\VisualCronTemp\Output.csv'

    Set @SQLStr = 'xp_cmdshell ''powershell.exe -command "get-content ' + @SourcePathFile + ' | out-file -filepath ' + @DestinationPathFile + ' -encoding Unicode"'''

    Exec (@SQLSTr)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply