none
Inventory RRS feed

  • 질문

  • I would need script that user runs on computer and it would give information "User", "Serial", "Hostname"

    Also if possible it would add that info into to a excel or csv file. I would send this script to multiple users and when they run it, I would have excel list with that information. How would I go about it?

     
    2019년 4월 17일 수요일 오전 6:15

답변

  • Perhaps there are multiple profiles on the machine?

    Try this:

    $computer = Get-Content .\computerlist.txt
    $Output = Foreach($C in $computer){
        $System = Get-WmiObject Win32_ComputerSystem -ComputerName $C | Select-Object -Property Name
        $BIOS = Get-WmiObject Win32_BIOS -ComputerName $C | Select-Object -Property SerialNumber
        $DomainUsers = (Get-WmiObject Win32_NetworkLoginProfile -ComputerName $C).name -join ";"
        [PSCustomObject]@{
                ComputerName = $C
                Name = $System.Name
                SerialNumber = $BIOS.SerialNumber
                Users = $DomainUsers
            }
    }
    $Output
    $Output |Export-Csv -Path .\Result.csv -NoTypeInformation -Append


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)





    2019년 4월 18일 목요일 오후 3:50
  • You're correct. I've edited my post with corrected code.

    The correct line should have been (without the " | select name") :

    $DomainUsers=(Get-WmiObject Win32_NetworkLoginProfile -ComputerName $C).name -join ";"


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)


    2019년 4월 18일 목요일 오후 5:47

모든 응답

  • 2019년 4월 17일 수요일 오전 6:56
    중재자
  • Hi,

    Thanks for your question.

    You can get these informations by wmi. You may don't need to run the script on mutiple computers, just use powershell remotely to get these information.

    Please refer the link below:

    https://powershell.org/forums/topic/getting-computer-name-serial-number-and-model-of-list-of-machines/

    Best regards,

    Lee


    Just do it.

    2019년 4월 17일 수요일 오전 9:00
    중재자
  • Hi,

    I only have few users that I need to get that info and I only know their names. So I would really like to have script that I can send to my selected users and have them run it in order to get my inventory finished. Output should contain serial, hostname and username of the logged user, which you can get by "whoami" command. Also I can have hostname by using command "wmic computersystem  get name" and serial "wmic bios get serialnumber". I just need to compile script from those commands and have output on the shared network folder.

    Maybe it´s not powershell related at all, just cmd file

    2019년 4월 18일 목요일 오전 3:41
  • Hi,

    I only have few users that I need to get that info and I only know their names. So I would really like to have script that I can send to my selected users and have them run it in order to get my inventory finished. Output should contain serial, hostname and username of the logged user, which you can get by "whoami" command. Also I can have hostname by using command "wmic computersystem  get name" and serial "wmic bios get serialnumber". I just need to compile script from those commands and have output on the shared network folder.

    Maybe it´s not powershell related at all, just cmd file

    Again - we do not supply or write scripts on demand. The forum is for users who are trained in Windows and are writing scripts and have a question about a script they have written.

    Please look in the Gallery, for pre-written scripts.  If you do not know how to find scripts then please hire a consultant to help you.


    \_(ツ)_/

    2019년 4월 18일 목요일 오전 4:01
    중재자
  • I have this script in use and it is working otherwise fine, but there is a problem with csv output.                       

    $computer = Get-Content .\computerlist.txt

    $Output = Foreach($C in $computer){

    $System = Get-WmiObject Win32_ComputerSystem -ComputerName $C | Select-Object -Property Name

    $BIOS = Get-WmiObject Win32_BIOS -ComputerName $C | Select-Object -Property SerialNumber

    $DomainUsers = Get-WmiObject Win32_NetworkLoginProfile -ComputerName $C | Select-Object -Property Name
    [PSCustomObject]@{

    ComputerName = $C

    Name = $System.Name


    SerialNumber = $BIOS.SerialNumber

    Users = $DomainUsers.Name
    }

    }

    $Output



    $Output |Export-Csv -Path .\Result.csv -NoTypeInformation -Append

    Other information is correct, but the last one only shows "System.Object[]", it shows the user correct in Powershell window, but not in csv file.

    2019년 4월 18일 목요일 오후 3:26
  • Perhaps there are multiple profiles on the machine?

    Try this:

    $computer = Get-Content .\computerlist.txt
    $Output = Foreach($C in $computer){
        $System = Get-WmiObject Win32_ComputerSystem -ComputerName $C | Select-Object -Property Name
        $BIOS = Get-WmiObject Win32_BIOS -ComputerName $C | Select-Object -Property SerialNumber
        $DomainUsers = (Get-WmiObject Win32_NetworkLoginProfile -ComputerName $C).name -join ";"
        [PSCustomObject]@{
                ComputerName = $C
                Name = $System.Name
                SerialNumber = $BIOS.SerialNumber
                Users = $DomainUsers
            }
    }
    $Output
    $Output |Export-Csv -Path .\Result.csv -NoTypeInformation -Append


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)





    2019년 4월 18일 목요일 오후 3:50
  • Then it will only show ; in name

    If I run only this command and output it to CSV, it shows the name correct in CSV file

    Get-WmiObject Win32_NetworkLoginProfile -ComputerName NAME-OF-PC | Select-Object -Property Name


    • 편집됨 saulpomell 2019년 4월 18일 목요일 오후 4:56
    • 답변으로 표시됨 saulpomell 2019년 4월 19일 금요일 오전 5:15
    • 답변으로 표시 취소됨 saulpomell 2019년 4월 19일 금요일 오전 5:15
    2019년 4월 18일 목요일 오후 4:55
  • You're correct. I've edited my post with corrected code.

    The correct line should have been (without the " | select name") :

    $DomainUsers=(Get-WmiObject Win32_NetworkLoginProfile -ComputerName $C).name -join ";"


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)


    2019년 4월 18일 목요일 오후 5:47
  • Or …

    Get-Content .\computerlist.txt |
        ForEach-Object{
            $bios = Get-WmiObject Win32_BIOS -ComputerName $_
            [PSCustomObject]@{
                ComputerName = $_
                BIOSNAme = $bios.Name
                SerialNumber = $bios.SerialNumber
                Users = (Get-WmiObject Win32_NetworkLoginProfile -ComputerName $_).name -join ";"
            }
        } | 
        Export-Csv -Path .\Result.csv -NoTypeInformation


    \_(ツ)_/

    2019년 4월 18일 목요일 오후 6:23
    중재자