1

Is there a way to import a CSV from a Website and use it in PowerShell? With the Import-Csv Cmdlet I get this error:

$FilePath = "http://sharepoint.com/mydocuments/serverlist.csv"
$serverList = Import-Csv $FilePath -Delimiter ";"


Import-Csv : Cannot find drive. A drive with the name 'http' does not exist.
At line:2 char:15
+ $serverList = Import-Csv $FilePath -Delimiter ";"
+               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (http:String) [Import-Csv], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.ImportCsvCommand

2 Answers 2

2

Download the CSV first:

$FilePath = "http://sharepoint.com/mydocuments/serverlist.csv"
$localPath = "C:\temp\serverlist.csv"
$wc = New-Object System.Net.Webclient
$wc.DownloadFile($FilePath, $localPath)
$serverList = Import-Csv $localPath -Delimiter ";"
Sign up to request clarification or add additional context in comments.

Comments

0

Try this (Make sure you add your headers if you don't already have them or remove header option if you do):

#Create an array 
$serverList= @()
#Create URL Variable
$FilePath= "http://sharepoint.com/mydocuments/serverlist.csv"
#ImportData from URL and use convert-FromCSV into Array
$serverList = (Invoke-WebRequest $FilePath).content | ConvertFrom-Csv -Delim ';' -Header 'header1','header2'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.