GetSaraScan.ps1


<#PSScriptInfo
 
.VERSION 2.1.0
 
.GUID 7e1ce83f-5542-4262-85a3-3685eb2e1c4c
 
.AUTHOR Jeffrey Speer
 
.COMPANYNAME
 
.COPYRIGHT
 
.TAGS
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
.PRIVATEDATA
 
#>
 



<#
 
.DESCRIPTION
This script gets a ConfigurationDetails HTML file from a machine with Outlook installed without needing to manipulate file paths or even with a UI item.
 
#>
 

Param()


Set-Content -Path C:\Users\Admin_jspeer\Desktop\GetSaraScan\GetSaraScan.ps1 -Value @"
<#
.SYNOPSIS
This script gets a ConfigurationDetails HTML file from a machine with Outlook installed without needing to manipulate file paths or even with a UI item.
.VERSION
2.0.0
.AUTHOR
Jeffrey Speer
#>
 
# Your actual script logic goes here
"@



# So Microsoft killed SARA right?
# Let's go get ourselves a SARA scan using the Enterprise version of SARA :)
 
# Couldn't bear but try and decorate this
Write-Host "#####################################################################" -ForegroundColor Magenta
Write-Host "# SARA Installer by Jeff Speer #" -ForegroundColor Magenta
Write-Host "# #" -ForegroundColor Magenta
Write-Host "# This script was built after Microsoft decided to end SARA. #" -ForegroundColor Magenta
Write-Host "# Running this script assumes you have write access to your Desktop.#" -ForegroundColor Magenta
Write-Host "# #" -ForegroundColor Magenta
Write-Host "# #" -ForegroundColor Magenta
Write-Host "# TOS: #" -ForegroundColor Magenta
Write-Host "# - I am not a pro, edit as you please. #" -ForegroundColor Magenta
Write-Host "# - The script can take a few minutes to #" -ForegroundColor Magenta
Write-Host "# complete. Have Outlook Open. #" -ForegroundColor Magenta
Write-Host "# - Does not work with New Outlook. #" -ForegroundColor Magenta
Write-Host "# - Scipt assumes you have Edge installed. #" -ForegroundColor Magenta
Write-Host "# If not, install it. Or Modify #" -ForegroundColor Magenta
Write-Host "# -Files Installed are placed on Desktop #" -ForegroundColor Magenta
Write-Host "# and are from Official Microsoft library #" -ForegroundColor Magenta
Write-Host "# #" -ForegroundColor Magenta
Write-Host "# See here: https://learn.microsoft.com/ #" -ForegroundColor Magenta
Write-Host "# en-us/microsoft-365/troubleshoot/ #" -ForegroundColor Magenta
Write-Host "# administration/assistant-outlook-scan #" -ForegroundColor Magenta
Write-Host "#####################################################################" -ForegroundColor Magenta
 
# First thing we need to do is ensure the folder where SARA will upload our SARA scan is otherwise empty or non existent
# This is just a best practice so it doesn't error out and always starts a fresh
# We just want this to stop once our log file is uploaded and then we can pull it
# Logs are typically stored here: C:\Users\YOURUSERNAME\AppData\Local\SaRALogs\UploadLogs
 
# Define the path you want to check and delete
$path = "$Env:USERPROFILE\AppData\Local\SaRALogs\UploadLogs"
 
# Check if the path exists
if (Test-Path $path) {
    # If it exists remove the item
    Remove-Item $path -Recurse -Force
    Write-Output "The path '$path' has been deleted."
} else {
    Write-Output "The path '$path' does not exist."
}
 
# Define the URL of the file to download
$url = "https://download.microsoft.com/download/13eaffaa-0961-4a6a-863b-26d1f8b0ca15/SaRACmd_17_01_2877_000.zip"
 
# Define the path where the file will be saved on the Desktop
$desktopPath = [System.Environment]::GetFolderPath('Desktop')
$filePath = Join-Path -Path $desktopPath -ChildPath "file.zip"
 
# Download the file and save it to the specified path
Invoke-WebRequest -Uri $url -OutFile $filePath
Write-Output "File downloaded successfully to $filePath"
 
# Unzip the downloaded file
$newFolderName = "SaraUnzipped"
$newFolderPath = Join-Path -Path $desktopPath -ChildPath $newFolderName
 
# Create the new folder
New-Item -Path $newFolderPath -ItemType Directory
 
Write-Output "Folder '$newFolderName' created on your desktop."
 
# Unzip the file
Expand-Archive -LiteralPath $filePath -DestinationPath $newFolderPath
 
 
# Define the path to the exe
$saRAcmdPath = Join-Path -Path $newFolderPath -ChildPath "SaRAcmd.exe"
 
# Ensure that the executable path exists
if (Test-Path $saRAcmdPath) {
    Write-Output "SaRAcmd.exe found at '$saRAcmdPath'"
   
    # Define the arguments to pass to the executable
    $args = "-S ExpertExperienceAdminTask -AcceptEula"
 
    # Run the command using Start-Process with proper argument handling
    Start-Process -FilePath $saRAcmdPath -ArgumentList $args -NoNewWindow
    Write-Host "SaRA scan started in the background."
 
} else {
    Write-Output "SaRAcmd.exe not found at '$saRAcmdPath'."
}
 
# Folder path to monitor
$pathToMonitor = "$Env:USERPROFILE\AppData\Local\SaRALogs\"
$folderName = "UploadLogs"
$fullPath = Join-Path -Path $pathToMonitor -ChildPath $folderName
 
# Wait for the folder to be created
while (-not (Test-Path -Path $fullPath -PathType Container)) {
    Write-Host "Waiting for folder $folderName to be created. This can take a few minutes..."
    Write-Host "Trying again in 15 seconds"
 
    Start-Sleep -Seconds 15
}
 
Write-Host "Folder $folderName has been created at $fullPath!"
 
# Now check for the HTML file starting with 'ConfigurationDetails' Filename is dynamic
$file = Get-ChildItem -Path $fullPath -Filter "ConfigurationDetails*.html" -File | Select-Object -First 1
 
# Check if the file exists
if ($file) {
    # If the file is found open it in Edge
    Start-Process "msedge" $file.FullName
    Write-Output "Opening file: $($file.FullName)"
} else {
    Write-Output "No file starting with 'ConfigurationDetails' found in $fullPath."
}
Write-Host -ForegroundColor Green "Terminated. Exit code 0."
Read-Host -Prompt "Press Enter to exit"
# I hope this was fun. No dealing with file path manipulation opening cmd. This literally once run, manipulates the file paths, downloads, executes and opens the SARA report right in front of you.