Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2314

Aprosh admin tool

$
0
0

Guten Tag Peter,

Du hattest mir mal einen code bereitgestellt um lokalle Benutzer in einem GUI listview aufzulisten.

Der code funktioniert sehr gut obwohl immer ein Fehler generiert wird den ich nicht verstehe und damit auch nicht beseitigne kann.

1218 heisst wohl Zeile und 80 heisst wohl Zeichen 80?

Vielleicht kannst Du etwas Licht in die Dunkelheit bringen?

Fehlermeldung: Exception calling.... und Catch

Habe Catch einfach mal mit # Catch ausgeblendet und der Fehler ist weg würde mich aber interessieren warum Du in eingeben hast wenn er "keine Funktion" hat bezw. nicht benötigt wird.

Kann zumindest nicht feststellen, dass irgendetwas nicht funktioniert nachdem ich catch ausgeblendet habe. 

der gleiche Fehler tritt auch unter anderen Benutzerkonten auf

\\LT-0421I-ECB\root\cimv2:Win32_Group.Domain="LT-0421I-ECB",Name="Administrators"

Exception calling "Add" with "1" argument(s): "Object reference not set to an instance of an

object."

At C:\Users\sa_ringfri\Documents\WindowsPowerShell\Windows System Administration Tool.ps1:1218

char:80

+                 ForEach ($Col in ($lvMain.Columns | ?{$_.Index -ne 0})){$Field = $Col.Text;$ ...

+                                                                                           ~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : NullReferenceException

 

Exception calling "Add" with "1" argument(s): "Object reference not set to an instance of an

object."

At C:\Users\sa_ringfri\Documents\WindowsPowerShell\Windows System Administration Tool.ps1:1218

char:80

+                 ForEach ($Col in ($lvMain.Columns | ?{$_.Index -ne 0})){$Field = $Col.Text;$ ...

+                                                                                            ~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : NullReferenceException

 

Exception calling "Add" with "1" argument(s): "Object reference not set to an instance of an

object."

At C:\Users\sa_ringfri\Documents\WindowsPowerShell\Windows System Administration Tool.ps1:1218

char:80

+                 ForEach ($Col in ($lvMain.Columns | ?{$_.Index -ne 0})){$Field = $Col.Text;$ ...

+                                                                                            ~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : NullReferenceException

 

Catch : The term 'Catch' is not recognized as the name of a cmdlet, function, script file, or

operable program. Check the spelling of the name, or if a path was included, verify that the path

is correct and try again.

At C:\Users\sa_ringfri\Documents\WindowsPowerShell\Windows System Administration Tool.ps1:1224

char:3

+         Catch{$SBPStatus.Text = "[$ComputerName] Error: Could not retrieve local admin ...

+         ~~~~~

    + CategoryInfo          : ObjectNotFound: (Catch:String) [], CommandNotFoundException

    + FullyQualifiedErrorId : CommandNotFoundException


Code:

    $btnLocalUsersGroups_Click={

             Get-ComputerName

             Initialize-Listview

             $SBPStatus.Text="Retrieving Local Users and Groups..."

       Update-ContextMenu (Get-VariablecmsUser*)

             

             'Type','Name','Domain','SID'|ForEach-Object {Add-Column$_}

             

             $LocalUsers=Get-WmiObject-computername$ComputerName-query "Select * from Win32_UserAccount Where LocalAccount = True"

             

             ForEach($LocalUserin$LocalUsers) {

                    $Item= New-ObjectSystem.Windows.Forms.ListViewItem('LocalUser')

                    $Item.SubItems.Add($LocalUser.Name)

                    $Item.SubItems.Add($LocalUser.Domain)

                    $Item.SubItems.Add($LocalUser.SID)

                    $lvMain.Items.Add($Item)

              }

             

             $LocalGroups=Get-WmiObject-computername$ComputerName-query"SELECT * FROM Win32_Group Where Domain='$ComputerName'"

             

             ForEach($LocalGroupin$LocalGroups) {

             Write-Host$LocalGroup

                    $Item= New-ObjectSystem.Windows.Forms.ListViewItem('Group')

           $Item.BackColor="Red"

           $Item.ForeColor="Yellow"

                    $NewItem=$Item.SubItems.Add($LocalGroup.Name)

                    $NewItem.BackColor="Red"

           $NewItem.ForeColor="Yellow"

                    $NewItem=$Item.SubItems.Add($LocalGroup.Domain)

                    $NewItem.BackColor="Red"

           $NewItem.ForeColor="Yellow"

                    $NewItem=$Item.SubItems.Add($LocalGroup.SID)

                    $NewItem.BackColor="Red"

           $NewItem.ForeColor="Yellow"

                    $lvMain.Items.Add($Item)

      #            

      # Direkte User in Gruppen auflösen

      #

             $GroupUsers=Get-WmiObject-computername$ComputerName-Query"SELECT * FROM Win32_GroupUser WHERE GroupComponent=`"Win32_Group.Domain='$Computername',Name='$($LocalGroup.Name)'`""|Foreach-Object {[wmi]$_.PartComponent}

                    If($GroupUsers) {

                          ForEach($GroupUserin$GroupUsers) {

                                 $Item= New-ObjectSystem.Windows.Forms.ListViewItem('GroupMember')

                                 $Item.SubItems.Add($GroupUser.Name)

                                 $Item.SubItems.Add($GroupUser.Domain)

                                 $Item.SubItems.Add($GroupUser.SID)

                                 $lvMain.Items.Add($Item)

                           }

                    $Info| %{

                          $Item= New-ObjectSystem.Windows.Forms.ListViewItem($_.$Col0)

                    

1218     ForEach ($Colin ($lvMain.Columns|?{$_.Index-ne0})){$Field=$Col.Text;$Item.SubItems.Add($_.$Field)}

                          $lvMain.Items.Add($Item)

                     }

                    

                    $SBPStatus.Text="Ready"

                     }

??? # Catch

            {$SBPStatus.Text="[$ComputerName] Error: Could not retrieve local administrators."}

       } 

Vorab vielen Dank



Viewing all articles
Browse latest Browse all 2314


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>