Replace netsh with Windows PowerShell – Basic network cmdlets

Some days ago I made a blog post about how you can replace diskpart.exe with the new cmdlets in Windows PowerShell v3. Now my next goal was to replace netsh with PowerShell.

Microsoft offers a lot of new cmdlets for networking tasks lets see what we have here. We got a lot of new PowerShell modules which are related to networking.

get-module

Now the two modules which sound really interesting are

NetAdapter
NetTCPIP

lets check which cmdlets are included

Get-Command -Module NetAdapter

net-adpater module

 Get-Command -Module NetTCPIP

Now lets start with NetAdpater.

List all Network Adapters

 Get-NetAdapter 

get-netadapter

Just list Wireless Network Adapters

 Get-NetAdapter -Name *Wireless* 

get-netadapter wireless

Get more information VLAN ID, Speed, Connection status

 Get-NetAdapter | ft Name, Status, Linkspeed, VlanID 

get-netadapter information

Get driver information

 Get-NetAdapter | ft Name, DriverName, DriverVersion, DriverInformation, DriverFileName 

get-netadapter driver

Get adapter hardware information. This can be really usefull when you need to know the PCI slot of the NIC.

 Get-NetAdapterHardwareInfo 

get-netadapterhardwareinfo

Disable and Enable a Network Adapter

 Disable-NetAdapter -Name "Wireless Network Connection"
Enable-NetAdapter -Name "Wireless Network Connection" 

disable enable network adapter

Rename a Network Adapter

 Rename-NetAdapter -Name "Wireless Network Connection" -NewName "Wireless" 

rename network adapter

Now with the NetTCPIP PowerShell module we can work with IP settings

Get IP and DNS address information

 Get-NetAdapter -Name "Local Area Connection" | Get-NetIPAddress 

get-ipaddress

Get IP address only

 (Get-NetAdapter -Name "Local Area Connection" | Get-NetIPAddress).IPv4Address 

get-ipaddress only

Get DNS Server Address information

 Get-NetAdapter -Name "Local Area Connection" | Get-DnsClientServerAddress 

get-dnsserver

Set IP Address

 New-NetIPAddress -InterfaceAlias "Wireless" -IPv4Address 10.0.1.95 -PrefixLength "24" -DefaultGateway 10.0.1.1 

or if you want to change a existing IP Address

 Set-NetIPAddress -InterfaceAlias "Wireless" -IPv4Address 192.168.12.25 -PrefixLength "24"

Remove IP Address

 Get-NetAdapter -Name "Wireless" | Remove-NetIPAddress 

Set DNS Server

 Set-DnsClientServerAddress -InterfaceAlias "Wireless" -ServerAddresses "10.10.20.1","10.10.20.2" 

Set interface to DHCP

 Set-NetIPInterface -InterfaceAlias "Wireless" -Dhcp Enabled 

Now with this basic knowledge we can replace some of the basic netsh commands and ipconfig

netsh

ipconfig
netsh interface set interface "Local Area Connection" newname="Management"
netsh interface ipv4 set address "Management" static 192.168.10.101 255.255.255.0 192.168.10.1

Windows PowerShell

Get-NetAdapter
Rename-NetAdapter -Name "Local Area Connection" -NewName "Management"
New-NetIPAddress -InterfaceAlias "Management" -IPv4Address 192.168.10.101 -PrefixLength "24" -DefaultGateway 192.168.10.1

Replace Diskpart with Windows PowerShell – Basic Storage cmdlets

Windows Server 8

Last week I made a blog post about how you can create a USB drive for Windows To Go. In my post I used diskpart.exe to format the USB drive. Now we don’t live in the stone age anymore, so I did the same with the new version of Windows PowerShell coming in Windows 8 and Windows Server 8.

Now here some basic cmdlets to do some simple storage operations, like clean a disk, create a partition and so on.

Lets start simple

List all disks

Get-Disk

get-disk

Now get all partitions

Get-Partition

get-partition

Now get all partitions of disk 0

Get-Partition -DiskNumber 0

get-partitiondisk

Clear a Disk

Get-Disk 1 | Clear-Disk -RemoveData

clear-disk

Create a new partition

New-Partition -DiskNumber 1 -UseMaximumSize

new-partition

Format this volume

Get-Partition -DiskNumber 1 -PartitionNumber 1 | Format-Volume -FileSystem NTFS

format-volume

Create new partition and format it with the label “USB”:

New-Partition -DiskNumber 1 -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel USB

format-volume1

Change driveletter

Set-Partition -DriveLetter E -NewDriveLetter T

set-partition

Set a partition active

Set-Partition -DriveLetter T -IsActive $ture

set-partition1

Remove a partition

Remove-Partition -DriveLetter T

remove-partition

