The script at the end of the post seems to have different problems based on the machine it is running on and the Version of PowerShell (Windows vs Core). Here is the digest of results with all pertinent machine/OS/PS information.
Edition: Microsoft Windows 11 Pro 64-bit
Version: 2009 23H2
Build: 22631.3593 (May Updates)
Installed: 2/29/2024 10:20
Dell XPS 8920 i7-7700 32Gb DDR4 Dual Channel
Get-ChildItem : The specified path, file name, or both are too long. The fully
qualified file name must be less than 260 characters, and the directory name
must be less than 248 characters.
At G:BEKDocsScriptsFile ManipulationGet-WinSettingsAppsV3.ps1:108 char:13
+ $CtrlObjs = Get-ChildItem @GCIArgs |
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-ChildItem], PathTooLongEx
ception
+ FullyQualifiedErrorId : System.IO.PathTooLongException,Microsoft.PowerSh
ell.Commands.GetChildItemCommand
The variable '$CtrlObjs' cannot be retrieved because it has not been set.
At G:BEKDocsScriptsFile ManipulationGet-WinSettingsAppsV3.ps1:113 char:16
+ For ($Cntr = $($CtrlObjs.count - 1); $Cntr -ge 0; $Cntr--) {
+ ~~~~~~~~~
+ CategoryInfo : InvalidOperation: (CtrlObjs:String) [], RuntimeE
xception
+ FullyQualifiedErrorId : VariableIsUndefined
Index was out of range. Must be non-negative and less than the size of the
collection.
Parameter name: index
At G:BEKDocsScriptsFile ManipulationGet-WinSettingsAppsV3.ps1:132 char:1
+ [Void]$FinalList.Add(($SettingObjs[0]))
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], ArgumentOutOfRangeExce
ption
+ FullyQualifiedErrorId : System.ArgumentOutOfRangeException
Program Vers : 3.0
Powershell Vers: 5.1.22621.2506 (ISE)
Run Time : 00:23
Setting Pgms : 0
--------------------------------------------
Program Vers : 3.0
Powershell Vers: 5.1.22621.2506 (CLI)
Run Time : 00:41
Setting Pgms : 43
Name Path
---- ----
appwiz.cpl C:WindowsSystem32
bthprops.cpl C:WindowsSystem32
...
WF.msc C:WindowsSystem32en-US
WmiMgmt.msc C:WindowsSystem32
-----------------------------------------------
Program Vers : 3.0
Powershell Vers: 7.4.2
Run Time : 26:22
Setting Pgms : 43
Name Path
---- ----
appwiz.cpl C:WindowsSystem32
bthprops.cpl C:WindowsSystem32
...
WF.msc C:WindowsSystem32
WmiMgmt.msc C:WindowsSystem32
===================================================
MinsiForum UM790 Pro Ryzen 7940HS 32Gb DDR5 Dual Channel
Edition: Microsoft Windows 11 Pro 64-bit
Version: 2009 23H2
Build: 22631.3593 (May Updates)
Program Vers : 3.0
Powershell Vers: 5.1.22621.2506 (ISE)
Run Time : 00:34
Setting Pgms : 41
Name Path
---- ----
appwiz.cpl C:WindowsSystem32
bthprops.cpl C:WindowsSystem32
...
WF.msc C:WindowsSystem32en-US
WmiMgmt.msc C:WindowsSystem32
-----------------------------------------------------
Program Vers : 3.0
Powershell Vers: 5.1.22621.2506 (CLI)
Run Time : 00:22
Setting Pgms : 41
Name Path
---- ----
appwiz.cpl C:WindowsSystem32
bthprops.cpl C:WindowsSystem32
...
WF.msc C:WindowsSystem32
WmiMgmt.msc C:WindowsSystem32en-US
-----------------------------------------------------
Program Vers : 3.0
Powershell Vers: 7.4.2
Run Time : 22:43
Setting Pgms : 41
Name Path
---- ----
appwiz.cpl C:WindowsSystem32
bthprops.cpl C:WindowsSystem32
,,,
WF.msc C:WindowsSystem32en-US
WmiMgmt.msc C:WindowsSystem32
Here’s the code:
Param (
[Parameter(Mandatory=$False)]
[Switch] $Report
)
Function Get-AdminStatus {
$identity =
[Security.Principal.WindowsIdentity]::GetCurrent()
$principal =
New-Object Security.Principal.WindowsPrincipal $identity
If (-NOT ($principal.IsInRole(
[Security.Principal.WindowsBuiltinRole]::Administrator)))
{"User"}
Else
{"Administrator"}
} #End Function ----------- Get-AdminStatus ------------------
#------------------------ Main Program ------------------------
Clear-Host
$PgmVers = [Version]"3.0"
$Message = ""
$Title = ""
Add-Type -AssemblyName "System.Windows.Forms"
$Top =
new-Object System.Windows.Forms.Form -property @{Topmost=$true}
$TermMsg = {
[Windows.Forms.MessageBox]::Show($Top, $Message, $Title,
[Windows.Forms.MessageBoxButtons]::OK ,
[Windows.Forms.MessageBoxIcon]::Information)}
If ( (Get-AdminStatus) -eq "User") {
$Message =
"Program REQUIRES Powershell to be run`n" +
"as Administrator!"
$Title = "Administrator Access REQUIRED...Terminating!"
$Button = "OK"
$Icon = "Error"
$Null = & $TermMsg
Exit
}
$RunStartTime = Get-Date
# Create lists to hold .cpl & .msc files
$SettingObjs = new-object System.Collections.Generic.List[Object]
$FinalList = new-object System.Collections.Generic.List[Object]
$GCIArgs = @{Path = "C:"
Recurse = $True
File = $True
Include = "*.cpl","*.msc"
ErrorAction = "SilentlyContinue"
}
$CtrlObjs = Get-ChildItem @GCIArgs |
Sort-Object Extension,Name -Descending
# Loop through each Array Element and weed out copies
For ($Cntr = $($CtrlObjs.count - 1); $Cntr -ge 0; $Cntr--) {
$TestVal = ($CtrlObjs[$Cntr].DirectoryName)
If ($TestVal -NotMatch
"SysWOW64|WinSxS|DriverStore|Distribution") {
[Void]$SettingObjs.Add([PSCustomObject]@{
Name = $($CtrlObjs[$($Cntr)].Name)
Path = $($CtrlObjs[$($Cntr)].DirectoryName)
Ext = $($CtrlObjs[$($Cntr)].Extension)
})
} #End If
} #End For
#Remove Duplicates from the list
[Void]$FinalList.Add(($SettingObjs[0]))
For ($Cntr = 1; $Cntr -lt $SettingObjs.Count; $Cntr++) {
If (-Not ($SettingObjs[$($Cntr-1)].Name -eq
($SettingObjs[$($Cntr)].Name))) {
[Void]$FinalList.Add(($SettingObjs[$($Cntr)]))
}
}
$RunTime = ((Get-Date) - $RunStartTIme)
#Generate Report Content Variable
$RptCont =
"Program Vers : $PgmVers`n" +
"Powershell Vers: $($PSVersionTable.PSVersion)`n" +
"$("Run Time : {0:mm}:{0:ss}" -f $RunTime)`n" +
"Setting Pgms : $($FInalList.count)" | Out-String
$RptCont += $FinalList | FT -Property Name, Path |
Out-String
If ($Report.IsPresent) {
$ReportFile =
"$([environment]::getfolderpath("mydocuments"))" +
"Windows Setting Pgms Output.txt"
$RptCont > $ReportFile
}
Else {
$RptCont
}
Comment based help stripped out as post is already too long.
So my actual questions:
- Why does Windows PS ISE run fine on the UM790Pro and produce errors on the Dell XPS8920?
- Why does PS Core run exponentially longer than Windows PS?