Question: I need assistance changing the current path for the code below. I am using this script from Microsoft.com to integrate powershell with Power BI. My

I need assistance changing the current path for the code below. I am using this script from Microsoft.com to integrate powershell with Power BI. My goal is to automatically update the data in my Power BI dataset by refreshing this folder with my csv file inside then placing the previous csv file into an "archive" folder within the "test" folder.

Link to original script and it is also listed below: https://powerbi.microsoft.com/en-us/blog/using-a-power-bi-app-to-upload-csv-files-to-a-dataset/

Current Path: C:\Users\pzb583\Desktop\test

The "Archive" folder is inside "test".

The file with the data is called "test_data1".

Not familiar with shell scripting so any help with this would be much appreciated.

cls

$ErrorActionPreference = "Stop"

$currentPath = (Split-Path $MyInvocation.MyCommand.Definition -Parent)

#Create Archive Folder

new-item -Name "Archive" -Force -ItemType directory -Path "$currentPath\CSVData" | Out-Null

Import-Module "$currentPath\Modules\PowerBIPS" -Force

while($true)

{

# Iterate each CSV file and send to PowerBI

Get-ChildItem "$currentPath\CSVData" -Filter "*.csv" |% {

$file=$_

#Import csv and add column with filename

$data = Import-Csv $file.FullName | select @{Label="File";Expression={$file.Name}}, *

# Send data to PowerBI

$data | Out-PowerBI -dataSetName "CSVSales" -tableName "Sales" -types @{"Sales.OrderDate"="datetime"; "Sales.SalesAmount"="double"; "Sales.Freight"="double"} -batchSize 300 -verbose

# Archive the file

Move-Item $file.FullName "$currentPath\CSVData\Archive\" -Force

}

Write-Output "Sleeping..."

Sleep -Seconds 5

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!