Search code examples
powershellasp-classic

Classic ASP - Display List of Timezones using powershell


Is there anyway to display system timezone using powershell GET-Timezone -ListAvailble. My requirements is to display this in a dropdownlist in an ASP page. Using .net com is not an option for me now, and even SQL server sys.time_zone_info.


Solution

  • You could use Shell.Exec to call the powershell command and read from the standard output.

    The powershell part is from Lee_Dailey's answer

    <%
    Set objShell = server.CreateObject("WScript.Shell")
    Set objExec = objShell.Exec("cmd /c powershell [System.TimeZoneInfo]::GetSystemTimeZones().DisplayName")
    Set objStdOut = objExec.StdOut
    
    
    Response.write "<select name=""Timezones"">"
    
    While Not objStdOut.AtEndOfStream
       Response.write "<option>" & objStdOut.ReadLine & "</option>"
    Wend
    
    Response.write "</select>"
    
    %>