/build/static/layout/Breadcrumb_cap_w.png

Powershell script works partly

Dear all,

Only the $x variable works. Can anyone help me to make also $y work? I think it's a simple solution , but i don't know how :-) 

$x = "C:\Program Files (x86)\DELL\KACE\Inventory.log"
$y = "C:\Program Files\DELL\KACE\Inventory.log"
if ((test-path $x) -or (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"  
}




0 Comments   [ + ] Show comments

Answers (2)

Posted by: Axel_Bodin 3 years ago
White Belt
0

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 3 years ago
Posted by: rileyz 3 years ago
Red Belt
0

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 3 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 3 years ago

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