Powershell - Import local CSV

时间秒杀一切 提交于 2019-12-12 05:32:16

问题


I have a powershell script that imports a CSV file using this command:

$empCsv = Import-Csv "addEmp.csv"

I have the csv sitting in the same directory as the script but I'm getting a FileNotFoundException. If I use the command with a path to the CSV like this:

$empCsv = Import-Csv .\Desktop\createUser\addEmp.csv

It works fine.

I want to be able to give this script to someone to use and let them run the script from any location and be able to import the .csv that's sitting in the same directory.

Why can't my first command find the csv?

Thanks!


回答1:


To import a CSV in the same directory, I suggest:

$empCsv = Import-Csv "$PSScriptRoot\addEmp.csv"

PSScriptRoot gives you the path of the currently executing script.



来源:https://stackoverflow.com/questions/45326806/powershell-import-local-csv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!