This topic contains 2 replies, has 3 voices, and was last updated by
September 8, 2019 at 6:15 am #175225ParticipantTopics: 1Replies: 0Points: 16Rank: Member
I'm new to PowerShell scripting. I created a test script to convert a *.csv file from another folder and I want to save in a folder with the date. EX: c:\TEST_Convert\09072019\Convertfile_09072019.xls. Can you tell me how to add the date in the path?
$newfolder=New-Item -Type Directory $(Get-Date -UFormat '%m%d%Y')
$CurrentDate = Get-Date -UFormat '%m%d%Y'
$xl = new-object -comobject excel.application
$xl.visible = $true
$Workbook = $xl.workbooks.open(“C:\TEST_Copy\09072019\TestFile.csv”)
$Worksheets = $Workbooks.worksheets
$Workbook.Saved = $True
September 8, 2019 at 9:35 am #175282ParticipantTopics: 1Replies: 1529Points: 2,587Rank: Community Hero
First: You forgot to format your code as code. Please use the code tag button when you post code.
Second: You forgot to tell what's not working. 😉
You don't need to use quotation marks around variables – sometimes that's even counterproductive if you don't use the right ones as you can see in your command $Workbook.SaveAs ... 😉
You may take a look at the great module from Doug Finke ImportExcel. It will make your life easier I think. 😉
Last problem I can see: you create a variable $Worksheets but you're never using it.
September 9, 2019 at 4:16 pm #175486ParticipantTopics: 6Replies: 78Points: 143Rank: Participant
Looks like you're pretty much there. You just need to create the new directory using New-Item.
New-Item -Type Directory -Name $CurrentDate
You must be logged in to reply to this topic.