Here's a quick demo of how to quickly update all your computers in PDQ Inventory to have a new Custom Field. We're going to look at adding Custom Fields to multiple computers with PowerShell and the PDQ Inventory Custom Fields Import Wizard. (Enterprise mode required for Custom Fields.)
Normally, the Custom Fields Import Wizard is used within PDQ Inventory itself (more info here); but, fortunately, the PDQ products have command line interface (CLI) utilities to help us do this with PowerShell as well.
It turns out, PDQ Inventory has many commands that you can use from a command line.
So, how do we find what's available? We ask!
In fact, all you need to do is run the following command from an elevated command prompt or PowerShell window:
Look at all those helpful looking commands!
For this blog, we're looking at using the CreateCustomField and ImportCustomFields commands specifically. Let's find out more about their usage.
With that in mind, let's dive in and add all the things!
Below are the six sections needed to use PowerShell and PDQ Inventory commands to create a Custom Field and import data:
First, we need to identify which computers you wish to add values to.
If you want to update all computers, you'll need to use something like the following (using sqlite3.exe):
Otherwise, you'll need to craft your own SQL statement. For example, to get all computers that contain the word LAB, you would do something like this (emphasis added).
Once you've picked the computers you wish to update, we'll need to get the data that you want to add as a Custom Field.
Let's create a Custom Field called Department. We'll give it a data type of String since we'll be using text as the value. The only available Custom Field data types are: Boolean, String, Integer, Date, and DateTime.
Since the ImportCustomFields command is expecting a CSV file, you're going to need to create one. So, let's create an array with our CSV headers.
$ComputerList = @("ComputerName,$CustomFieldName")
Then, we're going to loop through each computer (with ForEach-Object) in $Computers and then give it a value of Sales for the Department and add it to the $ComputerList array.
Next, we're going to create a temp file (with Out-File) for our CSV and export our $ComputerList to that file.
Before you can import the CSV file that we created, we're going to need to make the Custom Field. So, let's use the CreateCustomField command you looked at earlier.
PDQInventory.exe CreateCustomField -Name $CustomFieldName -Type $CustomFieldType
Since you've created the Custom Field, we can now use PDQ Inventory's Custom Fields Import Wizard to import the data into our database.
Now that we've gone over each section, let's throw a script together that you can use.
And that's it! Now, you can modify this to suit your needs and get all your data imported like a boss.
You now wield the power to more easily create Custom Fields and fill them with glorious data. Hopefully, this will help get all kinds of custom data into your PDQ Inventory database for a more complete view of your environment.
To see this in action, please check out this short video:
Kris was an employee at PDQ.