none
script keeps freezing at same spot RRS feed

  • Question

  • when running scripts i keep coming across the following issue - for example, if i run a script to gather the computer name, model, serial number etc from AD it gets stuck on 1 pc-- multiple scripts have the same issue.

    how can i adjust the following script to skip or pass the problem pc if it takes longer then lets say a minute to respond to the request from the script.

    below is an example of the script being used:


    Get-ADComputer -ResultPageSize 1000 -searchbase "OU" -filter * -Properties * | Sort-Object -property name |
         select @{N="Computer";E={$_.Name }},
                @{N="Memory";E={(Get-WmiObject -Class Win32_OperatingSystem -cn $_.Name).TotalVisibleMemorySize}},
                @{N="Model";E={(Get-WmiObject -Class Win32_computerSystem -cn $_.Name).Model}}, 
                @{N="Serial Number";E={(Get-WmiObject Win32_bios -cn $_.Name).SerialNumber}},
                @{N="Manufacturer"; E={(Get-WmiObject Win32_ComputerSystem -cn $_.Name).Manufacturer }} | export-csv C:\temp\pcinfo01.csv

    thank you.

    Thursday, December 19, 2013 9:28 PM

Answers

  • able to ping it. able to connect to it. but for some reason the script tends to freeze at that point. just started to happen. rebooted pc in question as well.

    Run WMIDiag on it.  It sounds like the repository might be corrupt.

    Try it this way. It will be faster and it will avoid some issues with multiple rapid WMI connections.

    Get-ADComputer -searchbase "OU"| 
         ForEach-Object{
                 $BIOS=Get-WmiObject Win32_bios -cn $_.Name
                 $OS=Get-WmiObject -Class Win32_OperatingSystem -cn $_.Name
                 $CS=Get-WmiObject -Class Win32_computerSystem -cn $_.Name
                 $props=@{
                      Computer=$_.Name
                      Memory=$OS.TotalVisibleMemorySize
                      Model=$CS.Model
                      SerialNumber=$BIOS.SerialNumber
                      Manufacturer=$CS.Manufacturer
                }
                New-Object PsObject -Property $props
         }
    


    ¯\_(ツ)_/¯

    Friday, December 20, 2013 1:19 PM

All replies

  • Does the problem PC respond to ping requests? If not, you can use this to skip machines that aren't responding:

    Get-ADComputer -Filter * -SearchBase 'OU=blah,DC=domain,DC=com'| ForEach {
    
        $pingCheck = Test-Connection $_.Name -Count 1 -Quiet
    
        If ($pingCheck) {
    
            Write-Host "$($_.Name ) is up, do your select in here."
    
        }
    
    }


    Don't retire TechNet! - (Don't give up yet - 12,420+ strong and growing)


    Thursday, December 19, 2013 9:46 PM
  • It's winter?


    ¯\_(ツ)_/¯

    Thursday, December 19, 2013 9:50 PM
  • Thursday, December 19, 2013 9:56 PM
  • able to ping it. able to connect to it. but for some reason the script tends to freeze at that point. just started to happen. rebooted pc in question as well.

    Friday, December 20, 2013 12:56 PM
  • able to ping it. able to connect to it. but for some reason the script tends to freeze at that point. just started to happen. rebooted pc in question as well.

    Run WMIDiag on it.  It sounds like the repository might be corrupt.

    Try it this way. It will be faster and it will avoid some issues with multiple rapid WMI connections.

    Get-ADComputer -searchbase "OU"| 
         ForEach-Object{
                 $BIOS=Get-WmiObject Win32_bios -cn $_.Name
                 $OS=Get-WmiObject -Class Win32_OperatingSystem -cn $_.Name
                 $CS=Get-WmiObject -Class Win32_computerSystem -cn $_.Name
                 $props=@{
                      Computer=$_.Name
                      Memory=$OS.TotalVisibleMemorySize
                      Model=$CS.Model
                      SerialNumber=$BIOS.SerialNumber
                      Manufacturer=$CS.Manufacturer
                }
                New-Object PsObject -Property $props
         }
    


    ¯\_(ツ)_/¯

    Friday, December 20, 2013 1:19 PM
  • To run against one computer for testing do this:
    @(@{Name='W8Test'})| 
         ForEach-Object{
                 $BIOS=Get-WmiObject Win32_bios -cn $_.Name
                 $OS=Get-WmiObject -Class Win32_OperatingSystem -cn $_.Name
                 $CS=Get-WmiObject -Class Win32_computerSystem -cn $_.Name
                 $props=@{
                      Computer=$_.Name
                      Memory=$OS.TotalVisibleMemorySize
                      Model=$CS.Model
                      SerialNumber=$BIOS.SerialNumber
                      Manufacturer=$CS.Manufacturer
                }
                New-Object PsObject -Property $props
         }
    
    


    ¯\_(ツ)_/¯

    Friday, December 20, 2013 1:21 PM