Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

Wednesday 20 September 2023

[Solved] Add-WindowsCapability failed. Error code = 0x800f0954

In this post, we'll look at how to fix the 0x800f0954 error that may appear when installing optional Windows features such as RSAT tools, Language pack features, or any other Windows features.

Errors:

1. PowerShell Add-WindowsCapability Error:

  Add-WindowsCapability : Add-WindowsCapability failed. Error code = 0x800f0954
  At line:6 char:13
  + Add-WindowsCapability -Online -Name $langFeature
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : NotSpecified: (:) [Add-WindowsCapability], COMException
      + FullyQualifiedErrorId : Microsoft.Dism.Commands.AddWindowsCapabilityCommand


2. DISM Package Manager Error:

DISM Package Manager: PID=2628 TID=4325 Error in operation: (null) (CBS HRESULT=0x800f0954) - CCbsConUIHandler::Error 
DISM DISM Package Manager: PID=2628 TID=4561 Failed finalizing changes. - CDISMPackageManager::Internal_Finalize(hr:0x800f0954) 
DISM Package Manager: PID=2628 TID=4561 Failed processing package changes with session options - CDISMPackageManager::ProcessChangesWithOptions(hr:0x800f0954) 
DISM Package Manager: PID=2628 TID=4561 Failed to install capability. - CPackageManagerCLIHandler::ProcessCmdLine_AddCapability(hr:0x800f0954) 
DISM Package Manager: PID=2628 TID=4561 Failed while processing command add-capability. - CPackageManagerCLIHandler::ExecuteCmdLine(hr:0x800f0954) 2
DISM Package Manager processed the command line but failed. HRESULT=800F0954


Solution:

To fix 0x800f0954 error, please follow one below solutions and retry the installation.

Method 1: Local Group Policy
  • Right click on start and click Run then type gpedit.msc and hit enter.
  • Navigate to Computer Configuration > Administrative Templates > System.
  • Scroll down to find "Specify settings for optional component installation and component repair" and open the settings.
  • And select Enabled and also check the checkbox "Download repair content and optional features directly from Windows Updates instead of Windows Server Updates Services (WSUS)".
  • Go back to the PowerShell or Command Prompt window and run gpupdate /force
  • Finally rerun the Add-WindowsCapability in PowerShell or DISM command again to install the feature.


Method 2: Registry

Change WSUServer registry value to 0 and then run windows capability or DISM to directly download the components from internet. Use the following PowerShell script or use Registry GUI to do the change:


Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name "UseWUServer" -Value 0
Restart-Service "Windows Update" -ErrorAction SilentlyContinue



Hopefully you have been able to fix the Add-WindowsCapability or DISM command failed 0x800f0954 error that so many of us have been running into.


Friday 15 September 2023

PowerShell - Special Folders (System Folders)

In VBscript, there existed a concept known as Special Folders, for example, My Documents which could be accessed using the Shell. Application object and passing in a constant that applied to a certain folder. This is also possible using PowerShell.



$a = New-Object -ComObject Shell.Application
Get-ChildItem $a.NameSpace(0x21).Self.Path

The prior two lines of code can also be written as follows: 

Get-ChildItem ((New-Object -ComObject Shell.Application).Namespace(0x21).Self.Path)

Below is the list of special folders and its hex number, please do comment on this post if any of them is/are wrong:

Hex Number Folder Name
0x1 Internet Explorer
0x2 Programs
0x3 Control Panel
0x4 Printers and Faxes
0x5 My Documents
0x6 Favorites
0x7 Startup
0x8 My Recent Documents
0x9 SendTo
0xa Recycle Bin
0xb Start Menu
0xd My Music
0xe My Videos
0x10 Desktop
0x11 My Computer
0x12 My Network Places
0x13 NetHood
0x14 Fonts
0x15 Templates
0x16 All Users Start Menu
0x17 All Users Programs
0x18 All Users Startup
0x18 All Users Startup
0x19 All Users Desktop
0x1a Application Data
0x1b PrintHood
0x1c Local Settings Application Data
0x20 Local Settings Temporary Internet Files
0x21 Cookies
0x22 Local Settings History
0x23 All Users Application Data
0x24 Windows
0x25 System32
0x26 Program Files
0x27 My Pictures
0x28 User Profile
0x2b Common Files
0x2e All Users Templates
0x2f Administrative Tools
0x31 Network Connections


You can also use the .NET way in PowerShell: 

[System.Environment]::GetFolderPath("<SpecialFolder>")
  • Desktop
  • Programs
  • Personal
  • MyDocuments
  • Favorites
  • Startup
  • Recent
  • SendTo
  • StartMenu
  • MyMusic
  • DesktopDirectory
  • MyComputer
  • Templates
  • ApplicationData
  • LocalApplicationData
  • InternetCache
  • Cookies
  • History
  • CommonApplicationData
  • System
  • ProgramFiles
  • MyPictures
  • CommonProgramFiles

Between the following are the possible Enumeration values and their associated numeric values, the VBScript version appears to have more alternatives than the .NET version:
  •  0  Desktop 
  •  2  Programs 
  •  5  Personal 
  •  6  Favourites 
  •  7  Startup 
  •  8  Recent 
  •  9  SendTo 
  •  11 StartMenu 
  •  13 MyMusic 
  •  16 DesktopDirectory 
  •  17 MyComputer 
  •  21 Templates 
  •  26 ApplicationData 
  •  28 LocalApplicationData 
  •  32 InternetCache 
  •  33 Cookies 
  •  34 History 
  •  35 CommonApplicationData 
  •  37 System 
  •  38 ProgramFiles 
  •  39 MyPictures 
  •  43 CommonProgramFiles

Monday 28 November 2022

How to disable Windows PowerShell 2.0

There are multiple ways to disable the Windows PowerShell 2.0, I guess most of us know how to disable it using Windows feature turn on/off method so in this blog, I am going to demonstrate using command.

To check if PowerShell 2.0 Enabled:

1. DISM Command: DISM /online /get-features /format:table (or below command)
2. Get-WindowsOptionalFeature -Online -FeatureName MicrosoftWindowsPowerShellV2Root

Please using following command to Disable the Windows PowerShell 2.0

1. Disable-WindowsOptionalFeature -Online -FeatureName MicrosoftWindowsPowerShellV2Root (or below command)
2. DISM /online /Disable-Feature /FeatureName:"MicrosoftWindowsPowerShellV2Root"

Make sure you run the command as Administrator.

This command should turn off both "MicrosoftWindowsPowerShellV2Root" and "MicrosoftWindowsPowerShellV2," which correspond to "Windows PowerShell 2.0" and "Windows PowerShell 2.0 Engine" in the "Turn Windows features on or off" dialogue.



Wednesday 24 August 2022

Clear - CCMCache remotely using Configuration Manger Console & PowerShell Script

Have you ever needed to remotely clean the ccmcache folder on a computer? This blog article will explain how:

Step 1 - Add following PowerShell script in Software Library > Scripts:

## Initialize the CCM resource manager com object
[__comobject]$CCMComObject = New-Object -ComObject 'UIResource.UIResourceMgr'
## Get the CacheElementIDs to delete
$CacheInfo = $CCMComObject.GetCacheInfo().GetCacheElements()
## Remove cache items
ForEach ($CacheItem in $CacheInfo) {
$null = $CCMComObject.GetCacheInfo().DeleteCacheElement([string]$($CacheItem.CacheElementID))
}

Step 2 - In the Configuration Manager (SCCM/MECM) console, locate the computer. 
Step 3 - Click it with the right mouse button and select Run Script > Select the Script you added > Next. 
Step 4 - Wait for the process to complete, and monitor Script Status Monitoring for output.

FREE Cybersecurity Certifications

Here's 15 FREE courses provided by the Qualys. The cybersecurity firm Qualys focuses on providing cloud-based security and compliance so...