Tuesday, April 24, 2018

powershell windows eventlog filter

Here is a little powershell line to filter events in powershell:

SYSTEM is the group the event is in
PROVIDERNAME is the category / type
MESSAGE is the content / description of the event
(change the keywords as needed)

# find reboots
Get-WinEvent -LogName System -MaxEvents 10000 | Where-Object {$_.providername -like "*kernel*" -and $_.Message -like "*démarré*"} | format-table Timecreated, Leveldisplayname, message -auto -wrap

# isolate a day to find the cause of the reboot
Get-WinEvent -LogName System -MaxEvents 10000 | Where-Object {$_.timecreated -le "2018-04-19" -and $_.timecreated -gt "2018-04-18 14:00:00"} | format-table Timecreated, Leveldisplayname, message -auto -wrap

remote version:
$machine01 = ""
$login01 = "compagny\user"
$password01 = "usuallydonotputpasswordofadmininascript"

$Credential= New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $login01,($password01 | ConvertTo-SecureString -AsPlainText -Force)

#Get-WinEvent -Credential $Credential -ComputerName $Machine01 -LogName System -MaxEvents 5000 | Where-Object {$_.providername -like "*kernel*" -and $_.Message -like "*démarré*"} | format-table Timecreated, Leveldisplayname, message -auto -wrap

# isolate a day
Get-WinEvent -LogName System -MaxEvents 1500 -Credential $Credential -ComputerName $Machine01 | `
Where-Object {$_.timecreated -le "2018-05-01" -and $_.timecreated -gt "2018-04-14 14:00:00" -and $_.message -like "*vid*"} | `
format-table Timecreated, Leveldisplayname, message -auto -wrap

Monday, April 9, 2018

Access extract all vba modules for versionning support

Hello,

I wanted to extract all VBA modules from Microsoft ACCESS to be able to use GIT for versionning my VBA code

Here is a VBA macro to extract all module in a subfolder called:
[current directory of access file]\VBAProjectFiles

In microsoft access4
ALT F11
new module
copy paste this code in the module
run it

every file will be overwritten each time, but eh, GIT will see what line were added and deleted in each module

Required:
Access to VBA models in options, confidentiality center


-------------------- VBA module99 ---------------------------------

Option Compare Database

'====================================================
' exportation des modules VBA pour push dans GIT
'====================================================
Public Sub exportVBAlinebyline()

    path00 = CurrentDb.Name
    pathend00 = InStrRev(path00, "\")
    path01 = Left(path00, Len(path00) - (Len(path00) - pathend00))
    filename00 = Right(path00, (Len(path00) - pathend00))
    filename01 = Replace(filename00, ".", "")
   
    ' The reference for the FileSystemObject Object is Windows Script Host Object Model
    ' but it not necessary to add the reference for this procedure.
   
    Dim objfso As Object
    Dim file01 As Object
    Dim strMod As String
    Dim mdl As Object
    Dim i As Integer
   
    Set objfso = CreateObject("Scripting.FileSystemObject")
   
    ' Set up the file.
    ' SpFolder is a small function, but it would be better to fill in a
    ' path name instead of SpFolder(Desktop), eg "c:\users\somename\desktop"
   
    path02 = path01 & "VBAProjectFiles"
    If objfso.FolderExists(path02) = False Then
        err01 = 0: err02 = "": On Error Resume Next
        objfso.createfolder path02
        err01 = Err.number: err02 = Err.Description: On Error GoTo 0
    Else
        '=== folder already exist
    End If
   
    If err01 = 0 Then
       
        '=== list of all modules
        Set file01 = objfso.CreateTextFile(path01 & "\" & filename01 & "_liste.txt")
       
       
        '=== For each component in the project ...
        For Each mdl In VBE.ActiveVBProject.VBComponents
            '=== list of all modules
            file01.writeline mdl.Name
           
            Set file02 = objfso.CreateTextFile(path02 & "\" & mdl.Name & ".txt")
            '=== using the count of lines ...
            i = VBE.ActiveVBProject.VBComponents(mdl.Name).CodeModule.CountOfLines
            '=== put the code in a string ...
            If i > 0 Then
               strMod = VBE.ActiveVBProject.VBComponents(mdl.Name).CodeModule.Lines(1, i)
            End If
            '=== and then write it to a file, first marking the start with
            '=== some equal signs and the component name.
            file02.writeline strMod
            file02.Close
        Next
       
        '=== Close eveything
        file01.Close
        Set objfso = Nothing
       
    Else
        MsgBox ("ERROR cannot create folder: " & vbCrLf & path02)
    End If
   
End Sub