For a while now I've wanted to load the RSAT (Windows Remote Server Administration Tools) tool I use daily via a script at logon, but as my admin user account, not my normal logon. There are numerous posts on the web about doing that but with the later versions of PowerShell most of those don't work. Windows 10 doesn't help.
I'm sure there are better ways of doing this but after trying the suggestions I found on the web I hit on a combination that works. The full script and all future updates are on my PowerShell Library site here:
https://www.powershellgallery.com/profiles/Kcmjr
I call the script "RSAT-As-Admin.ps1". It includes a list of RSAT tools that you must adjust to suit your needs. The way it's written you can add additional executables easily if desired.
Here is the code from release v1.00. Updates will be posted at the link,above.
Param(
[Switch]$Console = $false
#--[
Set to true to enable local console result display. Defaults to false ]--
)
<#==============================================================================
File Name : RSAT-As-Admin.ps1
Original Author : Kenneth C. Mazie (kcmjr AT
kcmjr.com)
:
Description : Automatically loads
specified Windows RSAT AD Admin tools using the user ID you specify.
:
Notes : Normal operation is with no
command line options. The list of RSAT tools below
: should be commented in/out
as needed. Tested on Windows 10 1803
only.
:
Arguments : Command line options for
testing:
: - "-console $true"
will enable local console echo
:
Warnings : None
:
Legal : Public Domain. Modify and
redistribute freely. No rights reserved.
: SCRIPT PROVIDED "AS
IS" WITHOUT WARRANTIES OR GUARANTEES OF
: ANY KIND. USE AT YOUR OWN
RISK. NO TECHNICAL SUPPORT PROVIDED.
: That being said, please
let me know if you find bugs or improve the script.
:
Credits : Code snippets and/or ideas
came from many sources including but
: not limited to the
following: n/a
:
Last Update by : Kenneth C. Mazie
Version History : v1.0 - 09-24-18 - Original
Change History : v1.1 - 00-00-00 -
:
==============================================================================#>
<#PSScriptInfo
.VERSION 1.00
.GUID
75f90821-5799-44ed-af38-bc4e05f9e385
.AUTHOR Kenneth C.
Mazie (kcmjr AT kcmjr.com)
.DESCRIPTION
Automatically loads
specified Windows RSAT AD Admin tools using the user ID you specify.
#>
#Requires -Version 5.1
Clear-Host
$Script:Credential = ""
$ThisDomain = (Get-ADDomain).DNSroot
$Credential = Get-Credential #-Credential
"domain\username"
#------------------------------------------------------------------------------------------------------
$ToolList = @() #--[ Array of separate items to allow easy
addition or removal. Comment out lines for tools you don't want loaded ]--
#$ToolList +=
"dsac.exe" #--[
Active Directory Administrative Center
]--
$ToolList += "dsa.msc" #--[ Active Directory Users and
Computers ]--
#$ToolList +=
"domain.msc" #--[
Active Directory Domains and Trusts
]--
#$ToolList +=
"dssite.msc" #--[
Active Directory Sites and Services
]--
$ToolList += "gpmc.msc" #--[ Group Policy Management ]--
$ToolList += "dhcpmgmt.msc" #--[ DHCP Manager ]--
$ToolList += "dnsmgmt.msc" #--[ DNS Manager ]--
$ToolList += "dfsmgmt.msc" #--[ DFS Manager ]--
#$ToolList +=
"vmw.exe" #--[ Volume
Activation Tools
]--
#$ToolList +=
"printmanagement.msc" #--[
Print Management
]--
#$ToolList +=
"nlbmgr.exe" #--[
Network Load Balancing Manager
]--
#$ToolList +=
"secpol.msc /s" #--[
Local Security Policy
]--
#$ToolList +=
"iscsicpl.exe" #--[
iSCSI Initiator
]--
#$ToolList +=
"fsrm.msc" #--[
File Server Resource Manager
]--
#$ToolList +=
"Cluadmin.msc" #--[
Failover Cluster Manager
]--
#$ToolList +=
"ClusterUpdateUI.exe" #--[
Cluster Aware Updating
]--
#$ToolList +=
"certsrv.msc" #--[
Certification Authority
]--
#$ToolList +=
"adsiedit.msc" #--[
ADSI Edit
]--
#--------------------------------------------------------------------------------------------------------
$ToolPath = "c:\windows\system32\"
[Environment]::CurrentDirectory
= (Get-Location -PSProvider
FileSystem).ProviderPath
$Result = disable-UEV
#--[ Microsoft UE-V
(User Experience Virtualization) is a tool that enables users to move from one
Windows ]--
#--[ device to
another and maintain the same operating system (OS) and applications settings.
(i.e roaming) ]--
If ($Result -Like "*successfully*"){
If ($Console){Write-host $Result -Foregroundcolor Green}
}Else{
If ($Console){Write-Host "There was an error disabling
UE-V"
-ForegroundColor Red}
}
ForEach ($Tool in $ToolList){
write-host "`n-------------------------------------------------------------------`n"
If ($Tool.Split(" ").count -gt 1){ #--[ There is a space in the tool command
meaning some sort of argument ]--
$Arg = $Tool.Split(" ")[1]
$Tool = $Tool.Split(" ")[0]
If ($Tool.Split('.')[1] -eq "exe"){
$Command = 'Start-Process "'+($ToolPath+$Tool+" "+$Arg)+'" -verb
runas'
}Else{
$Command = 'Start-Process mmc.exe -verb runas
-argument "'+($ToolPath+$Tool+" "+$Arg)+'"'
}
}Else{
If ($Tool.Split('.')[1] -eq "exe"){
$Command = 'Start-Process '+($ToolPath+$Tool)+' -verb runas'
}Else{
$Command = 'Start-Process mmc.exe -verb runas
-argument '+($ToolPath+$Tool)
}
}
#$Command
#--[ Un-comment to display the resultant command line ]--
If (Test-Path -Path ($ToolPath+$Tool)) {
Start-Process powershell.exe -Credential $Credential -NoNewWindow
-ArgumentList $Command
If ($Console){write-host "Tool $Tool is starting..." -ForegroundColor
Green}
}Else{
If ($Console){write-host "Tool $Tool was not found..." -ForegroundColor
Red}
}
}