TheLug Posted February 17, 2018 Posted February 17, 2018 So I have a ton of machines that have a ini file in the windows dir. I need to pull a specific fields value and save all that data in one place. I was going to push out my script via SCCM once ready. I can pull the data from the field. But what would be the best way to put that info into a file? The initial thought was to create a new ini file with the PC ID, the copy that file to a network share. But I am thinking there has gotta be something better, like saving to a csv, using powershell, etc. Any help would be appreciated. $LogFileDir = ("C:\LogFiles") $OriginalIni = (@WindowsDir & "\Original.ini") $OriginalIniRead = IniRead ($OriginalIni, "Scanner","ComPort","Null") $Server = ("\\ServerName") MsgBox (64,"Scanner ini COM Port",$OriginalIniRead,4) IniWrite ($Server & "\" & @ComputerName & ".ini" , "OriginalComPort" , "Value" , $OriginalIniRead)
Subz Posted February 17, 2018 Posted February 17, 2018 You could write to a single file with @ComputerName as the Key Name using a timer (if the file fails to write because its been written to by another computer) for example: While 1 If IniWrite($Server & "\ComPorts.ini" , @ComputerName, "OriginalComPort" , $OriginalIniRead) = 0 Then Sleep(Random(5000, 15000)) ;~ Wait between 5 and 10 seconds before trying again. Else ExitLoop EndIf Wend Or you could write to csv file using similar method for example: Local $sFileName = "\\Server\ComPort.csv" While 1 If FileWrite($sFileName, @ComputerName & "," & "Original Comport" & "," & IniRead ($OriginalIni, "Scanner","ComPort","Null") & @CRLF) = 0 Then Sleep(Random(5000, 15000)) ;~ Sleep 5 - 15 Seconds and try again Else ExitLoop EndIf Wend Alternatively you could write to individual .ini files like you have posted and then use a separate script to write that data into csv format for example: #include <File.au3> Local $hFileList = FileOpen(@ScriptDir & "\" & @Year & "-" & @Mon & "=" & @MDay & "_Comport.csv", 2) Local $aFileList = "\\Server", "*.ini", 1, 0, 1, 0) If @Error Then Exit MsgBox(32, "Error", "Unable to find any ini files.") Local $sOriginalComPort = "" For $i = 1 To $aFileList[0] FileWrite($hFileList, StringReplace($aFileList[0], ".ini", "") & "," & IniRead ("\\Server\" & $aFileList[$i], "OriginalComPort" , "Value", "Null") & @CRLF) Next Please note none of the code above has been tested, but hopefully should give you some ideas. TheLug 1
TheLug Posted February 17, 2018 Author Posted February 17, 2018 1 hour ago, Subz said: Local $sFileName = "\\Server\ComPort.csv" While 1 If FileWrite($sFileName, @ComputerName & "," & "Original Comport" & "," & IniRead ($OriginalIni, "Scanner","ComPort","Null") & @CRLF) = 0 Then Sleep(Random(5000, 15000)) ;~ Sleep 5 - 15 Seconds and try again Else ExitLoop EndIf Wend I think this is gonna get the job done!!! Great idea thanks so much!!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now