Maintain control of your Microsoft 365 data
Post Reply
rtheseeker
Enthusiast
Posts: 56
Liked: 2 times
Joined: Sep 26, 2022 9:13 pm
Full Name: Rajeev Mehta
Contact:

Unique warning

Post by rtheseeker »

After some powershell scripting idea; at the moment; I want to run a script that parses through all the warning messages for all the job ran last night/latest and higlights any warning message which does not match a pre-defined set of warning mesages. I have been able to achive this using an excel sheet however it does involve a bit of work;
> Copy thousands of warning messages from each job to this excel sheet which has 4 colums of common warning defined in a formula
Cell A1 to A2000: Populate when I choose only warnings manually copy those to first cell
Cell B =IF(ISNUMBER(SEARCH("OneDrive was not found", A2)), "Match", "No Match")
CELL C: =IF(ISNUMBER(SEARCH("OneDrive was not found", A2)), "Match", "No Match")
Then I do a filter and anything that does not match these cells give me the unique warning; I try and run this once a week as there are thousands of warning messages every day
Is there a way to create a powershell; I tried using the below after suggestion from Fabian however could not find a way to put the multiple warning messages per job in an array so that I can loop through it; at the moment the below mentioned line of code only returns one warning mesage per job

Get-VBOJobSession -JobType backup -last | select -First 50 -ExpandProperty Log | select title | Whre-Object {$_.Title -notlike "*Success*"}
Mike Resseler
Product Manager
Posts: 8045
Liked: 1263 times
Joined: Feb 08, 2013 3:08 pm
Full Name: Mike Resseler
Location: Belgium
Contact:

Re: Unique warning

Post by Mike Resseler »

I assume you have a type in your PowerShell with the Where-Object and it is correct in your script :-)

I don't think it is possible like this to be honest, from what I understand, I think you need to use other tools to parse through the logs. Unfortunately my current lab has a specific build so I cannot test this but I will try to get someone to figure it out.
rtheseeker
Enthusiast
Posts: 56
Liked: 2 times
Joined: Sep 26, 2022 9:13 pm
Full Name: Rajeev Mehta
Contact:

Re: Unique warning

Post by rtheseeker » 1 person likes this post

I sorted it out; this script works
# Get the date of the previous night
$lastNight = (Get-Date).AddDays(-1).ToString("MM/dd/yyyy")

# Get all job sessions that ran last night with warnings
$lastNightSessions = Get-VBOJobSession -JobType Backup | Where-Object {
$_.CreationTime -ge $lastNight -and
$_.CreationTime -lt (Get-Date).ToString("MM/dd/yyyy") -and $_.JobName -like '*OneDrive*'
}

# Initialize $logs before using it
$logs = @()

foreach ($lastNightSession in $lastNightSessions) {
$logs += $lastNightSession.Log
}

# Display only warning logs excluding specific warnings
foreach ($log in $logs) {
if ($log.title -like '*warning*' -and
$log.title -notlike '*OneDrive was not found*' -and
$log.title -notlike '*does not have a valid Microsoft 365 license with SharePoint plan enabled*' -and
$log.title -notlike '*Failed to find group owner account*') {
$formattedLog = "{0} {1}" -f $log.title, $log.description
Write-Host $formattedLog
}
}
Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests