Solved

Help modifying powershell script to use credentials

Posted on 2013-12-18
8
830 Views
Last Modified: 2013-12-18
Can someone help me modify this script so it allows me to supply the administrator password for the ip i enter
for instance if i want to go to 192.168.1.2 i need to give it administrator:adm!n or something like that

thanks!
#########################################################
#           Powershell PC Info Script V1.0b             #
#              Coded By:Trenton Ivey(kno)               #
#                     hackyeah.com                      #
#########################################################

function Pause ($Message="Press any key to continue..."){
    ""
    Write-Host $Message
    $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}


function GetCompName{
    $compname = Read-Host "Please enter a computer name or IP"
    CheckHost
}

function CheckHost{
    $ping = gwmi Win32_PingStatus -filter "Address='$compname'"
    if($ping.StatusCode -eq 0){$pcip=$ping.ProtocolAddress; GetMenu}
    else{Pause "Host $compname down...Press any key to continue"; GetCompName}
}
    


function GetMenu {
    Clear-Host
    "  /----------------------\"
    "  |     PC INFO TOOL     |"
    "  \----------------------/"
    "  $compname ($pcip)"
    ""
    ""
    "1) PC Serial Number"
    "2) PC Printer Info"
    "3) Current User"
    "4) OS Info"
    "5) System Info"
    "6) Add/Remove Program List"
    "7) Process List"
    "8) Service List"
    "9) USB Devices"
    "10) Uptime"
    "11) Disk Space"
    "12) Memory Info"
    "13) Processor Info"
    "14) Monitor Serial Numbers"
    ""
    "C) Change Computer Name"
    "X) Exit The program"
    ""
    $MenuSelection = Read-Host "Enter Selection"
    GetInfo
}


