I am reaching out to look for ideas on how to customize a an existing PowerShell so the technicians can easily create and install either via on a single workstation or on a domain.
The script uses basic ‘Get-wmiobject’ cmdlets and gathers PC information. It will then create a custom object and then convert the output to a json file format and upload to our database via API. The SiteID indicates which client this computer belongs to.
$prop = @{ SiteID = "1" ComputerName = $ComputerInfo.name Manufacturer = $ComputerInfo.Manufacturer Model = $ComputerInfo.model Productkey = $null OS = $OSInfo.caption ServicePacklevel = $Servicepack Domain = $ComputerInfo.Domain IP = $IPAddress HDDSize = $HDrives CPUSpeed = $CPUInfo.name Ram = [string]([math]::Round($ComputerInfo.TotalPhysicalMemory / 1GB)) + " GB" MACAddress = $MacAddress SerialNumber = $BiosInfo.SerialNumber ServiceTagNumber = $BiosInfo.SerialNumber ExpressServiceTagNumber = $ExpressServiceTag }
My script will do a continual loop and once every 4 hours, run again and upload its data, which will reset a time field in our database which indicates when a machine ‘reported in’ last.
Using PowerShell Studio, I converted my script with the hard set ‘SiteID’ to a service and installed it on few workstations at a small client office and it works. The SiteID field will be custom for each site and I need to make this easy for technicians to install on workstations which some may still be running on PSversion 2 (Windows 7).
This is my ideal scenario for what this would look for as the process a technician would follow to create the executalbe to deploy to one of our clients. The technician would just have to supply the SiteID number.
Create-InventoryEXE - SiteID 10 -Name “BobsAutoInv”
The output is an EXE or MSI that can be run on a workstation or set to run as a GPO to run on an entire Domain.
“BobAutoInv.msi”
I am not committed to the idea that this HAS TO BE A SERVICE and to run this as a scheduled task. My thought is that services might be more easily monitored by our auditor where we can run a report on services running to see if this one is stopped, started, or even there.
Wonder if anyone can give me general direction on how to:
- Hard code the SiteID without the technicians going into the code itself.
- Create the service from the script via command line. Can this be done with a dotnet command/script?
- If a service is not a good idea, how to do this as a scheduled task, keeping in mind that older version of PowerShell might have to be contended with.