Changes

Inventory script

975 bytes added, 13:02, 13 May 2011
changed the auti code a bit, to do with the console writing of the final report
$s_ToAddress = "-t " & $email_address
$s_Subject = "PC's with missmatched WPKG programs"
 
If FileExists($pc_xml_path) = 0 Then
ConsoleWrite("Error. Unable to read files in " & $pc_xml_path & ", exiting" & @CRLF)
Exit
ElseIf FileExists($master_xml_path) = 0 Then
ConsoleWrite("Error. Unable to read files in " & $master_xml_path & ", exiting" & @CRLF)
Exit
EndIf
If Not FileExists($pc_xml_path & "\invent\*") Then DirCreate($pc_xml_path & "\invent\")
; Now work out the list of installed packages for each machine generated xml file...
$filedelete = FileDelete($pc_xml_path & "\invent\*.csv")
;~ ConsoleWrite ("deleted files = " & $filedelete & @CRLF)
_make_xml_array($pc_xml_path)
 
;Write to the console a list of csv files in $pc_xml_path & "\invent\
$csv_files = _FileListToArray($pc_xml_path & "\invent\", "*.csv", 1)
ConsoleWrite(@CRLF)
For $r = 1 To $csv_files[0] Step 1
ConsoleWrite(StringUpper($csv_files[$r]) & @CRLF)
Next
ConsoleWrite(@CRLF & "The list of CSV files above are the files in " & $pc_xml_path & "\invent\ showing the inventory of the WPKG programs installed. " & _
"'ALL.CSV' is a concatination of all the indervidual CSV files." & @CRLF & @CRLF)
; Now sort out the mailing of the machines needing up/downgrading
_FileReadToArray($pc_xml_path & "\invent\all.csv", $all_csv_file)
$all_error_occurance_id = _ArrayFindAll($all_csv_file, "grade required", "", "", "", 1)
If @error < 1 Then For $o = 0 To _ArrayMaxIndex($all_error_occurance_id) Step 1 $error_list = $error_list & $all_csv_file[$all_error_occurance_id[$o]] & @CRLF Next ConsoleWrite("Machines and packages that differ from the Master XML files = " & @CRLF & @CRLF & $error_list & @CRLF)
If StringLen($email_address) > 0 Then If FileExists($mailsend) Then
$wpkg_invent_email_file = EnvGet("temp") & "\wpkg_invent_email.txt" $write2file = FileOpen($wpkg_invent_email_file, 2) FileWriteLine($write2file, $error_list) FileClose($write2file)
$sendmail = $mailsend & " -v -d " & $s_domain & " -smtp " & $s_SmtpServer & " " & $s_ToAddress & " -f " & $s_FromAddress & _ " -sub """ & $s_Subject & """ +cc +bc -m """ & $wpkg_invent_email_file & """,text/plain,i" $std_run_reg = Run($sendmail, "", "", $STDERR_CHILD + $STDOUT_CHILD)
$q = 1 $timewatch = TimerInit() ; Make a note of the current time While $q = 1
$std_out_read = StdoutRead($std_run_reg) $std_err_read = StderrRead($std_run_reg) If (StringLen($std_out_read) > 0) OR (StringLen($std_err_read) > 0) Then ConsoleWrite(@CRLF & @CRLF & "Email sent" & @CRLF) $q = 2 EndIf If TimerDiff($timewatch) > 5000 Then $q = 2 ConsoleWrite(@CRLF & @CRLF & "Error sending email :(" & @CRLF) EndIf WEnd Sleep(1000) FileDelete($wpkg_invent_email_file) Else ConsoleWrite("The file '" & EnvGet("LOGONSERVER") & "\netlogon\bin\mailsend.exe' is missing, unable to send any email" & @CRLF) EndIf
EndIf
Else
ConsoleWrite("All of the pcs are up to date with their WPKG packages" & @CRLF)
EndIf
Else
15
edits