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日 15: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日 17: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日 15: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日 15: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日 16:56
    • 回答としてマーク saulpomell 2019年4月19日 5:15
    • 回答としてマークされていない saulpomell 2019年4月19日 5:15
    2019年4月18日 16: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日 17: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日 18:23
    モデレータ