Background: I am trying to detect whether an log entry exists. If it does, declare its string variable, otherwise continue. Here is a portion of the script (In this order):
$Arch = (Get-WmiObject -Class Win32_OperatingSystem).OSArchitecture
If ($Arch -eq "64-bit") {
$SMSAgentFolder = "$env:WinDir\SysWOW64\CCM";
$CCMSetupFolder = "$Env:Windir\CCMSetup"
} Else {
$SMSAgentFolder = "$Env:WinDir\System32\CCM";
$CCMSetupFolder = "$Env:Windir\System32\CCMSetup"
}
New-Variable HinvStrWarning -Value "Warning! There is not a Hardware Inventory entry listed in the Inventory Agent Log file."
Function SetHinv {
$Hinv = Select-String $Hinvpattern $Invfile | select -Last 1 | % {
$_.Matches.Groups[2].Value + ' ' + $_.Matches.Groups[1].Value
}
}
Function SetTSSinv {
$TSSInv = (New-TimeSpan $Sinv).Days
}
$InvFile = "$SMSAgentFolder\logs\inventoryagent.log"
$Hinvpattern = 'HinvEndpoint.*<time="(.*?)" date="(.*?)"'
$Hinv = Select-String $Hinvpattern $InvFile | select -Last 1 | % {
$_.Matches.Groups[2].Value + ' ' + $_.Matches.Groups[1].Value
}
If(![string]::IsNullOrWhiteSpace($Hinv)) {
SetHinv; SetTSHinv
} else {
Add-Content $verboseLog "$HinvStrWarning"
}
The function Function SetTSSinv {$TSSInv = (New-TimeSpan $Sinv).Days}
does not work by calling the function name but if you manually do it like this: $TSSInv = (New-TimeSpan $Sinv).Days
, it does it no problem.
That was as far as I have gotten in my troubleshooting, so the additional code here may be incorrect:
Add'l Declarations:
$7Days = $GetDate.AddDays(7)
$SMSCli = [wmiclass] "\\$Env:ComputerName\root\ccm:SMS_Client"
Functions:
Function SinvScan {$SMSCli.TriggerSchedule("{00000000-0000-0000-0000-000000000002}")}
Function SinvStr {If (((($GetDate).Days) - $TSSinv) -ge $7Days){Add-Content $VerboseLog $InvLogSinvScn; SinvScan}}
The variable removal will potentially affect above.. Thanks for you help!
Sorry Guys, I was overthinking it. For my instance this works:
New-Variable SinvStrWarning -Value "Warning! There is not a Software Inventory entry listed in the Inventory Agent Log file."
$InvFile = "$SMSAgentFolder\logs\inventoryagent.log"
Function SetSinv {
$Sinv = Select-String $Sinvpattern $Invfile | select -Last 1 | % {
$_.Matches.Groups[2].Value + ' ' + $_.Matches.Groups[1].Value
}
}
$Sinvpattern = 'SinvEndpoint.*<time="(.*?)" date="(.*?)"'
$Sinv = Select-String $Sinvpattern $Invfile | select -Last 1 | % {
$_.Matches.Groups[2].Value + ' ' + $_.Matches.Groups[1].Value
}
$SinvNull = $Sinv -ne $Null
If ($SinvNull -eq "True"){
SetSinv;
$TSSInv = (New-TimeSpan $Sinv).Days
} Else {
Add-Content $verboseLog "$SinvStrWarning"
}