/build/static/layout/Breadcrumb_cap_w.png

Scripting Question


Monitor size inventory

05/29/2018 577 views

-nologo -executionpolicy bypass -WindowStyle hidden -noprofile -file "monitor.ps1">  "C:\kbox\monitor.txt"

Hello,

 I found a power shell script that give me the serial number, model, make of the monitor on attached to the pc. I want to run this on our network and have the output save to a folder on c drive. Can someone help with the output save to c drive side. thank you.

here is the power Shell script:

function Decode {

If ($args[0] -is [System.Array]) {

[System.Text.Encoding]::ASCII.GetString($args[0])

}

    Else {

"Not Found"

}

}

echo "Name, Serial"

ForEach ($Monitor in Get-WmiObject WmiMonitorID -Namespace root\wmi) { 

$Name = Decode $Monitor.UserFriendlyName -notmatch 0

$Serial = Decode $Monitor.SerialNumberID -notmatch 0

$Manufacturer = Decode $Monitor.ManufacturerName -notmatch 0

$User = $Monitor.PSComputerName

echo "$User, $Manufacturer, $Name, $Serial"

}





3 Comments   [ + ] Show comments

Comments

  • how about running it with putting the result to a file like: powershell yourscript.ps >file.txt
  • add more information and does not save to c:\kbox\monitors.
  • ok it pulls the information to the folder as a txt file. I'm able to see the txt file looks great.
    KDEBIASSE; DELL P2213 ; FP04F3AVD3VS
    KDEBIASSE; DELL P2210 ; 6H6FX22EBKTM
    but when I do inventory on the file:
    ShellCommandTextReturn(cmd /c type c:\KBOX\monitors.txt)
    nothing comes up:
    4) Monitor Inventory PS: KDEBIASSE; DELL P2213TM [string]
    I'm able to get other txt file into inventory lists:
    Printer_list: 5/30/2018 4:17:46 PM - Logged in user: kdebiasse
    ------------------------------------------------------
    Send To OneNote 16
    Microsoft XPS Document Writer
    Microsoft Print to PDF
    Fax
    Adobe PDF
    \\admcprint1\ITCopyRoom
    \\admcprint2\IThpP3005

All Answers

1
Hello,

This will print the results to a text file called "psresults" in the root of C:
$(function Decode {
If ($args[0] -is [System.Array]) {
[System.Text.Encoding]::ASCII.GetString($args[0])
}
    Else {
"Not Found"

}
}
echo "Name, Serial"
ForEach ($Monitor in Get-WmiObject WmiMonitorID -Namespace root\wmi) { 
$Name = Decode $Monitor.UserFriendlyName -notmatch 0
$Serial = Decode $Monitor.SerialNumberID -notmatch 0
$Manufacturer = Decode $Monitor.ManufacturerName -notmatch 0
$User = $Monitor.PSComputerName
echo "$User, $Manufacturer, $Name, $Serial"


) *>&1 > C:\psresults.txt
Answered 05/30/2018 by: Channeler
Red Belt

  • Does not work. get error:
    At C:\Users\kdebiasse\Desktop\monitor.ps1:21 char:1
    + ) *>&1 > C:\psresults.txt
    + ~
    Unexpected token ')' in expression or statement.
    + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx
    ception
    + FullyQualifiedErrorId : UnexpectedToken
    • retried, works fine here.

      1-Make sure you are running PS as administrator

      2- Make sure you are running the Script on a Physical Device, for VMs will not work

      See:
      https://imgur.com/a/5OQfbhA
      • Running as admin is only needed because the file is being saved to c:\. Just change the location off of root and it'll save with a non elevated PS. Otherwise it works fine for me.
  • Thank you I found what was wrong. I did not put $(function .... in the beginning. It is working.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