Disable and Enable Features Using Dism

Dism- Deployment Image Servicing and Management used to service a windows image (.wim) or a virtual hard disk. It can be also used to enable and disable features in windows.

Start the cmd as administrator and supply below commands-

#It gives the list of all features

C:Windows\system32>Dism /online /Get-Features

#It enable the feature

C:Windows\system32>Dism /online /Enable-Feature /FeatureName:<FeatureName> /All


#It disable the feature

C:Windows\system32>Dism /online /Disable-Feature /FeatureName:<FeatureName>


Reading and Writing Text File using PowerShell

Here I am listing some of the common cmdlets which help to operate with text file-

How to create text file using PowerShell?
New-Item <File Path>
How to open text file or any folder sturcture using PowerShell?
Invoke-Item <File Path>
How to add or append contents in text file using PowerShell?
Add-Content <File Path> Text with single quote
How to clear contents in text file using PowerShell?
Clear-Content <File Path>
How to clear contents and add new contents in text file using PowerShell?
Set-Content <File Path> Text with single quote
How to read file contents using PowerShell?
Get-Content <File Path>
How to save cmdlets outputs directly to text file?
Cmdlets | Out-File <File Path>. Example: Get-Process | Out-File D:\PowerShell
How to remove text file using PowerShell?
Remove-Item <File Path>

How to create generation 2 virtual machine using PowerShell?

Below script would help to create virtual machine in Hyper-V using PowerShell-

  1. Open PowerShell window as admin.
  2. Paste below script and hit enter.
  3. VM would be created.
  4. Open Hyper-V Manager and verify it.

# Set VM Name, Switch Name, and Installation Media Path.
$VMName = ‘TestVM’
# Switch is nothing but network adapter
$Switch = ‘My New Virtual Switch’
#OS Iso file should be assigned to InstallMedia
$InstallMedia = ‘D:\Softwares\en_windows_10_enterprise_version_1607_updated_jul_2016_x64_dvd_9054264.iso’

# Create New Virtual Machine
# MemoryStartupBytes contents the RAM size of VM.
# NewVHDSizeBytes contents the size of HD.
New-VM -Name $VMName -MemoryStartupBytes 1073741824 -Generation 2 -NewVHDPath “C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\$VMName.vhdx” -NewVHDSizeBytes 53687091200 -Path “C:\ProgramData\Microsoft\Windows\Hyper-V\$VMName” -SwitchName $Switch

# Add DVD Drive to Virtual Machine
Add-VMScsiController -VMName $VMName
Add-VMDvdDrive -VMName $VMName -Path $InstallMedia

# Mount Installation Media
$DVDDrive = Get-VMDvdDrive -VMName $VMName

# Configure Virtual Machine to Boot from DVD
Set-VMFirmware -VMName $VMName -FirstBootDevice $DVDDrive