Bring a disk online

 Set-Disk 1 -isOffline $false 

Remove Readonly flag

 Set-Disk 1 -isReadOnly $false 

Initialize Disk with GPT

 Initialize-Disk 1 -PartitionStyle GPT 

online disk

This is some basic knowledge about the storage module in PowerShell v3. Lets see how we can change the commands from using diskpart to Windows PowerShell.

Diskpart.exe

select disk 1
clean
create partition primary
format fs=ntfs quick
active
assign letter=e

PowerShell:

Get-Disk 1 | Clear-Disk -RemoveData
New-Partition -DiskNumber 1 -UseMaximumSize -IsActive -DriveLetter E | Format-Volume -FileSystem NTFS -NewFileSystemLabel USB

replace-diskpart

Windows 8 Consumer Preview: Cannot acces NetApp CIFS share

Windows 8 Logo

If you try to connect to a NetApp CIFS share via Windows 8 beta you may cannot access the share because of the following error:

SMB connections fail with error “Invalid Signature”

Cause:

This behavior may be due to the “Secure Negotiate” feature added to SMB 2.24 for the Windows “8″ beta release, which relies on the correct signing of error responses by all SMB 2 servers (including those supporting only protocol versions 2.0 and 2.1). Some third-party file servers do not respond with a signed error response causing the connection to fail.

Microsoft has two workrounds for this problem:

  • Enable signing on the third-party file server.
  • Disable “Secure Negotiate” on the client.

You can disable “Secure Negotiate” with the following PowerShell command:

Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanWorkstation\Parameters" RequireSecureNegotiate -Value 0 -Force

Checkout the Microsoft KB2686098

Update

Only some minutes after I released this blog post I got an anwser from Glenn Sizemore (NetApp) how you can enable SMB 2 signing on the NetApp.

ONTAP CLI:

options cifs.smb2.signing.required on

PowerShell:

ipmo DataONTAP
Connect-NaController controller
Set-NaOption cifs.smb2.signing.required off

Thanks for that.

Windows Server 8: Enable CSV Cache

Windows Server 8

In Windows Server 8 beta, Microsoft released a lot of new features for Cluster Shared Volumes (CSV). One of them is CSV Cache. CSV Cache gives you the possibility to allocate system memory (RAM) of the cluster nodes as cache. This can improve the performance of read requests in workloads like Hyper-V.

Now to enable the CSV Cache on a cluster you have to do this with Windows PowerShell.

  1. First open the PowerShell prompt
  2. Set the size of the CSV Cache. The default it 512MB. With this command you will reserve the Memory on all Cluster nodes for caching.
    (Get-Cluster). SharedVolumeBlockCacheSizeInMB = 512
    
  3. Now you have to enable the Cache on on the Cluster Shared Volumes you want to use.
    Get-ClusterSharedVolume “Cluster Disk 1” | Set-ClusterParameter  CsvEnableBlockCache 1
    

If you want to know more about CSV Cache, you can read this blog post from Elden Christensen on the Failover Clustering and Network Load Balancing Team Blog.

Installing Windows 8 Consumer Preview on the Samsung Series 7 Slate PC

samsungseries7slatepcwindows8If you have a Samsung Series 7 Slate PC which normally comes with Windows 7 but you want to try out the Windows 8 Consumer Preview on it, Samsung offers now drivers and a firmware upgrade for your Slate.

You can get it here: http://www.samsung.com/global/windowspreview/

Windows 8: How to create a Windows To Go USB drive

Windows 8 Logo

Microsoft released a new feature called “Windows To Go” with Windows 8. With this feature it is possible to boot your Windows 8 from a USB drive on any PC. In this post I show you how you can do this.

Requirements

Step-by-Step

First let me show you my setup to begin with.

I have my System Drive (C:), the USB drive I want to use (E:) and the Windows 8 ISO mounted (F:)

Windows To Go

 

  1. Run diskpart
    Windows To Go
  2. With “list disk” you can list all your disk
    Windows To Go
  3. Now select your usb drive (select disk 1) and clean it. After that you can create a new partition and format that and close diskpart.
    select disk 1
    clean
    create partition primary
    format fs=ntfs quick
    active
    assign letter=e
    exit
    

    WindowsToGo05 Diskpart

  4. Now in my case the ISO is mounted as drive F:. Now with dism I can apply the Windows Image to my USB drive (E:)
    dism /apply-image /imagefile=f:\sources\install.wim /index:1 /applydir:e:\
    

    WindowsToGo

  5. Now you have to make this drive bootable
    bcdboot e:\windows /s e: /f ALL
    
  6. now you are done. You can now boot your USB drive. The first boot will take some time to setup.

If you want to know more about Windows To Go I recommend you the Microsoft session from the BUILD conference.