This is probably a simple thing I am missing but I am trying to convert a comma separated variable into a csv like formatted array ($myarray) using powershell.
FROM:
$ftitemsname = "itemname"
$ftitemssrc= "\\server\folder\a"
$ftitemsdst = "/sftp/items/"
$ftitemstiming = "4"
# 4 AM Execution
$ftobjectsSrc = "/sftp/objects/"
$ftobjectsdst = "\\server\folder\b"
$ftobjectsTiming = "4" "\\server\folder\a","/sftp/objects/","4"
#<WINSCP File Transfer Snippet>
# Download files
$transferResult1 = $session.GetFiles($ftitemsSrc, ($ftitemsdst + $itemsname), $true, $transferOptions)
$transferResult.Check()
Write-EventLog -LogName "Application" -Source "Winscp" -EventID 51221 -EntryType Information -Message "Upload of {0} succeeded -f $transfer.FileName" -Category 1 -RawData 10,20
# Download files
$transferResult1 = $session.GetFiles($ftobjectsSrc, ($ftobjectsdst + $objectsname), $true, $transferOptions)
$transferResult.Check()
Write-EventLog -LogName "Application" -Source "Winscp" -EventID 51221 -EntryType Information -Message "Upload of {0} succeeded -f $transfer.FileName" -Category 1 -RawData 10,20
To make it look like this in my powershell array. Csv representation of the array
I don't want it to actually export to a csv I want to use it in order to pipe those values into a powershell array.
I want to use that array to start an action to them.
This is the manual way I was building it.. but I want to simplify it for others to edit a simply comma separated list versus creating all net new variables.
Eventually, I will be using a foreach value to perform action.
TO:
$myheaders = "name, source, destination, timing"
$mylist1 = "objects","\\server\folder\a","/sftp/objects/","4"
$mylist2= "items","\\server\folder\a","/sftp/items/","4"
foreach($item2do in $entries){
$transferResult1 = $session.GetFiles($item2do.source, ($item2do.destination + $item2do.name), $true, $transferOptions)
$transferResult.Check()
Write-EventLog -LogName "Application" -Source "Winscp" -EventID 51221 -EntryType Information -Message "Upload of {0} succeeded -f $transfer.FileName" -Category 1 -RawData 10,20
}