Smart Label OS Install Date
I have been trying to get a smart label working based on the OS_INSTALL_DATE field in the db. I followed the following Blog post: http://www.itninja.com/blog/view/smart-label-based-on-os-installation-date, but am not getting it to work.
Looking at the db, I notice that the field type isn't a timestamp, but just a varchar. Is this what could be causing the issue? Or does anyone else know of a way to get this working?
Thanks!
3 Comments
[ + ] Show comments
Answers (1)
Please log in to answer
Posted by:
rockhead44
8 years ago
I have done the following to get the OS Date installed:
Created a powershell script to get the OS date and time installed and output a text file to C:\ProgramData\Dell\KACE\user
My file reads as:
=====================================
function Ps64([scriptblock]$block) {
$machineName = [Environment]::MachineName;
try {
# Note: The configuration name is what forces it to 64 bit.
$session = New-PSSession -ComputerName $machineName -ConfigurationName Microsoft.PowerShell
} catch {
# Try to enable Remote Management on this machine.
winrm quickconfig -q -f
# Try again.
$session = New-PSSession -ComputerName $machineName -ConfigurationName Microsoft.PowerShell
}
# Now invoke our code in 64 bit PowerShell.
try {
Invoke-Command -Session $session -ScriptBlock $block -ArgumentList $args
} finally {
Remove-PSSession $session
}
}
([WMI]'').ConvertToDateTime((Get-WmiObject Win32_OperatingSystem).InstallDate)|out-file C:\ProgramData\Dell\KACE\user\OSinstalldateandtime.txt
================================================================
From there I deploy the .ps1 file, along with a batch file. I zipped the 2 together and and created an offline kscript, with the zip file uploaded. From there I target my machines and call the .bat file which reads
@ECHO OFF
SET ThisScriptsDirectory=%~dp0
SET PowerShellScriptPath=%ThisScriptsDirectory%MyPowerShellScript.ps1
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""C:\ProgramData\Dell\KACE\kbots_cache\packages\kbots\255\OSDT.ps1""' -Verb RunAs}";
That executes the powershell file and outputs the text file to the location I specified above. In my case, I had to include the full path to the package to get it to execute properly.
Next, I created a new Software inventory record as a CIR using the following syntax:
ShellCommandTextReturn(cmd.exe /c type C:\ProgramData\Dell\KACE\user\OSinstalldateandtime.txt)
Finally, I created a report which returns machines that have that software inventory record.
There may be an easier way but this is what worked for me after much research and trial-and-error.
We had it setup as the created date in KACE, but if we forget to delete the agent from KACE before reimaging the computer, it won't be picked up by the smart label.
Going by OS install date, this will fix that issue. - crrussell3 8 years ago