function GetInfo{
    Clear-Host
    switch ($MenuSelection){
        1 { #PC Serial Number
            gwmi -computer $compname Win32_BIOS | Select-Object SerialNumber | Format-List
            Pause
            CheckHost
          }
          
        2 { #PC Printer Information
            gwmi -computer $compname Win32_Printer | Select-Object DeviceID,DriverName, PortName | Format-List
            Pause
            CheckHost          
          }
          
        3 { #Current User
            gwmi -computer $compname Win32_ComputerSystem | Format-Table @{Expression={$_.Username};Label="Current User"}
            ""
            #May take a very long time if on a domain with many users
            #"All Users"
            #"------------"
            #gwmi -computer $compname Win32_UserAccount | foreach{$_.Caption}
            Pause
            CheckHost          
          }
          
        4 { #OS Info
            gwmi -computer $compname Win32_OperatingSystem | Format-List @{Expression={$_.Caption};Label="OS Name"},SerialNumber,OSArchitecture
            Pause
            CheckHost       
          }
          
        5 { #System Info
            gwmi -computer $compname Win32_ComputerSystem | Format-List Name,Domain,Manufacturer,Model,SystemType
            Pause
            CheckHost         
          }        
          
        6 { #Add/Remove Program List
            gwmi -computer $compname Win32_Product | Sort-Object Name | Format-Table Name,Vendor,Version
            Pause
            CheckHost
          }
          
        7 { #Process Listx
        
            gwmi -computer $compname Win32_Process | Select-Object Caption,Handle | Sort-Object Caption | Format-Table
            Pause
            CheckHost         
          }
          
        8 { #Service List
            gwmi -computer $compname Win32_Service | Select-Object Name,State,Status,StartMode,ProcessID, ExitCode | Sort-Object Name | Format-Table
            Pause
            CheckHost        
          }
        
        9 { #USB Devices
            gwmi -computer $compname Win32_USBControllerDevice | %{[wmi]($_.Dependent)} | Select-Object Caption, Manufacturer, DeviceID | Format-List
            Pause
            CheckHost          
          }
          
        10 { #Uptime
            $wmi = gwmi -computer $compname Win32_OperatingSystem
            $localdatetime = $wmi.ConvertToDateTime($wmi.LocalDateTime)
            $lastbootuptime = $wmi.ConvertToDateTime($wmi.LastBootUpTime)
            
            "Current Time:      $localdatetime"
            "Last Boot Up Time: $lastbootuptime"
            
            $uptime = $localdatetime - $lastbootuptime
            ""
            "Uptime: $uptime"
            Pause
            CheckHost
          }
        11 { #Disk Info
            $wmi = gwmi -computer $compname Win32_logicaldisk
            foreach($device in $wmi){
                    Write-Host "Drive: " $device.name   
                    Write-Host -NoNewLine "Size: "; "{0:N2}" -f ($device.Size/1Gb) + " Gb"
                    Write-Host -NoNewLine "FreeSpace: "; "{0:N2}" -f ($device.FreeSpace/1Gb) + " Gb"
                    ""
             }
            Pause
            CheckHost
          }
        12 { #Memory Info
            $wmi = gwmi -computer $compname Win32_PhysicalMemory
            foreach($device in $wmi){
                Write-Host "Bank Label:     " $device.BankLabel
                Write-Host "Capacity:       " ($device.Capacity/1MB) "Mb"
                Write-Host "Data Width:     " $device.DataWidth
                Write-Host "Device Locator: " $device.DeviceLocator    
                ""        
            }
            Pause
            CheckHost
          }
        13 { #Processor Info
            gwmi -computer $compname Win32_Processor | Format-List Caption,Name,Manufacturer,ProcessorId,NumberOfCores,AddressWidth  
            Pause
            CheckHost
          }
        14 { #Monitor Info
            
            #Turn off Error Messages
            $ErrorActionPreference_Backup = $ErrorActionPreference
            $ErrorActionPreference = "SilentlyContinue"


            $keytype=[Microsoft.Win32.RegistryHive]::LocalMachine
            if($reg=[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($keytype,$compname)){
                #Create Table To Hold Info
                $montable = New-Object system.Data.DataTable "Monitor Info"
                #Create Columns for Table
                $moncol1 = New-Object system.Data.DataColumn Name,([string])
                $moncol2 = New-Object system.Data.DataColumn Serial,([string])
                $moncol3 = New-Object system.Data.DataColumn Ascii,([string])
                #Add Columns to Table
                $montable.columns.add($moncol1)
                $montable.columns.add($moncol2)
                $montable.columns.add($moncol3)



                $regKey= $reg.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\DISPLAY" )
                $HID = $regkey.GetSubKeyNames()
                foreach($HID_KEY_NAME in $HID){
                    $regKey= $reg.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\DISPLAY\\$HID_KEY_NAME" )
                    $DID = $regkey.GetSubKeyNames()
                    foreach($DID_KEY_NAME in $DID){
                        $regKey= $reg.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\DISPLAY\\$HID_KEY_NAME\\$DID_KEY_NAME\\Device Parameters" )
                        $EDID = $regKey.GetValue("EDID")
                        foreach($int in $EDID){
                            $EDID_String = $EDID_String+([char]$int)
                        }
                        #Create new row in table
                        $monrow=$montable.NewRow()
                        
                        #MonitorName
                        $checkstring = [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFC + [char]0x00           
                        $matchfound = $EDID_String -match "$checkstring([\w ]+)"
                        if($matchfound){$monrow.Name = [string]$matches[1]} else {$monrow.Name = '-'}

                        
                        #Serial Number
                        $checkstring = [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFF + [char]0x00           
                        $matchfound =  $EDID_String -match "$checkstring(\S+)"
                        if($matchfound){$monrow.Serial = [string]$matches[1]} else {$monrow.Serial = '-'}
                                                
                        #AsciiString
                        $checkstring = [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFE + [char]0x00           
                        $matchfound = $EDID_String -match "$checkstring([\w ]+)"
                        if($matchfound){$monrow.Ascii = [string]$matches[1]} else {$monrow.Ascii = '-'}         

                                
                        $EDID_String = ''
                        
                        $montable.Rows.Add($monrow)
                    }
                }
                $montable | select-object  -unique Serial,Name,Ascii | Where-Object {$_.Serial -ne "-"} | Format-Table 
            } else { 
                Write-Host "Access Denied - Check Permissions"
            }
            $ErrorActionPreference = $ErrorActionPreference_Backup #Reset Error Messages
            Pause
            CheckHost
          }
        1337 { Write-Host "Program Made By Trenton Ivey (Trenton@hackyeah.com)";Pause; CheckHost}
        c {Clear-Host;$compname="";GetCompName}
        x {Clear-Host; exit}
        default{CheckHost}
      }
}

#---------Start Main--------------
$compname = $args[0]
if($compname){CheckHost}
else{GetCompName}]

Open in new window

0
Comment
Question by:bbimis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 300 total points
ID: 39727322
Use
$creds = Get-Credential

This will prompt for your credentials.

Then modify each
gwmi -computer $compname
to
gwmi -computer $compname -credentials $creds

HTH,
Dan
0
 

Author Comment

by:bbimis
ID: 39727343
I get this error
Get-WmiObject : A positional parameter cannot be found that accepts argument
'System.Management.Automation.PSCredential'.
At C:\push script\myscript.ps1:64 char:13
+             gwmi -computer $compname - credentials $creds  Win32_BIOS | Select-O ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-WmiObject], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Here is my modified code:
#########################################################
#           Powershell PC Info Script V1.0b             #
#              Coded By:Trenton Ivey(kno)               #
#                     hackyeah.com                      #
#########################################################

$creds = Get-Credential

function Pause ($Message="Press any key to continue..."){
    ""
    Write-Host $Message
    $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}


function GetCompName{
    $compname = Read-Host "Please enter a computer name or IP"
    CheckHost
}

function CheckHost{
    $ping = gwmi Win32_PingStatus -filter "Address='$compname'"
    if($ping.StatusCode -eq 0){$pcip=$ping.ProtocolAddress; GetMenu}
    else{Pause "Host $compname down...Press any key to continue"; GetCompName}
}
    


function GetMenu {
    Clear-Host
    "  /----------------------\"
    "  |     PC INFO TOOL     |"
    "  \----------------------/"
    "  $compname ($pcip)"
    ""
    ""
    "1) PC Serial Number"
    "2) PC Printer Info"
    "3) Current User"
    "4) OS Info"
    "5) System Info"
    "6) Add/Remove Program List"
    "7) Process List"
    "8) Service List"
    "9) USB Devices"
    "10) Uptime"
    "11) Disk Space"
    "12) Memory Info"
    "13) Processor Info"
    "14) Monitor Serial Numbers"
    ""
    "C) Change Computer Name"
    "X) Exit The program"
    ""
    $MenuSelection = Read-Host "Enter Selection"
    GetInfo
}


function GetInfo{
    Clear-Host
    switch ($MenuSelection){
        1 { #PC Serial Number
            gwmi -computer $compname - credentials $creds  Win32_BIOS | Select-Object SerialNumber | Format-List
            Pause
            CheckHost
          }
          
        2 { #PC Printer Information
            gwmi -computer $compname - credentials $creds Win32_Printer | Select-Object DeviceID,DriverName, PortName | Format-List
            Pause
            CheckHost          
          }
          
        3 { #Current User
            gwmi -computer $compname - credentials $creds Win32_ComputerSystem | Format-Table @{Expression={$_.Username};Label="Current User"}
            ""
            #May take a very long time if on a domain with many users
            #"All Users"
            #"------------"
            #gwmi -computer $compname - credentials $creds Win32_UserAccount | foreach{$_.Caption}
            Pause
            CheckHost          
          }
          
        4 { #OS Info
            gwmi -computer $compname - credentials $creds Win32_OperatingSystem | Format-List @{Expression={$_.Caption};Label="OS Name"},SerialNumber,OSArchitecture
            Pause
            CheckHost       
          }
          
        5 { #System Info
            gwmi -computer $compname - credentials $creds Win32_ComputerSystem | Format-List Name,Domain,Manufacturer,Model,SystemType
            Pause
            CheckHost         
          }        
          
        6 { #Add/Remove Program List
            gwmi -computer $compname - credentials $creds Win32_Product | Sort-Object Name | Format-Table Name,Vendor,Version
            Pause
            CheckHost
          }
          
        7 { #Process Listx
        
            gwmi -computer $compname - credentials $creds Win32_Process | Select-Object Caption,Handle | Sort-Object Caption | Format-Table
            Pause
            CheckHost         
          }
          
        8 { #Service List
            gwmi -computer $compname - credentials $creds Win32_Service | Select-Object Name,State,Status,StartMode,ProcessID, ExitCode | Sort-Object Name | Format-Table
            Pause
            CheckHost        
          }
        
        9 { #USB Devices
            gwmi -computer $compname - credentials $creds Win32_USBControllerDevice | %{[wmi]($_.Dependent)} | Select-Object Caption, Manufacturer, DeviceID | Format-List
            Pause
            CheckHost          
          }
          
        10 { #Uptime
            $wmi = gwmi -computer $compname - credentials $creds Win32_OperatingSystem
            $localdatetime = $wmi.ConvertToDateTime($wmi.LocalDateTime)
            $lastbootuptime = $wmi.ConvertToDateTime($wmi.LastBootUpTime)
            
            "Current Time:      $localdatetime"
            "Last Boot Up Time: $lastbootuptime"
            
            $uptime = $localdatetime - $lastbootuptime
            ""
            "Uptime: $uptime"
            Pause
            CheckHost
          }
        11 { #Disk Info
            $wmi = gwmi -computer $compname - credentials $creds Win32_logicaldisk
            foreach($device in $wmi){
                    Write-Host "Drive: " $device.name   
                    Write-Host -NoNewLine "Size: "; "{0:N2}" -f ($device.Size/1Gb) + " Gb"
                    Write-Host -NoNewLine "FreeSpace: "; "{0:N2}" -f ($device.FreeSpace/1Gb) + " Gb"
                    ""
             }
            Pause
            CheckHost
          }
        12 { #Memory Info
            $wmi = gwmi -computer $compname - credentials $creds Win32_PhysicalMemory
            foreach($device in $wmi){
                Write-Host "Bank Label:     " $device.BankLabel
                Write-Host "Capacity:       " ($device.Capacity/1MB) "Mb"
                Write-Host "Data Width:     " $device.DataWidth
                Write-Host "Device Locator: " $device.DeviceLocator    
                ""        
            }
            Pause
            CheckHost
          }
        13 { #Processor Info
            gwmi -computer $compname - credentials $creds Win32_Processor | Format-List Caption,Name,Manufacturer,ProcessorId,NumberOfCores,AddressWidth  
            Pause
            CheckHost
          }
        14 { #Monitor Info
            
            #Turn off Error Messages
            $ErrorActionPreference_Backup = $ErrorActionPreference
            $ErrorActionPreference = "SilentlyContinue"


            $keytype=[Microsoft.Win32.RegistryHive]::LocalMachine
            if($reg=[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($keytype,$compname)){
                #Create Table To Hold Info
                $montable = New-Object system.Data.DataTable "Monitor Info"
                #Create Columns for Table
                $moncol1 = New-Object system.Data.DataColumn Name,([string])
                $moncol2 = New-Object system.Data.DataColumn Serial,([string])
                $moncol3 = New-Object system.Data.DataColumn Ascii,([string])
                #Add Columns to Table
                $montable.columns.add($moncol1)
                $montable.columns.add($moncol2)
                $montable.columns.add($moncol3)



                $regKey= $reg.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\DISPLAY" )
                $HID = $regkey.GetSubKeyNames()
                foreach($HID_KEY_NAME in $HID){
                    $regKey= $reg.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\DISPLAY\\$HID_KEY_NAME" )
                    $DID = $regkey.GetSubKeyNames()
                    foreach($DID_KEY_NAME in $DID){
                        $regKey= $reg.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\DISPLAY\\$HID_KEY_NAME\\$DID_KEY_NAME\\Device Parameters" )
                        $EDID = $regKey.GetValue("EDID")
                        foreach($int in $EDID){
                            $EDID_String = $EDID_String+([char]$int)
                        }
                        #Create new row in table
                        $monrow=$montable.NewRow()
                        
                        #MonitorName
                        $checkstring = [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFC + [char]0x00           
                        $matchfound = $EDID_String -match "$checkstring([\w ]+)"
                        if($matchfound){$monrow.Name = [string]$matches[1]} else {$monrow.Name = '-'}

                        
                        #Serial Number
                        $checkstring = [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFF + [char]0x00           
                        $matchfound =  $EDID_String -match "$checkstring(\S+)"
                        if($matchfound){$monrow.Serial = [string]$matches[1]} else {$monrow.Serial = '-'}
                                                
                        #AsciiString
                        $checkstring = [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFE + [char]0x00           
                        $matchfound = $EDID_String -match "$checkstring([\w ]+)"
                        if($matchfound){$monrow.Ascii = [string]$matches[1]} else {$monrow.Ascii = '-'}         

                                
                        $EDID_String = ''
                        
                        $montable.Rows.Add($monrow)
                    }
                }
                $montable | select-object  -unique Serial,Name,Ascii | Where-Object {$_.Serial -ne "-"} | Format-Table 
            } else { 
                Write-Host "Access Denied - Check Permissions"
            }
            $ErrorActionPreference = $ErrorActionPreference_Backup #Reset Error Messages
            Pause
            CheckHost
          }
        1337 { Write-Host "Program Made By Trenton Ivey (Trenton@hackyeah.com)";Pause; CheckHost}
        c {Clear-Host;$compname="";GetCompName}
        x {Clear-Host; exit}
        default{CheckHost}
      }
}

#---------Start Main--------------
$compname = $args[0]
if($compname){CheckHost}
else{GetCompName}

Open in new window

0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39727382
First: it's -credentials, not - credentials. Notice the extra space you put in. That's where the error is from.

Second: Instead of

function GetCompName{
    $compname = Read-Host "Please enter a computer name or IP"
    CheckHost
}


use

function GetCompName{
    $compname = Read-Host "Please enter a computer name or IP"
    $creds = Get-Credential
    CheckHost
}


and remove $creds = Get-Credential from the start. This way the script will ask for credentials right after the computer name, which is the logical way
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 70

Expert Comment

by:Qlemo
ID: 39727398
That's correct if you need to reenter the credentials each time (different credentials for different PCs). Else asking only once for the creds, at the very beginning or if not set already, is enough.
0
 

Author Comment

by:bbimis
ID: 39727399
Thanks i'm not good with powerscript but trying to learn from example. Thanks again!
I still get this error when i did your modifications

Get-WmiObject : A parameter cannot be found that matches parameter name 'credentials'.
At C:\push script\myscript.ps1:65 char:38
+             gwmi -computer $compname -credentials $creds  Win32_BIOS | Select-Ob ...
+                                      ~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-WmiObject], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetWmiObjectCommand

new code
#########################################################
#           Powershell PC Info Script V1.0b             #
#              Coded By:Trenton Ivey(kno)               #
#                     hackyeah.com                      #
#########################################################



function Pause ($Message="Press any key to continue..."){
    ""
    Write-Host $Message
    $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}


function GetCompName{
    $compname = Read-Host "Please enter a computer name or IP"
    $creds = Get-Credential
    CheckHost
}

function CheckHost{
    $ping = gwmi Win32_PingStatus -filter "Address='$compname'"
    if($ping.StatusCode -eq 0){$pcip=$ping.ProtocolAddress; GetMenu}
    else{Pause "Host $compname down...Press any key to continue"; GetCompName}
}
    


function GetMenu {
    Clear-Host
    "  /----------------------\"
    "  |     PC INFO TOOL     |"
    "  \----------------------/"
    "  $compname ($pcip)"
    ""
    ""
    "1) PC Serial Number"
    "2) PC Printer Info"
    "3) Current User"
    "4) OS Info"
    "5) System Info"
    "6) Add/Remove Program List"
    "7) Process List"
    "8) Service List"
    "9) USB Devices"
    "10) Uptime"
    "11) Disk Space"
    "12) Memory Info"
    "13) Processor Info"
    "14) Monitor Serial Numbers"
    ""
    "C) Change Computer Name"
    "X) Exit The program"
    ""
    $MenuSelection = Read-Host "Enter Selection"
    GetInfo
}


function GetInfo{
    Clear-Host
    switch ($MenuSelection){
        1 { #PC Serial Number
            gwmi -computer $compname -credentials $creds  Win32_BIOS | Select-Object SerialNumber | Format-List
            Pause
            CheckHost
          }
          
        2 { #PC Printer Information
            gwmi -computer $compname -credentials $creds Win32_Printer | Select-Object DeviceID,DriverName, PortName | Format-List
            Pause
            CheckHost          
          }
          
        3 { #Current User
            gwmi -computer $compname -credentials $creds Win32_ComputerSystem | Format-Table @{Expression={$_.Username};Label="Current User"}
            ""
            #May take a very long time if on a domain with many users
            #"All Users"
            #"------------"
            #gwmi -computer $compname -credentials $creds Win32_UserAccount | foreach{$_.Caption}
            Pause
            CheckHost          
          }
          
        4 { #OS Info
            gwmi -computer $compname -credentials $creds Win32_OperatingSystem | Format-List @{Expression={$_.Caption};Label="OS Name"},SerialNumber,OSArchitecture
            Pause
            CheckHost       
          }
          
        5 { #System Info
            gwmi -computer $compname -credentials $creds Win32_ComputerSystem | Format-List Name,Domain,Manufacturer,Model,SystemType
            Pause
            CheckHost         
          }        
          
        6 { #Add/Remove Program List
            gwmi -computer $compname -credentials $creds Win32_Product | Sort-Object Name | Format-Table Name,Vendor,Version
            Pause
            CheckHost
          }
          
        7 { #Process Listx
        
            gwmi -computer $compname -credentials $creds Win32_Process | Select-Object Caption,Handle | Sort-Object Caption | Format-Table
            Pause
            CheckHost         
          }
          
        8 { #Service List
            gwmi -computer $compname -credentials $creds Win32_Service | Select-Object Name,State,Status,StartMode,ProcessID, ExitCode | Sort-Object Name | Format-Table
            Pause
            CheckHost        
          }
        
        9 { #USB Devices
            gwmi -computer $compname -credentials $creds Win32_USBControllerDevice | %{[wmi]($_.Dependent)} | Select-Object Caption, Manufacturer, DeviceID | Format-List
            Pause
            CheckHost          
          }
          
        10 { #Uptime
            $wmi = gwmi -computer $compname -credentials $creds Win32_OperatingSystem
            $localdatetime = $wmi.ConvertToDateTime($wmi.LocalDateTime)
            $lastbootuptime = $wmi.ConvertToDateTime($wmi.LastBootUpTime)
            
            "Current Time:      $localdatetime"
            "Last Boot Up Time: $lastbootuptime"
            
            $uptime = $localdatetime - $lastbootuptime
            ""
            "Uptime: $uptime"
            Pause
            CheckHost
          }
        11 { #Disk Info
            $wmi = gwmi -computer $compname -credentials $creds Win32_logicaldisk
            foreach($device in $wmi){
                    Write-Host "Drive: " $device.name   
                    Write-Host -NoNewLine "Size: "; "{0:N2}" -f ($device.Size/1Gb) + " Gb"
                    Write-Host -NoNewLine "FreeSpace: "; "{0:N2}" -f ($device.FreeSpace/1Gb) + " Gb"
                    ""
             }
            Pause
            CheckHost
          }
        12 { #Memory Info
            $wmi = gwmi -computer $compname -credentials $creds Win32_PhysicalMemory
            foreach($device in $wmi){
                Write-Host "Bank Label:     " $device.BankLabel
                Write-Host "Capacity:       " ($device.Capacity/1MB) "Mb"
                Write-Host "Data Width:     " $device.DataWidth
                Write-Host "Device Locator: " $device.DeviceLocator    
                ""        
            }
            Pause
            CheckHost
          }
        13 { #Processor Info
            gwmi -computer $compname -credentials $creds Win32_Processor | Format-List Caption,Name,Manufacturer,ProcessorId,NumberOfCores,AddressWidth  
            Pause
            CheckHost
          }
        14 { #Monitor Info
            
            #Turn off Error Messages
            $ErrorActionPreference_Backup = $ErrorActionPreference
            $ErrorActionPreference = "SilentlyContinue"


            $keytype=[Microsoft.Win32.RegistryHive]::LocalMachine
            if($reg=[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($keytype,$compname)){
                #Create Table To Hold Info
                $montable = New-Object system.Data.DataTable "Monitor Info"
                #Create Columns for Table
                $moncol1 = New-Object system.Data.DataColumn Name,([string])
                $moncol2 = New-Object system.Data.DataColumn Serial,([string])
                $moncol3 = New-Object system.Data.DataColumn Ascii,([string])
                #Add Columns to Table
                $montable.columns.add($moncol1)
                $montable.columns.add($moncol2)
                $montable.columns.add($moncol3)



                $regKey= $reg.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\DISPLAY" )
                $HID = $regkey.GetSubKeyNames()
                foreach($HID_KEY_NAME in $HID){
                    $regKey= $reg.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\DISPLAY\\$HID_KEY_NAME" )
                    $DID = $regkey.GetSubKeyNames()
                    foreach($DID_KEY_NAME in $DID){
                        $regKey= $reg.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\DISPLAY\\$HID_KEY_NAME\\$DID_KEY_NAME\\Device Parameters" )
                        $EDID = $regKey.GetValue("EDID")
                        foreach($int in $EDID){
                            $EDID_String = $EDID_String+([char]$int)
                        }
                        #Create new row in table
                        $monrow=$montable.NewRow()
                        
                        #MonitorName
                        $checkstring = [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFC + [char]0x00           
                        $matchfound = $EDID_String -match "$checkstring([\w ]+)"
                        if($matchfound){$monrow.Name = [string]$matches[1]} else {$monrow.Name = '-'}

                        
                        #Serial Number
                        $checkstring = [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFF + [char]0x00           
                        $matchfound =  $EDID_String -match "$checkstring(\S+)"
                        if($matchfound){$monrow.Serial = [string]$matches[1]} else {$monrow.Serial = '-'}
                                                
                        #AsciiString
                        $checkstring = [char]0x00 + [char]0x00 + [char]0x00 + [char]0xFE + [char]0x00           
                        $matchfound = $EDID_String -match "$checkstring([\w ]+)"
                        if($matchfound){$monrow.Ascii = [string]$matches[1]} else {$monrow.Ascii = '-'}         

                                
                        $EDID_String = ''
                        
                        $montable.Rows.Add($monrow)
                    }
                }
                $montable | select-object  -unique Serial,Name,Ascii | Where-Object {$_.Serial -ne "-"} | Format-Table 
            } else { 
                Write-Host "Access Denied - Check Permissions"
            }
            $ErrorActionPreference = $ErrorActionPreference_Backup #Reset Error Messages
            Pause
            CheckHost
          }
        1337 { Write-Host "Program Made By Trenton Ivey (Trenton@hackyeah.com)";Pause; CheckHost}
        c {Clear-Host;$compname="";GetCompName}
        x {Clear-Host; exit}
        default{CheckHost}
      }
}

#---------Start Main--------------
$compname = $args[0]
if($compname){CheckHost}
else{GetCompName}

Open in new window

0
 
LVL 70

Assisted Solution

by:Qlemo
Qlemo earned 200 total points
ID: 39727409
It is -Credential (singular).
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39727420
Yup. Thanks Qlemo.

When in doubt (or in a hurry) use the help :)

help gwmi will tell you the correct syntax.
0
 

Author Closing Comment

by:bbimis
ID: 39727568
thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
This Micro Tutorial will give you basic overview of the control panel section on Windows 7. It will depth in Network and Internet, Hardware and Sound, etc. This will be demonstrated using Windows 7 operating system.
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question