PowerShell version anomalies

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:

  1. Why does Windows PS ISE run fine on the UM790Pro and produce errors on the Dell XPS8920?
  2. Why does PS Core run exponentially longer than Windows PS?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật