Reputation: 6843
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
Upvotes: 1
Views: 7526
Reputation: 1
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'
Upvotes: 0
Reputation: 10107
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 ";"
Upvotes: 2