October 2025
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories

October 2025
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

PowerShell To Add IP Address

Setting an IP address
PS C:\Users\Administrator> Get-NetAdapter

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
—-                      ——————–                    ——- ——       ———-             ———
Ethernet0                 Intel(R) 82574L Gigabit Network Conn…      12 Up           00-0C-29-3C-C0-2F         1 Gbps
PS C:\Users\Administrator>
Get-NetIPAddress -InterfaceIndex 12 -AddressFamily IPv4

 

To add the IP address use:

New-NetIPAddress -InterfaceIndex 12 -AddressFamily IPv4 -IPAddress 192.168.1.9 -PrefixLength 24

PowerShell to Shutdown Windows Server 2012

Launch PowerShell, type stop then tab, you should see Stop-Computer.  If this flashy technique does not work, then just type this one simple command long-hand:

# PowerShell command to shutdown Windows Server 2012

Stop-Computer

 

shutdown utility. However, there is a little known switch to bring-up a GUI version of this command line utility.

# GUI method of using the built-in Shutdown command

Shutdown -i

Note: If you are going to use any of the Shutdown commands, the first switch to learn is -a.  Shutdown -a meaning abort!

Pure Shutdown

I like to operate shutdown from within PowerShell.
# Shutdown the local Windows Server 2012 machine

Shutdown -s -m \\localhost

Reboot Windows Server 2012 using Powershell

For occasions where you employ the shutdown command, then instead of typing -s, substitute -r.

# How to Reboot Server 2012 with PowerShell
Restart-Computer

# How to Reboot with the built-in command
Shutdown -r -m \\localhost

shutdown /r /t 0

 

Install and Remove DHCP SERVER Using PowerShell

Install DHCP SERVER Using PowerShell

 

PS C:\Users\Administrator> get-command -Module servermanager

CommandType     Name                                               ModuleName
———–     —-                                               ———-
Alias           Add-WindowsFeature                                 ServerManager
Alias           Remove-WindowsFeature                              ServerManager
Function        Disable-ServerManagerStandardUserRemoting          ServerManager
Function        Enable-ServerManagerStandardUserRemoting           ServerManager
Cmdlet          Get-WindowsFeature                                 ServerManager
Cmdlet          Install-WindowsFeature                             ServerManager
Cmdlet          Uninstall-WindowsFeature                           ServerManager

 

 

PS C:\Users\Administrator> Add-WindowsFeature -IncludeAllSubFeature -Name DHCP, RSAT-DHCP

