As our business continues to focus on providing white labeled Tier 3 IT support services, RMM as a service, and co-managed IT services this blog will be highlighting tips for RMM automation. Here is one of the recent updates we are making to several of our scripts. It is great to have a diagnostic script that outputs information and review those logs to help figure out issues or to write out the log file created to output for review from the RMM.
What if you have a software tool that aggregates log files to look for trends or security issues across the organization. Running the script and manually collecting log files from each computers gets tedious at scale, so I came up with the idea to automate the log collection via sending them to a FTP site. Here is what we are adding to scripts:
It is important to not store variables in scripts especially when they are credentials for the FTP server, so make sure to define variables accordingly. Here are the variables we are using for this script:
- $LocalDir = the local directory where you expect to find the logs from the script
- $RemoteDir = the FTP server address and file directory structure (ie ftp://myftpserver.com/LOGS)
- $FTPUsername = username for the FTP server
- $FTPPassword = password for the FTP server
$LatestLogFile = Get-ChildItem -Path $LocalDir -Filter *.log | Sort -Property CreationTime -Descending | Select -First 1
$RemoteFile = $RemoteDir + "/" + $($LatestLogFile.Name)"
# Create FTP Request Object
$FTPRequest = [System.Net.FtpWebRequest]::Create("$RemoteFile")
$FTPRequest = [System.Net.FtpWebRequest]$FTPRequest
$FTPRequest.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$FTPRequest.Credentials = new-object System.Net.NetworkCredential($FTPUsername, $FTPPassword)
$FTPRequest.UseBinary = $true
$FTPRequest.UsePassive = $true
# Read the File for Upload
$FileContent = Get-Content -Encoding Byte -Path $LatestLogFile.FullName
$FTPRequest.ContentLength = $FileContent.Length
# Get Stream Request by bytes
$Run = $FTPRequest.GetRequestStream()
$Run.Write($FileContent, 0, $FileContent.Length)
Notice that we use the $LatestLogFile variable to find the most recent log file. Edit this as needed (ie *.txt or whatever) to get the newest log file name. Adding this to the end of the RMM automation script will allow the needed log files to be placed in the FTP server. Collecting from multiple machines means that each file collected should have a different file name, so make sure when you are scripting the diagnostic that you use to name the log file with $env:computername or some other identifier to make sure the files don’t overwrite themselves when uploaded.
If your company is a MSP or wants to become one and automation just seems out of reach, then contact us to run your RMM for you.