Thursday, 6 March 2014

PowerShell Scripts - File exist or not

In an organisation where software inventory application does not exist Scripts plays a good role. I met one situation where we had to analyse that in how many computers of our organisation has Winzip installed so that licenses can be procured before they raid us and charge the fine upon.Thus inspired me to create a script which would explore the files remotely exist or not.

I have again used the powershell to make this happen. Script would go through the text file which has computer names in it and will execute the same command one by one on all of them.


$colComputers = Get-Content C:\FileName.txt
$ErrorActionPreference = "SilentlyContinue"
foreach ($StrComputer in $colComputers)
{
$GenItems1 = gwmi Win32_ComputerSystem -Comp $StrComputer
$x86Path = 'C:\Program Files (x86)\WinZip\WZCAB.DLL'
if(!$GenItems1){
Write-Host “$StrComputer not found”
}
else
{
Write-Host $StrComputer, (Get-Item $x86Path | Select -ExpandProperty VersionInfo).fileVersion
}
}



Regards,
Baij

PowerShell Scripts - Ping a Series of IP Address

There are many application over the internet which can ping multiple machines and provide you the status however no software is trustworthy unless you know its coding thus should not be used as far as server or important machines are concerned thus created one of which coding is visible and is very easy to implement.

We need to simply change IP address series 10.10.10.$ to what is our requirement and it is just ready for your environment. Track your important servers connectivity using this simple script.

Start

$ping = New-Object System.Net.NetworkInformation.Ping
$i = 0
1..255 | foreach { $ip = “10.10.10.$_”
$Res = $ping.send($ip)
if ($Res.Status -eq “Success”)
{
$result = $ip + ” = Success”
Write-Host $result
$i++
}}

$Hosts = [string]$i + ” Hosts is pingable”


Write-Host $Hosts

Finish

Regards, IIS

PowerShell Scripts - Machine details from AD

It is also possible to fetch the Operating system and Machine name from Active Directory for which simple one line is enough. This script can fetch more in less time as it simply has to connect to active directory database. Other ways to pull the same information is to run a script remotely to each and every computer one by one remotely and then have data. More information can also be added like version, fsdn by just extending the script.

Below script will give away the output in a well defined table and can be used to create dashboard.

Get-ADComputer -Filter * -Property * | Format-Table Name,OperatingSystem -Wrap –Auto 


Same Information can be achieved by using Power shell also.


DSQUERY Computer "OU=OUNAME,DC=india,DC=DOMAINNAME,DC=local" -name COMPName* -scope subtree -limit 0 > C:\ComputerOU.csv


Regards, IIS

Symantec Altiris - Inventory from SQL Database


Altiris is an inventory software from Symantec which provides in depth details of the computers, server, devices in the organization. It has so many templates in built however its feature to fetch the inventory using the console does not convince much and has very complex architecture. Thus it is rather easy to pull inventory from altiris sql database than its console. I succeeded to create several here using sql queries and sharing eventually.

Below sql query will help you to pull the name for Computer, Software, Operating System, Processor in a tabular manner. Please go through the script and change as need be.

Start

Select * from
( SELECT DISTINCT
[Symantec_CMDB].[dbo].[vComputer].Name
,[Symantec_CMDB].[dbo].[Inv_AddRemoveProgram].DisplayName as name1
,[Symantec_CMDB].[dbo].Inv_HW_Computer_System.[Identifying Number]
,[Symantec_CMDB].[dbo].vComputer.[OS Name]
,[Symantec_CMDB].[dbo].[Inv_HW_Processor_Name_Windows].[Processor Name]

FROM [Symantec_CMDB].[dbo].Inv_AddRemoveProgram INNER JOIN [Symantec_CMDB].[dbo].vComputer
ON [Symantec_CMDB].[dbo].Inv_AddRemoveProgram._ResourceGuid = [Symantec_CMDB].[dbo].vComputer.Guid INNER JOIN
[Symantec_CMDB].[dbo].Inv_HW_Computer_System
ON [Symantec_CMDB].[dbo].vComputer.Guid = [Symantec_CMDB].[dbo].Inv_HW_Computer_System._ResourceGuid
INNER JOIN [Symantec_CMDB].[dbo].[Inv_HW_Processor_Name_Windows]
ON [Symantec_CMDB].[dbo].vComputer.Guid = [Symantec_CMDB].[dbo].[Inv_HW_Processor_Name_Windows]._ResourceGuid
)P
PIVOT (
Count(name1)
FOR name1 in ([Microsoft Office Standard 2007]
,[Java(TM) 6 Update 45]
,[WinZip 17.0]
,[Adobe Reader X (10.1.6)]
,[Symantec pcAnywhere]
)
)As PVT
Order by Name

