Skip to content

Commit 2813042

Browse files
committed
Support for PS Core.
1 parent 98c9293 commit 2813042

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed
112 Bytes
Binary file not shown.

GoogleImageSearch/GoogleImageSearch.psm1

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ function Get-GoogleImageSearchUrl
1515
[System.IO.FileInfo]
1616
$ImagePath
1717
)
18-
# Test for PS Core that is not supported
19-
Test-PSVersion
2018

2119
# Extract the image file name, without Path.
2220
$fileName = Split-Path $imagePath -Leaf
@@ -62,11 +60,25 @@ Content-Disposition: form-data; name="image_content"
6260
$stream.Close()
6361

6462
# get response stream, which should contain a 302 redirect to the results page
65-
$respStream = $request.GetResponse().GetResponseStream()
63+
if ($PSVersionTable.PSVersion.Major -gt 5)
64+
{
65+
try
66+
{
67+
$request.GetResponse()
68+
}
69+
catch [System.Exception]
70+
{
71+
Write-Output $PSItem.Exception.Response.Headers[0]
72+
}
73+
}
74+
else
75+
{
76+
$respStream = $request.GetResponse().GetResponseStream()
6677

67-
# pluck out the results page link that you would otherwise be redirected to
68-
(New-Object Io.StreamReader $respStream).ReadToEnd() -match 'HREF\="([^"]+)"' | Write-Verbose
69-
$matches[1]
78+
# pluck out the results page link that you would otherwise be redirected to
79+
(New-Object Io.StreamReader $respStream).ReadToEnd() -match 'HREF\="([^"]+)"' | Write-Verbose
80+
$matches[1]
81+
}
7082
}
7183

7284
function Get-Image

0 commit comments

Comments
 (0)