Powershell script works partly
Answers (2)
Try This
if (Test-Path $y -OlderThan (Get-Date).AddDays(-20))
{# // Kace Version is up to date or installed”}
elseif (Test-Path $y -OlderThan (Get-Date).AddDays(-20))
{# // Kace Version is up to date or installed”}
else
{Out-File \\vlsrv02\nokace\"$env:computername No or OLD KACE Version.txt" }
Comments:
-
I changed it to below script , but it don't work.
$x = "C:\Program Files (x86)\DELL\KACE\Inventory.log"
$y = "C:\Program Files\DELL\KACE\Inventory.log"
if (Test-Path $x -OlderThan (Get-Date).AddDays(-25))
{
# // File exists”
}
elseif (Test-Path $y -OlderThan (Get-Date).AddDays(-25))
{
# // File exists”
}
else
{
Out-File \\vlsrv02\nokace\"$env:computername NO KACE.txt"
} - arjanfeest 7 years ago
Try this http://pastebin.com/wvZPE5rE
Gah this site is crap for showing code.
You want to add in a bit for capturing up to date computers as well, just for fullness - otherwise how do you know if a scrip ran on x computer.
Good luck!
$DebugPreference = "Continue" #Continue|SilentlyContinue
$64BitOS = "C:\Program Files (x86)\DELL\KACE\Inventory.log"
$32BitOS = "C:\Program Files\DELL\KACE\Inventory.log"$CompareDate = (Get-Date).AddDays(-20)
If (Test-Path $64BitOS)
{Write-Debug 'File Found.'
$FileObject64BitOS = Get-ItemProperty $64BitOS
If ($FileObject64BitOS.LastWriteTime -gt $CompareDate)
{Write-Debug 'KACE up to date.'}
Else{Write-Debug 'KACE not up to date, file is older than compare date.'
Out-File \\vlsrv02\nokace\"$env:computername No or OLD KACE Version.txt"}}If (Test-Path $32BitOS)
{Write-Debug 'File Found.'
$FileObject32BitOS = Get-ItemProperty $32BitOS
If ($FileObject32BitOS.LastWriteTime -lt $CompareDate)
{Write-Debug 'KACE up to date.'}
Else{Write-Debug 'KACE not up to date, file is older than compare date.'
Out-File \\vlsrv02\nokace\"$env:computername No or OLD KACE Version.txt"}}
Comments:
-
We are almost there i think. Looks like the 32bit version don't work. When i run this script in Windows Powershell ISE it works ok, but when i run this script via GPO it give always the out-file, also when the .log is younger than 20 days. Do you have a idea what's wrong? :-) - arjanfeest 7 years ago
-
Ah, depends how the script is run. PowerShell has a 32 bit and 64 bit launcher. So you need to account for which bitness is running the script.
Since you know you are using GPO, find out hows its run, ie does 64 bit Powershell run on the 64 bit system? Use ProcMon. Next you need to know what context its executing the script, ie SYSTEM, KACE account?
With those two bits you can start debugging the script yourself. Use psexec you run as SYSTEM, if you need the system account - when i stay that I mean you you start powershell as system, then run the script - basicly flight testing the script the best you can etc.
Im basicly telling you how to fix it, but I'm not going to do it for you.
Out-file issue: Write the $FileObject64BitOS.LastWriteTime and $CompareDate to file so you can see the results, I suspect something is going wrong with one of those variables.
Good luck! - rileyz 7 years ago