Sponsored

PowerShell to check for Build Sheet

TurpJL

Well-Known Member
Joined
Apr 27, 2018
Threads
4
Messages
48
Reaction score
17
Location
MidWest
Vehicle(s)
2018 JLU Rubicon manual - Ordered 3/3
My build sheet became available today, so I know this at least worked for me and thought I would share.

I was bored a while back and wrote a PowerShell script to go check for the build sheet so I did not have to do it everyday. I assume CryptoSticker uses some similar logic because I got the notification from there right after mine.

Change the VIN in the $URL to match yours, open PowerShell, paste it in and hit enter. Once found, it will open your default browser with the buildsheet.

If your build sheet is there, you should be able to change the $URL to check for the Window Sticker instead:
$URL = "https://www.chrysler.com/hostd/windowsticker/getWindowStickerPdf.do?vin=1C4HJXFG7JWXXXXXX"

If I had to do this more often than my vehicle, this could be cleaned up quite a bit:


$Check = 0
$URL = "https://www.jeep.com/webselfservice/BuildSheetServlet?vin=1C4HJXFG7JWXXXXXX"

While ($Check -eq 0) {

if ((Invoke-WebRequest -Uri $URL).Rawcontentlength -gt 1200) {
Write-host "Build Sheet Available"
$check = 1
Start-Process $URL}

Else
{write-host "No Build Sheet"
#Sleep for 8 hours before checking again
Start-Sleep -Seconds 28800}
}
Sponsored

 

Brandonjjon

Well-Known Member
Joined
Feb 21, 2017
Threads
6
Messages
85
Reaction score
53
Location
TX
Vehicle(s)
2021 Rubicon 4XE (Granite)
Nice job! Always fun to see community code creations/contributions. For no particular reason, I decided I wanted to refactor your script a bit, having no prior knowledge of Powershell.. here's the fruits of that labor:

  • Added some sass to the informational messages (why not?)
  • Added window sticker checking (was only build sheet checking before)

Code:
[Jeep]::statusCheck("1C4HJXFG3JWXXXXXX")

class Jeep {
    
    # Class properties
    hidden $Options = @{
        Vin = "";
        Timer = 28800;
        Types = @{
            BuildSheet = @{
                url = "https://www.jeep.com/webselfservice/BuildSheetServlet?vin=";
                found = $false;
            }
            WindowSticker = @{
                url = "https://www.jeep.com/hostd/windowsticker/getWindowStickerPdf.do?vin=";
                found = $false;
            }
        };
        Loop = $true
    }

    # Named Constructor
    static [Jeep] statusCheck($Vin) {
        return [Jeep]::New($Vin)
    }

    # Constructor
    Jeep ([String] $Vin) {
        $this.Options.Vin = $Vin

        While ($this.Options.Loop) {
            $this.checkBuildSheet()
            $this.checkWindowSticker()
            $this.handleLoop()

            # Sleep for 8 hours before checking again
            # Start-Sleep -Seconds 28800
            Start-Sleep -Seconds $this.Options.Timer
        }
    }

    # Creates a timer to continually check for status updates
    [Void] handleLoop() {
        $continueLoop = $true
        foreach ($type in $this.Options.Types.Keys) {
            if ($this.Options.Types.$type.found) {
                $continueLoop = $false
            } else {
                $continueLoop = $true
            }
        }

        if (!$continueLoop) {
            $this.log("Nothing left to check! Now exiting...")
            exit
        }

        $this.log("I will check for you again soon!")
        Write-Host ""

        $this.Options.Loop = $continueLoop
    }

    # Sets the found status for the type of check
    [Void] setStatus([String] $type, [Bool] $status) {
        $this.Options.Types.$type.found = $status
    }

    # Gets the status for the type of check
    [Bool] getStatus([String] $type) {
        return $this.Options.Types.$type.found
    }

    # Wrapper for Write-Host, appends datetime or whatever you want to the output
    [String] log([String] $data) {
        return Write-Host "[$(Get-Date -Format g)] $data"
    }

    # Creates the request to the webpage
    [Bool] Request([String] $type) {
        if (!$this.Options.Types.ContainsKey($type)) {
            throw "An incompatible type was provided. Please specify wether you want to check for a buildsheet or windowsticker"
        }

        $url = $this.Options.Types.$type.url + $this.Options.Vin

        return (Invoke-WebRequest -Uri $url).Rawcontentlength -gt 1200
    }

    # Checks for build sheet availability
    [Void] checkBuildSheet() {
        $type = "BuildSheet"
        if (!$this.getStatus($type)) {
            if ($this.Request($type)) {
                $this.log("Build sheet available! Stand by, launching your browser...")
                $this.setStatus($type, $true)
                Start-Process ($this.Options.Types.$type.url + $this.Options.Vin)
            } else {
                $this.log("No build sheet detected :(")
            }
        }
    }

    # Checks for window sticker availability
    [Void] checkWindowSticker() {
        $type = "WindowSticker"
        if (!$this.getStatus($type)) {
            if ($this.Request($type)) {
                $this.log("Window sticker available! Stand by, launching your browser...")
                $this.setStatus($type, $true)
                Start-Process ($this.Options.Types.$type.url + $this.Options.Vin)
            } else {
                $this.log("No window sticker detected :(")
            }
        }
    }
}
It's obviously overkill for it's purpose, but it was fun. Also I coded this on my macbook and did not test this on windows at all. Who knows what bugs exist! But it does seem to work for the light testing I did.

Feel free to comment on it here:
https://gist.github.com/brandonjjon/7ed8018e1bdffdd900a51786227b2564
 
 



Top