File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff 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
7284function Get-Image
You can’t perform that action at this time.
0 commit comments