Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Powershell Script Works Correctly in Alteryx Designer but not on Alteryx Gallery

m00n

New Coder
I asked this over on the Alteryx forums and unfortunately didn't get any answer. Hopefully someone here with Alteryx/PS experience will know the issue. I have a workflow that runs a batch file with a tabcmd command to export data from tableau into a csv in a share drive folder. Then a powershell script runs that reorders the columns, and moves them to another folder. Finally, a second powershell script runs, converts the csv to xlsx and exports that to another folder. When I run it locally in Alteryx Designer, it works just fine and I get the expected output. When I run it in Alteryx Gallery, the workflow completes with no errors but it doesn't give me the expected out. It goes through the tabcmd step and the first powershell script with the correct output, but does not perform the second powershell script correctly. Please see below for script, the --- are there to omit sensitive information.

Code:
$SharedDriveFolderPath = "\\---\shares\Groups\---\---\---\---\--\B\"
$files = Get-ChildItem $SharedDriveFolderPath -Filter *.csv
 foreach ($f in $files){
$outfilename = $f.BaseName +'.xlsx'
$outfilename
#Define locations and delimiter
$csv = "\\---\shares\Groups\---\---\---\---\--\B\$f" #Location of the source file
$xlsx = "\\---\shares\Groups\---\---\---\---\---\---\C\$outfilename" #Desired location of output
$delimiter = "," #Specify the delimiter used in the file

# Create a new Excel workbook with one empty sheet
$excel = New-Object -ComObject excel.application
$workbook = $excel.Workbooks.Add(1)
$worksheet = $workbook.worksheets.Item(1)

# Build the QueryTables.Add command and reformat the data
$TxtConnector = ("TEXT;" + $csv)
$Connector = $worksheet.QueryTables.add($TxtConnector,$worksheet.Range("A1"))
$query = $worksheet.QueryTables.item($Connector.name)
$query.TextFileOtherDelimiter = $delimiter
$query.TextFileParseType  = 1
$query.TextFileColumnDataTypes = ,1 * $worksheet.Cells.Columns.Count
$query.AdjustColumnWidth = 1

# Execute & delete the import query
$query.Refresh()
$query.Delete()

# Save & close the Workbook as XLSX.
$Workbook.SaveAs($xlsx,51)
$excel.Quit()
}
 
Do you get this error when running it.
[CODE title="Powershell Error"]Get-ChildItem : Cannot find path '\\---\shares\Groups\---\---\---\---\--\B\' because it does not exist.
At line:2 char:10
+ $files = Get-ChildItem $SharedDriveFolderPath -Filter *.csv
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (\\---\shares\Gr...-\---\---\--\B\:String) [Get-ChildItem], ItemNotFound
Exception
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
[/CODE]
Also try echoing parts of the code to see if it works,
 
Do you get this error when running it.
[CODE title="Powershell Error"]Get-ChildItem : Cannot find path '\\---\shares\Groups\---\---\---\---\--\B\' because it does not exist.
At line:2 char:10
+ $files = Get-ChildItem $SharedDriveFolderPath -Filter *.csv
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (\\---\shares\Gr...-\---\---\--\B\:String) [Get-ChildItem], ItemNotFound
Exception
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
[/CODE]
Also try echoing parts of the code to see if it works,
I get something like this:
New-Object: Retrieving the COM class factory for component with CLSID....
$excel = New-Object -ComObject excel.application...
Resource Unavailable...
FullyQualifiedErrorId: No COMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand.
 
Back
Top Bottom