Skip to content

Instantly share code, notes, and snippets.

@chubin
Created February 22, 2016 22:19
Show Gist options
  • Save chubin/22a239783c67456eb0de to your computer and use it in GitHub Desktop.
Save chubin/22a239783c67456eb0de to your computer and use it in GitHub Desktop.
How to enable wttr.in in a PowerShell console
# To enable ANSI sequences in a PowerShell console run the following commands.
# After that you can use wttr.in in you PowerShell just lake that:
# (curl http://wttr.in/ -UserAgent "curl" ).Content
#
# More on it:
# http://stknohg.hatenablog.jp/entry/2016/02/22/195644 (jp)
#
Add-Type -MemberDefinition @"
[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool SetConsoleMode(IntPtr hConsoleHandle, int mode);
[DllImport("kernel32.dll", SetLastError=true)]
public static extern IntPtr GetStdHandle(int handle);
[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool GetConsoleMode(IntPtr handle, out int mode);
"@ -Namespace Win32 -Name NativeMethods
# コンソールモードを変更
$Handle = [Win32.NativeMethods]::GetStdHandle(-11) # stdout
$Mode = 0
$Result = [Win32.NativeMethods]::GetConsoleMode($Handle, [ref]$Mode)
$Mode = $Mode -bor 4 # undocumented flag to enable ansi/vt100
$Result = [Win32.NativeMethods]::SetConsoleMode($Handle, $Mode)
chcp 437
@strangeronline
Copy link

I run without enable-wttr.in-forPowerShell
PS C:\WINDOWS\system32>$PSVersionTable

Name Value


PSVersion 5.1.18362.145
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.18362.145
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

PS C:\WINDOWS\system32>(curl http://wttr.in/ -UserAgent "curl" -UseBasicParsing).Content
Weather report: Zaporizhia, Ukraine
….
Follow @igor_chubin for wttr.in updates

@chubin
Copy link
Author

chubin commented Nov 21, 2019

@strangeronline Yes, the gist is already 4 years old. Now it should just work out of the box, as you did it

@hroberts65616
Copy link

This does not work. When I run it with the curl command as below:

(curl wttr.in/SanDiego?0 -UserAgent "curl" ).Content

I get the following output

image

When I try to use this command by itself. it gets even worse:

(curl wttr.in/SanDiego -UserAgent "curl" ).Content

image

Is there anyway to fix this?

@Scarlov
Copy link

Scarlov commented Apr 28, 2023

Anyone figured out a fix to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment