0

Simple question: Can I avoid using NETSH in Windows Server 2008 R2 and instead use PowerShell CmdLets to manipulate things like HTTP?

If so, what are some CmdLets to get me started and are they part of some extra module?

1

There's a NetAdapter module in Powershell 3.0 which appears to cover the functionality of netsh, however the module only ships with Windows 8 or Windows Server 2012, so you're still stuck with netsh or CIM/WMI on Windows Server 2008 R2.

Although unrelated to netsh question, version 3 added an invoke-webrequest cmdlet which is includes in 2008 R2 and Windows 7.

1
2

powershell is running on top of .NET so you should be able to do whatever you want with http for example here is a simple RSS function :

function RSS{
    Param ($Rssurl='http://news.google.com/news?pz=1&cf=all&ned=us&hl=en&output=rss')
    $proxy = New-Object System.Net.WebProxy("http://10.10.18.18:8080")
    $Webclient = new-object net.webclient 
    $Webclient.proxy=$proxy
    $Webclient.UseDefaultCredentials = $True
    $rss = [xml]$Webclient.DownloadString($Rssurl)
    $rss.rss.channel.item | ForEach {
    New-Object PSObject -Property @{
        Title = $_.Title
        PublicationDate = (Get-Date $_.PubDate)
        Link = $_.Link
    }
}

here is an other example in pure PS to change the network card settings :

$card=Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=true"
if($profile -eq 'dhcp' ){
    $card.EnableDhcp()
    write-host OK -ForegroundColor 'green'
    exit
}
# manual IP settings :
$card.EnableStatic($address,'255.255.255.0')
$card.SetGateways($gw)
$card.SetDNSServerSearchOrder(@($dns,'10.24.1.8'))
1
  • Although useful, and I'll +1, I will keep the question open to see if anyone knows of some simple 'purpose built' CmdLets that are intentionally designed to replace NETSH as the way to fiddle with things like HTTP.sys port registrations. – Luke Puplett Nov 28 '12 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.