powershell - Using Import-CSV to make HTTP Request -



powershell - Using Import-CSV to make HTTP Request -

wonder if can help. i'm trying utilize powershell import list of domains , generate http request each of them. i've got far:

class="snippet-code-html lang-html prettyprint-override">$csvfilename = "c:\sites\sites.csv" $csv = import-csv $csvfilename -header @("url") | foreach { $http_request = [system.net.webrequest]::create('$csv') $http_response = $http_request.getresponse() $http_status = [int]$http_response.statuscode if ($http_status -eq 200) { write-host "site ok!" } else { write-host "the site may down, please check!" } $http_response.close() }

i'm not sure why 'create()' statement won't pick url. ideas?

many thanks

inside foreach loop, can access current element automatic variable $_

so replace line $http_request = [system.net.webrequest]::create('$csv') $http_request = [system.net.webrequest]::create("$_")

but before create method waiting string,you have expand url property (otherwise pscustomobject not string) : import-csv c:\temp\urls.csv -header "url" |select -expand url |%{ [system.net.webrequest]::create("$_")}

powershell http-request

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -