Skip to content

Instantly share code, notes, and snippets.

@joegasper
Last active July 26, 2024 18:36
Show Gist options
  • Save joegasper/129dbf41dc9a5d42c8eef8daa97f08e7 to your computer and use it in GitHub Desktop.
Save joegasper/129dbf41dc9a5d42c8eef8daa97f08e7 to your computer and use it in GitHub Desktop.
RSAT apps - How to Remotely Install RSAT with PowerShell

How to remotely install RSAT tools with PowerShell

How to get around Access Denied COM object issue

Access is denied.

    + CategoryInfo          : NotSpecified: (:) [Add-WindowsCapability], COMException
    + FullyQualifiedErrorId : Microsoft.Dism.Commands.AddWindowsCapabilityCommand

Set up a virtual account on the remote computer

$comp = 'the-remote-pc-name'
# Connect to the remote computer
Enter-PSSession $comp
# Set up an unrestricted account configuration file:
New-PSSessionConfigurationFile -RunAsVirtualAccount -Path $env:TEMP\VirtualLocalAdmin.pssc
# Might need to reconnect after the following:
Register-PSSessionConfiguration -Name 'VirtualLocalAdmin' -Path $env:TEMP\VirtualLocalAdmin.pssc -Force
# List the config permissions:
Get-PSSessionConfiguration -Name 'VirtualLocalAdmin'
# The accounts/groups listed will have unrestricted access to the system via remote PowerShell.
# Using this virtual account will be acting as if a fully local admin.
Exit

From your local workstation connect to the remote computer and install RSAT tools

# Connect to the remote computer using the virtual account
Enter-PSSession $comp -ConfigurationName 'VirtualLocalAdmin'
# Pick one - all RSAT tools or the example of just ADUC:
# Add-WindowsCapability -Online -Name 'Rsat*' -Verbose
# Add-WindowsCapability -Online -Name 'Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0' -Verbose
# Output when successful: 
#   Online        : True
#   RestartNeeded : False
Exit

Clean up the virtual account configuration

# Connect to the remote computer
Enter-PSSession $comp
# Unregister the virtual account configuration
Unregister-PSSessionConfiguration -Name 'VirtualLocalAdmin'
# Remove the configuration file
Remove-Item $env:TEMP\VirtualLocalAdmin.pssc
Exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment