urgent help - script help
hi all,
i tried following code (thx) , # number of processor not return correct number. the report shows 1 processor server shows 4 or 12 task manager's cpu. also, how should script change include more 1 ip (more 1 network adapter)?
thank much!
function get-info { [cmdletbinding()] param( [parameter(mandatory=$true,valuefrompipeline=$true,valuefrompipelinebypropertyname=$true)] [string[]]$computername, [string]$logfile = 'c:\unreachable.txt' ) begin { remove-item $logfile –erroraction silentlycontinue } process { foreach ($computer in $computername) { $continue = $true try { $os = get-wmiobject –class win32_operatingsystem –computername $computer –erroraction stop } catch { $continue = $false "$computer not reachable" | out-file $logfile -append } if ($continue) { $bios = get-wmiobject –class win32_bios –computername $computer $os = gwmi win32_operatingsystem -cn $computer $mem = get-wmiobject win32_computersystem -cn $computer | select @{name="physicalmemory";expression={($_.totalphysicalmemory/1mb).tostring("n0")}},numberofprocessors,name,model $phyv = get-wmiobject win32_bios -computer $computer | select serialnumber if($phyv -like “*vmware*” ){ $res =“virtual machine” }else {$res = "physical machine”} $networks = get-wmiobject win32_networkadapterconfiguration -computername $computer | ? {$_.ipenabled} foreach ($network in $networks) { $ipaddress = $network.ipaddress[0]} $obj = new-object –typename psobject $obj | add-member –membertype noteproperty –name computername –value ($computer) –passthru | add-member –membertype noteproperty –name hardware –value ($res) -passthru | add-member –membertype noteproperty –name operatingsystem –value ($os.caption) -passthru | add-member –membertype noteproperty –name servicepack –value ($os.servicepackmajorversion) -passthru | add-member –membertype noteproperty –name "physicalmemory(mb)" –value ($mem.physicalmemory) -passthru | add-member –membertype noteproperty –name processors –value ($mem.numberofprocessors) -passthru | add-member –membertype noteproperty –name ipaddress –value ($ipaddress) -passthru | add-member –membertype noteproperty –name macaddress –value ($network.macaddress) write-output $obj } } } }
if want full script, has tweaks, including writing out file , list nics (even disabled ones), i posted on technet credit azam, here:
full script: http://gallery.technet.microsoft.com/powershell-script-to-get-b716c3f4
thanks mike! did trick. (i up-voted you, because needed).
apparently "cores" doesn't mean "cores" or maybe , misunderstand - either way, here's final script appears produce need:
#---------------------------------------------------------------------------------------------------------------------- # - getinfo.psm1 - #---------------------------------------------------------------------------------------------------------------------- # authors: unknown, "john jy," jeff mason (tnjman), mike laughlin , others # source: # http://social.technet.microsoft.com/forums/windowsserver/en-us/d28b3cf9-1227-4026-94d5-144306fd38fa/urgent-help-script-help?forum=winserverpowershell # # 1) save/copy "getinfo.psm1" file "c:\windows\system32\windows\powershell\v1.0\modules\" folder # 2) go powershell # 3) import module powershell: import-module c:\windows\system32\windowspowershell\v1.0\modules\getinfo.psm1 # # 4) run against single computer, powershell, after importing module, type: # getinfo remote-server1 # (where "remote-server1" name of remote server report against) # # 5) run against multiple computers, # # a) create "wrapper script" call "getinfo" moudule, computer name passed parameter: # # #getinfo-servers.ps1 #wrapper script# # set-executionpolicy unrestricted # import-module "c:\windows\system32\windowspowershell\v1.0\modules\getinfo.psm1" # getinfo remote-server1 # getinfo remote-server2 # getinfo remote-server3 # #end of getinfo-servers.ps1 #wrapper script# # # b) execute above-saved "getinfo-servers.ps1 "wrapper script" # change directory saved wrapper script, type: # powershell .\getinfo-servers.ps1 # # 6) review results: # notepad c:\computerinfo.csv #---------------------------------------------------------------------------------------------------------------------- function getinfo { [cmdletbinding()] param( [parameter(mandatory=$true,valuefrompipeline=$true,valuefrompipelinebypropertyname=$true)] [string[]]$computername, [string]$logfile = 'c:\unreachable.txt' ) begin { remove-item $logfile –erroraction silentlycontinue } process { foreach ($computer in $computername) { $continue = $true try { $os = get-wmiobject –class win32_operatingsystem –computername $computer –erroraction stop } catch { $continue = $false "$computer not reachable" | out-file $logfile -append } if ($continue) { $bios = get-wmiobject –class win32_bios –computername $computer $os = gwmi win32_operatingsystem -cn $computer $mem = get-wmiobject win32_computersystem -cn $computer | select @{name="physicalmemory";expression={"{0:n2}" -f($_.totalphysicalmemory/1gb).tostring("n0")}},numberofprocessors,name,model $cpuinfo = "numberofcores" [string[]]$cpucore = get-wmiobject -class win32_processor –computername $computer -property $cpuinfo | select-object -property $cpuinfo $cpuinfo = "numberoflogicalprocessors" [string[]]$cpulp = get-wmiobject -class win32_processor –computername $computer -property $cpuinfo | select-object -property $cpuinfo $phyv = get-wmiobject win32_bios -computer $computer | select serialnumber if($phyv -like “*vmware*” -or $phyv -like "*-*"){ $res =“virtual machine” } else {$res = "physical machine”} # find active nics , ip of nic $networks = get-wmiobject win32_networkadapterconfiguration -computername $computer | ? {$_.ipenabled} foreach ($network in $networks) {[string[]]$ipaddress += $network.ipaddress[0]} $obj = new-object –typename psobject $obj | add-member –membertype noteproperty –name computername –value ($computer) –passthru | add-member –membertype noteproperty –name hardware –value ($res) -passthru | add-member –membertype noteproperty –name operatingsystem –value ($os.caption) -passthru | add-member –membertype noteproperty –name servicepack –value ($os.servicepackmajorversion) -passthru | add-member –membertype noteproperty –name "physicalmemory(gb)" –value ($mem.physicalmemory) -passthru | add-member –membertype noteproperty –name processors –value ($mem.numberofprocessors) -passthru | add-member –membertype noteproperty –name ipaddress –value ($ipaddress) -passthru | add-member –membertype noteproperty –name cpucores –value ($cpucore) -passthru | add-member –membertype noteproperty –name cpulogicalprocessors –value ($cpulp) -passthru | add-member –membertype noteproperty –name macaddress –value ($network.macaddress) -passthru | add-member –membertype noteproperty –name boxtype -value ($phyv) $csv = $computer + "," ` + $res + "," ` + $os.caption +"," ` + $os.servicepackmajorversion + "," ` + $mem.physicalmemory + "," ` + $mem.numberofprocessors + "," ` + $ipaddress + "," ` + $cpucore + "," ` + $cpulp + "," ` + $network.macaddress write-output $obj #write-output $csv - uncomment debug report output line write $csv | out-file c:\computerinfo.csv -append } # end if } # end foreach } # end process end {} } # end function
thanks!
tnjman
Windows Server > Windows PowerShell
Comments
Post a Comment