Success Restart Needed Exit Code      Feature Result
——- ————– ———      ————–
True    Yes            SuccessRest… {DHCP Server, Remote Server Administration…
WARNING: You must restart this server to finish the installation process.
WARNING: Windows automatic updating is not enabled. To ensure that your newly-installed role or feature is
automatically updated, turn on Windows Update.
PS C:\Users\Administrator> Get-WindowsFeature *dhcp*

Display Name                                            Name                       Install State
————                                            —-                       ————-
[X] DHCP Server                                         DHCP                      InstallPending
[X] DHCP Server Tools                           RSAT-DHCP                 InstallPending

 

Get-WindowsFeature

Install-WindowsFeature DHCP -IncludeManagementTools -whatif
Add-WindowsFeature -IncludeAllSubFeature -Name DHCP, RSAT-DHCP

 

You can install the DHCP server role on Windows server 2012, by running the following PowerShell command.

Install-WindowsFeature –Name DHCP

This would automatically install the DHCP RSAT which includes DHCP MMC, DHCP netsh context and DHCP PowerShell.

If you only wish to install DHCP RSAT, you can run the following command.

Install-WindowsFeature –Name RSAT-DHCP

Next step is to bind the DHCP server to a network interface where it can listen for the client requests and lease out IP addresses. This network interface should be configured with a static IPv4 or IPv6 address. The following PowerShell command would bind the DHCP server to
the network interface.

Set-DhcpServerv4Binding -BindingState $true -InterfaceAlias “Local Area Connection”

If your network operates in Windows domain environment then you will need to authorize the DHCP server in Active Directory so that it can serve IP addresses to client computers. Run the following command to authorize the DHCP server. In this case the IP address of DHCP
server is obtained by looking up in DNS. You can also choose to explicitly specify an IP address of DHCP server.

Add-DhcpServerInDC -DnsName “DhcpServer.DomainName.com”

A scope defines a range of IP addresses that are available to be leased out to client computers on a particular subnet. Here is an example of how to add a new scope through Powershell. The Add-DhcpServerV4Scope cmdlet also gives you options to specify the state of a scope, enable Network Access Protection (NAP), add the scope as part of a superscope and so on.

Add-DhcpServerv4Scope -Name “Friendly Name of Scope” -StartRange 10.10.10.1 -EndRange 10.10.10.254 -SubnetMask 255.255.255.0

In a network that uses DHCP, it is a common requirement to permanently reserve an IP address for specific clients. It is typically needed for devices like printers and application servers that always have a fixed IP address on the network. Here’s how to add a reservation on the DHCP server.

Add-DhcpServerv4Reservation -IPAddress 10.10.10.8 -ClientId F0-DE-F1-7A-11-6A -Description “Friendly name of reservation”

In addition to IP address leases, DHCP server also provides other configuration information to the clients. It can provide the IP address of DNS server, default gateway, router, WINS server and nmore. Network administrator has to define these properties on DHCP server by means of DHCP option values.

With PowerShell you can define :

–  A server wide option value which is applicable to all scopes on the DHCP server

–  An option value for a  specific scope or a reservation

For instance, the following command defines an option value to apply on all scopes.

Set-DhcpServerv4OptionValue -OptionId 6 -value 192.168.1.1

Note: option id 6 is for Dns Server

MAC address filtering is used to define a list of clients that can acquire IP addresses from the DHCP server. Any foreign client that is not on the list will fail to get an IP address. This greatly enhances security of corporate network. You can define two types of MAC Addresses
lists on DHCP servers. The clients in Allow list are provided services by the DHCP server and ones in Deny list are denied the services. Here is how you add a new MAC address to the deny list.

Add-DhcpServerv4Filter -List Deny -MacAddress F0-DE-F1-7A-11-6B -Description “Friendly name of filter”

Remove Windows feature
PS C:\Users\Administrator> Remove-WindowsFeature -Name DHCP, RSAT-DHCP

Success Restart Needed Exit Code      Feature Result
——- ————– ———      ————–
True    Yes            SuccessRest… {DHCP Server, Remote Server Administration…
WARNING: You must restart this server to finish the removal process.

Add A DHCP using PowerShell

Here is a quick powershell script to set your network card TCP/IP setting to dynamic addressing:

$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration | where{$_.IPEnabled -eq “TRUE”}

Foreach($NIC in $NICs)

{

$NIC.EnableDHCP()

$NIC.SetDNSServerSearchOrder()

}

IPConfig /all

Add A Static IP using PowerShell

$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername . | where{$_.IPEnabled -eq $true -and $_.DHCPEnabled -eq $true}
Foreach($NIC in $NICs) {
$ip = “192.168.1.10”
$gateway = “192.168.1.254”
$subnet = “255.255.255.0”
$dns = “8.8.8.8”,”192.168.1.254″
$NIC.EnableStatic($ip, $subnet)
$NIC.SetGateways($gateway)
$NIC.SetDNSServerSearchOrder($dns)
$NIC.SetDynamicDNSRegistration(“FALSE”)
}
IPConfig /all

Diskpart to Create and Format Partitions

To use the command line to bring a disk online, create a partition, and format it, run the following commands:

 C:\> Diskpart

DISKPART> list disk
DISKPART> select disk (id)
DISKPART> online disk (if the disk is not online)
DISKPART> attributes disk clear readonly
DISKPART> clean
DISKPART> convert mbr (or gpt)
DISKPART> create partition primary
DISKPART> select part 1
DISKPART> active (if this is the boot partition)
DISKPART> format fs=ntfs label=(name) quick
DISKPART> assign letter (letter)
DISKPART> list volume


The following are common errors displayed if you miss a step:

DISKPART> clean
DiskPart has encountered an error: The media is write protected.
See the System Event Log for more information.

Resolution: run “attributes disk clear readonly” before trying to clean the volume and create the partition.

DISKPART> convert mbr

Virtual Disk Service error:
The specified disk is not convertible. CDROMs and DVDs
are examples of disks that are not convertable.

Resolution: clear all data off the disk before converting by running the clean command.

DISKPART> create partition primary
Virtual Disk Service error:
There is not enough usable space for this operation.

Resolution: run “clean” before trying to create the partition.

DISKPART> format fs=ntfs quick
Virtual Disk Service error:
The volume is not online.

Resolution: online the disk, create the partition, and convert to mbr before formatting.


The following are common errors displayed if there is a hardware problem:

DISKPART> clean
DiskPart has encountered an error: The device is not ready.
See the System Event Log for more information.

Resolution: If the event log entry states “The driver detected a controller error on \Device”, the problem is likely your storage controller on your mainboard. Check your hard drive connections and reload your storage conroller driver. If the event log entry states “VDS fails to write boot code on a disk during clean operation. Error code: 80070015@02070008”, the hard drive itself has failed.

The following are common errors you may see if there is a hardware problem:

DISKPART> clean
DiskPart has encountered an error: The media is write protected.
See the System Event Log for more information.

Resolution: Running “attributes disk clear readonly”, as mentioned above, is the first step. Next, the disk is may be locked by an active process, in which case a reboot generally clears the error.

LVM Linux

Logical Volume Manager

Page Contents

•Gathering Information
•Creating and Moving Volume Groups
•?Partition The Disk
?Initialise The Physical Volumes
?Add the PVs to a Volume Group
?Add Logical Volumes to the Volume Group
?Add Filesystems to the Logical Volumes


•Migrating a Volume Group to Another System
•Reducing the Size of a Logical Volume
•Extending the Size of a Logical Volume
•Creating a Snapshot Logical Volume

LVM2 allows you to create a Volume Group from one or more physical volumes or disks. The volume group can then be divided into logical volumes by assigning space from the physical volumes. Logical volumes equate to partitions and can be used to contain filesystems

The ‘lvm’ command can be run to begin an interactive lvm session where commands can be issued to manage a logical volume

Gathering Information

Top Bottom

Three commands can be used to display detailed information about Volume Groups, Physical Volumes and Logical Volumes:
•vgdisplay
•pvdisplay
•lvdisplay

Summary information can be displayed via:
•vgs
•pvs
•lvs

The vgscan, pvscan and lvscan display the same information in a different format.

Creating and Moving Volume Groups

Top Bottom

This section deals with adding a brand new harddisk to your system, managed by LVM. We are going to create a new volume group to hold media files on disk /dev/sdb.

Partition The Disk

Top Bottom

use cfdisk to create three partitions of type 8E – Linux LVM
cfdisk (util-linux-ng 2.16)

Disk Drive: /dev/sdb
Size: 500107862016 bytes, 500.1 GB
Heads: 255   Sectors per Track: 63   Cylinders: 60801

Name        Flags      Part Type  FS Type          [Label]        Size (MB)
——————————————————————————
sdb1                    Primary   Linux LVM                       149996.21
sdb2                    Primary   Linux LVM                       149996.21
sdb3                    Primary   Linux LVM                       200112.84
Initialise The Physical Volumes

Top Bottom

Use pvcreate to initialise the physical volumes for use with LVM:
lvm> pvcreate /dev/sdb1 /dev/sdb2 /dev/sdb3
Physical volume “/dev/sdb1” successfully created
Physical volume “/dev/sdb2” successfully created
Physical volume “/dev/sdb3” successfully created
Add the PVs to a Volume Group

Top Bottom

Use vgcreate to add the physical volumes to a new volume group called ‘media’:
lvm> vgcreate media /dev/sdb1 /dev/sdb2 /dev/sdb3
Volume group “media” successfully created
Add Logical Volumes to the Volume Group

Top Bottom

Use lvcreate to create the Logical Volumes that will contain the filesystems of the volume group:
lvm> lvcreate -L10G -ndocuments media
Logical volume “documents” created
lvm> lvcreate -L100G -nmusic media
Logical volume “music” created
lvm> lvcreate -L100G -nvideo media
Logical volume “video” created
lvm> lvcreate -L15G -npictures media
Logical volume “pictures” created
Add Filesystems to the Logical Volumes

Top Bottom

Use mkfs to create the filesystems:
mkfs -t ext4 /dev/media/documents
mkfs -t ext4 /dev/media/music
mkfs -t ext4 /dev/media/video
mkfs -t ext4 /dev/media/pictures
With the filesystems prepared, they can now be mounted as /dev/media/documents, /dev/media/music, /dev/media/video and /dev/media/pictures for the device name.

Migrating a Volume Group to Another System

Top Bottom

To migrate a Volume Group to another system the Volume Group must be exported from the old system and then imported to the new system. Prior to exporting the VG, umount the filesystems, then de-activate the Volume Group:
lvm> vgchange -an media
4 logical volume(s) in volume group “media” now inactive
lvm> vgexport media
Volume group “media” successfully exported
With the disks attached to the new system, use vgscan to see if the Volume group is visible and lvscan to see which LVs are active:
lvm> vgscan
Reading all physical volumes.  This may take a while…
Found volume group “media” using metadata type lvm2
Found volume group “vg_zadoc” using metadata type lvm2
lvm> pvscan
PV /dev/sdb1   VG media      lvm2 [139.69 GiB / 39.69 GiB free]
PV /dev/sdb2   VG media      lvm2 [139.69 GiB / 114.69 GiB free]
PV /dev/sdb3   VG media      lvm2 [186.37 GiB / 86.37 GiB free]
PV /dev/sda2   VG vg_zadoc   lvm2 [465.25 GiB / 0    free]
Total: 4 [931.00 GiB] / in use: 4 [931.00 GiB] / in no VG: 0 [0   ]
lvm> lvscan
inactive          ‘/dev/media/music’ [100.00 GiB] inherit
inactive          ‘/dev/media/video’ [100.00 GiB] inherit
inactive          ‘/dev/media/documents’ [10.00 GiB] inherit
inactive          ‘/dev/media/pictures’ [15.00 GiB] inherit
ACTIVE            ‘/dev/vg_zadoc/lv_root’ [50.00 GiB] inherit
ACTIVE            ‘/dev/vg_zadoc/lv_home’ [409.41 GiB] inherit
ACTIVE            ‘/dev/vg_zadoc/lv_swap’ [5.84 GiB] inherit
To import and activate the Volume group use vgimport and vgchange:
lvm> vgimport media
Volume group “media” successfully imported
lvm> vgchange -ay media
4 logical volume(s) in volume group “media” now active
Reducing the Size of a Logical Volume

Top Bottom

To reduce the size of a Logical Volume, the filesystem must first be reduced using resize2fs, before attempting to issue the lvreduce command. A disk check is also required beforehand:
unmount /dev/system/test
e2fsck -f /dev/system/test
resize2fs /dev/system/test 8G
lvreduce -L 8G /dev/system/test
mount /dev/system/test /media/test

Extending the Size of a Logical Volume

Top Bottom

When increasing the size of a Logical Volume, the filesystem is resized after the LV is extended

Increase LV to 12G:
lvm lvextend -L 12G /dev/system/test
e2fsck -f /dev/system/test
resize2fs /dev/system/test

Increase LV by 2G:
lvm lvextend -L +2G /dev/system/test
e2fsck -f /dev/system/test
resize2fs /dev/system/test

Increase a volume by 20 physical extents:
lvm lvextend -l +20 /dev/system/test
e2fsck -f /dev/system/test
resize2fs /dev/system/test

Creating a Snapshot Logical Volume

Top Bottom

A snapshot logical volume allows you to create an exact copy of a volumes data at the time it was created:
lvcreate -L 5G -s -n homebackup /dev/system/home

Repair filesystem” prompt

How to edit /etc/fstab when at Centos/Redhat “Repair filesystem” prompt?

Now system was unable to boot the system because it was reading /etc/fstab file was unable to find the device for it. This can also happen when you have some external hard-drive attached with your linux system and you remove device but forgot to clean its entry from /etc/fstab file.

Linux gives you a “Repair Filesystem” prompt in this situation and you can enter that by providing the root password. The problem is that on “Repair Filesystem” prompt, linux file system and rest of the file systems are generally not mounted and if mounted then it is “Read-Only” so you can not change files.

Solution:

Use following command to mount the filesystem with writable permission:

Repair filesystem # mount -w -o remount /

After this you can go and change /etc/fstab file. Restart your computer and that’s it.

 

How to mount or unmount NAS/NFS share on ESXi

How to mount or unmount NAS/NFS share on ESXi

 


First you need to have the vmkernel port group configured for the NAS/NFS.

To mount NAS/NFS share on esxi:

esxcfg-nas -a -o <nas_server_hostname or ipaddress> -s <nas share name> <NAS_datastore_name>

To unmount NAS/NFS share on esxi:

esxcfg-nas -d <NAS_datastore_name>


Other options available in ESXi are:

~ # esxcfg-nas –help
esxcfg-nas <options> [<label>]
-a|–add                    Add a new NAS filesystem to /vmfs volumes.
                                 Requires –host and –share options.
                                 Use –readonly option only for readonly access.
-o|–host <host>        Set the host name or ip address for a NAS mount.
-s|–share <share>     Set the name of the NAS share on the remote system.
-y|–readonly             Add the new NAS filesystem with readonly access.
-d|–delete                 Unmount and delete a filesystem.
-l | –list                      List the currently mounted NAS file systems.
-h| –help                    Show this message.