Finish

Regards, IIS

Monday, 3 March 2014

Find Software Installed on Remote Computer

There are many features in the windows itself which can help you to know if a software related to one particular company is installed on remote computer or not. WMIC command is one of them which can help you. It is the inbuilt command of windows and has so many subfeature. Let me let you one them I used to know how many software has been installed on remote computer which is of Microsoft only.

Run the command in command prompt straight.

WMIC /Node:HostName path win32_Product Where (Caption like "%Microsoft%") Get Name, Version


If you want to know about the software from other publisher change Microsoft to others like Adobe, Java or whatever your need be. Also do not forget to change the hostname.

Regards, Baij


Tuesday, 25 February 2014

Full computer details in a excel



This script is very important for someone in IT infra and provide all information in one excel file which he ever dreamed of. This collects hostname, manufacturer, bios version, release date, serial number, user domain and logged in user name.


strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
   Set colBIOS = objWMIService.ExecQuery _
    ("Select * from Win32_BIOS")

Set wshNetwork = WScript.CreateObject( "WScript.Network" )
Set Excel = WScript.CreateObject("Excel.Application")
Set ExWb = Excel.Workbooks.Open("C:\test.xls",,False)
Set ExWs = ExWb.Worksheets(1)
r = 1
Do Until len(Excel.Cells(r, 1).value) = 0
r = r + 1
Loop
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each objItem in colItems
Excel.cells(r, 6).value = objItem.Model
Excel.cells(r, 13).value = Now
Next
Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory",,48)
For Each objItem in colItems

    Excel.cells(r, 12).value = objItem.Capacity
Next
For each objBIOS in colBIOS
    Excel.cells(r, 5).value = objBIOS.InstallableLanguages
    Excel.cells(r, 4).value = objBIOS.Manufacturer
    Excel.cells(r, 7).value = objBIOS.Name
    Excel.cells(r, 8).value = objBIOS.PrimaryBIOS
    Excel.cells(r, 9).value = objBIOS.ReleaseDate
    Excel.cells(r, 3).value = objBIOS.SerialNumber
    Excel.cells(r, 11).value = objBIOS.SMBIOSBIOSVersion
    For i = 0 to Ubound(objBIOS.BiosCharacteristics)
    Excel.cells(r, 17).value = objBIOS.BiosCharacteristics(i)
    Next
Next
Excel.cells(r, 1).value = wshNetwork.UserDomain
Excel.cells(r, 2).value = wshNetwork.UserName
ExWb.Save
Excel.Application.Quit


Regards,
Baij

Real Physical Memory Size in Machine

I have created one script to figure out the machine physical memory. This will provide its size in MB as well as in GB. It is dificult to know the exact size while applying simple coding Thus I created one with more coding and can be used the exact size.

Start

On Error Resume Next
Const GB = 1073741824
Const MB = 1048576
Dim Obj, Wmi

Set Wmi = GetObject("winmgmts:\\.\root\CIMV2")
For Each Obj In Wmi.ExecQuery("SELECT * FROM Win32_ComputerSystem")
 If Obj.TotalPhysicalMemory > Int(GB) Then
  msgbox _
  "Total Physical Memory : " & FormatNumber(Obj.TotalPhysicalMemory / GB,2) & " GB"
 Else
  msgbox _
  "Total Physical Memory : " & FormatNumber(Obj.TotalPhysicalMemory / MB,2) & " MB"
 End If
Next

Finish

Regards, IIS

Install Multiple Software with a Click