Windows Powershell Iphone Check Function

Discussion in 'iPhone' started by brownjamesa, Sep 21, 2016.

  1. brownjamesa, Sep 21, 2016
    Last edited: Sep 21, 2016

    brownjamesa macrumors member

    Joined:
    Sep 9, 2016
    #1
    For those of you that use Windows 10, you can use the following Powershell function to check the stock which helped me:

    1) Load the function into Windows Powershell by cut and pasting the following code (amend hash tables to suit your needs):


    Function IphoneCheck {
    #Create Hash Table to hold Phone your interested in
    $PhonesHT = @{
    'MN922B/A'='iPhone 7 128GB Black'
    'MN942B/A'='iPhone 7 128GB Gold'
    'MN962B/A'='iPhone 7 128GB Jet Black'
    'MN952B/A'='iPhone 7 128GB Rose Gold'
    'MN932B/A'='iPhone 7 128GB Silver'
    'MN972B/A'='iPhone 7 256GB Black'
    'MN992B/A'='iPhone 7 256GB Gold'
    'MN9C2B/A'='iPhone 7 256GB Jet Black'
    'MN9A2B/A'='iPhone 7 256GB Rose Gold'
    'MN982B/A'='iPhone 7 256GB Silver'
    'MN8X2B/A'='iPhone 7 32GB Black'
    'MN902B/A'='iPhone 7 32GB Gold'
    'MN912B/A'='iPhone 7 32GB Rose Gold'
    'MN8Y2B/A'='iPhone 7 32GB Silver'
    'MN4M2B/A'='iPhone 7 Plus 128GB Black'
    'MN4Q2B/A'='iPhone 7 Plus 128GB Gold'
    'MN4V2B/A'='iPhone 7 Plus 128GB Jet Black'
    'MN4U2B/A'='iPhone 7 Plus 128GB Rose Gold'
    'MN4P2B/A'='iPhone 7 Plus 128GB Silver'
    'MN4W2B/A'='iPhone 7 Plus 256GB Black'
    'MN4Y2B/A'='iPhone 7 Plus 256GB Gold'
    'MN512B/A'='iPhone 7 Plus 256GB Jet Black'
    'MN502B/A'='iPhone 7 Plus 256GB Rose Gold'
    'MN4X2B/A'='iPhone 7 Plus 256GB Silver'
    'MNQM2B/A'='iPhone 7 Plus 32GB Black'
    'MNQP2B/A'='iPhone 7 Plus 32GB Gold'
    'MNQQ2B/A'='iPhone 7 Plus 32GB Rose Gold'
    'MNQN2B/A'='iPhone 7 Plus 32GB Silver'
    }

    #Create Hash Table to hold Store locations
    $StoresHT = @{
    'R659'='Apple Watch at Selfridges'
    'R227'='Bentall Centre'
    'R113'='Bluewater'
    'R340'='Braehead'
    'R163'='Brent Cross'
    'R496'='Bromley'
    'R135'='Buchanan Street'
    'R118'='Bullring'
    'R252'='Cabot Circus'
    'R391'='Chapelfield'
    'R244'='Churchill Square'
    'R245'='Covent Garden'
    'R393'='Cribbs Causeway'
    'R545'='Drake Circus'
    'R341'='Eldon Square'
    'R482'='Festival Place'
    'R270'='Grand Arcade'
    'R308'='Highcross'
    'R242'='Lakeside'
    'R239'='Liverpool ONE'
    'R215'='Manchester Arndale'
    'R153'='Meadowhall'
    'R423'='Metrocentre'
    'R269'='Milton Keynes'
    'R328'='Princes Street'
    'R279'='Princesshay'
    'R092'='Regent Street'
    'R335'='SouthGate'
    'R334'='St Davids 2'
    'R410'='Stratford City'
    'R176'='The Oracle'
    'R255'='Touchwood Centre'
    'R136'='Trafford Centre'
    'R372'='Trinity Leeds'
    'R363'='Union Square'
    'R313'='Victoria Square'
    'R527'='Watford'
    'R174'='WestQuay'
    'R226'='White City'
    }


    $URL = 'https://reserve.cdn-apple.com/GB/en_GB/reserve/iPhone/availability.json'
    $WebContent = Invoke-WebRequest $URL
    $Stock = $WebContent | ConvertFrom-Json
    $LastUpdate = ([datetime]'1/1/1970').AddMilliseconds($Stock.updated).AddHours(1)
    $Results = $StoresHT.GetEnumerator() | Foreach-Object {
    $Store = $_
    $PhonesHT.GetEnumerator() | Foreach-Object {
    $Phone = $_
    $Obj = New-Object -TypeName PSObject
    Add-member -InputObject $Obj -MemberType noteproperty -name "Store" -value ($Store.Value)
    Add-member -InputObject $Obj -MemberType noteproperty -name "Phone" -value ($Phone.Value)
    Add-member -InputObject $Obj -MemberType noteproperty -name "Status" -value ($Stock.($Store.Name).($_.name))
    Add-member -InputObject $Obj -MemberType noteproperty -name "Last Updated" -value ($LastUpdate)
    $Obj
    }
    }
    $Results
    }


    2) Execute the function:

    PS C:\> IphoneCheck


    Store Phone Status Last Updated
    ----- ----- ------ ------------
    Highcross Plus Silver 256GB NONE 21/09/2016 11:42:06
    Highcross Plus Gold 256GB NONE 21/09/2016 11:42:06
    Highcross Plus Rose 128GB NONE 21/09/2016 11:42:06
    Highcross Plus Black 128GB NONE 21/09/2016 11:42:06
    Highcross Plus Black 256GB NONE 21/09/2016 11:42:06
    Highcross Plus Rose 256GB NONE 21/09/2016 11:42:06
    Highcross Plus Sliver 128GB NONE 21/09/2016 11:42:06
    Highcross Plus Gold 128GB NONE 21/09/2016 11:42:06
    BullRing Plus Silver 256GB NONE 21/09/2016 11:42:06
    BullRing Plus Gold 256GB NONE 21/09/2016 11:42:06
    BullRing Plus Rose 128GB NONE 21/09/2016 11:42:06
    BullRing Plus Black 128GB NONE 21/09/2016 11:42:06
    BullRing Plus Black 256GB NONE 21/09/2016 11:42:06
    BullRing Plus Rose 256GB NONE 21/09/2016 11:42:06
    BullRing Plus Sliver 128GB NONE 21/09/2016 11:42:06
    BullRing Plus Gold 128GB NONE 21/09/2016 11:42:06
    Touchwood Plus Silver 256GB NONE 21/09/2016 11:42:06
    Touchwood Plus Gold 256GB NONE 21/09/2016 11:42:06
    Touchwood Plus Rose 128GB NONE 21/09/2016 11:42:06
    Touchwood Plus Black 128GB UNLOCKED 21/09/2016 11:42:06
    Touchwood Plus Black 256GB UNLOCKED 21/09/2016 11:42:06
    Touchwood Plus Rose 256GB NONE 21/09/2016 11:42:06
    Touchwood Plus Sliver 128GB UNLOCKED 21/09/2016 11:42:06
    Touchwood Plus Gold 128GB NONE 21/09/2016 11:42:06

    Hope this helps someone, as it helped me grab my phones :)
     
  2. rockypee123 macrumors member

    Joined:
    Sep 7, 2016
    #2
    i know you may not have the time to do this but would you be able to make this more Layman friendly? Not really experienced with coding etc but wouldn't mind having this. Cheers
     
  3. CrispyUK macrumors newbie

    CrispyUK

    Joined:
    Sep 21, 2016
    #3
    Nice, thank you - looks like you're watching the same stores as me!

    Can you point me in the direction of a list of model numbers please? Struggling to hunt them down :(
     
  4. stonefeet macrumors regular

    stonefeet

    Joined:
    Mar 12, 2012
    #4
    well done man

    in layman's terms what you'd want to do is find the store codes for your area (somehow) and change this section to meet your needs

    'R118'='BullRing'
    'R255'='Touchwood'
    'R308'='Highcross'


    then run the code in either powershell as a ps1 file or in ISE
     
  5. l3uddz macrumors 6502

    Joined:
    Sep 11, 2014
    #5
    https://reserve.cdn-apple.com/GB/en_GB/reserve/iPhone/stores.json
     
  6. ventmore macrumors 6502

    Joined:
    Jul 13, 2008
    #6
    ^^^^That'll work too! :)

    Check the istocknow site for the store codes.
     
  7. CrispyUK macrumors newbie

    CrispyUK

    Joined:
    Sep 21, 2016
    #7
    To answer my own query, here's the Phones hash table section of code with all the models included, just delete any lines you're not interested in :)

    $PhonesHT = @{
    'MN922B/A'='iPhone 7 128GB Black'
    'MN942B/A'='iPhone 7 128GB Gold'
    'MN962B/A'='iPhone 7 128GB Jet Black'
    'MN952B/A'='iPhone 7 128GB Rose Gold'
    'MN932B/A'='iPhone 7 128GB Silver'
    'MN972B/A'='iPhone 7 256GB Black'
    'MN992B/A'='iPhone 7 256GB Gold'
    'MN9C2B/A'='iPhone 7 256GB Jet Black'
    'MN9A2B/A'='iPhone 7 256GB Rose Gold'
    'MN982B/A'='iPhone 7 256GB Silver'
    'MN8X2B/A'='iPhone 7 32GB Black'
    'MN902B/A'='iPhone 7 32GB Gold'
    'MN912B/A'='iPhone 7 32GB Rose Gold'
    'MN8Y2B/A'='iPhone 7 32GB Silver'
    'MN4M2B/A'='iPhone 7 Plus 128GB Black'
    'MN4Q2B/A'='iPhone 7 Plus 128GB Gold'
    'MN4V2B/A'='iPhone 7 Plus 128GB Jet Black'
    'MN4U2B/A'='iPhone 7 Plus 128GB Rose Gold'
    'MN4P2B/A'='iPhone 7 Plus 128GB Silver'
    'MN4W2B/A'='iPhone 7 Plus 256GB Black'
    'MN4Y2B/A'='iPhone 7 Plus 256GB Gold'
    'MN512B/A'='iPhone 7 Plus 256GB Jet Black'
    'MN502B/A'='iPhone 7 Plus 256GB Rose Gold'
    'MN4X2B/A'='iPhone 7 Plus 256GB Silver'
    'MNQM2B/A'='iPhone 7 Plus 32GB Black'
    'MNQP2B/A'='iPhone 7 Plus 32GB Gold'
    'MNQQ2B/A'='iPhone 7 Plus 32GB Rose Gold'
    'MNQN2B/A'='iPhone 7 Plus 32GB Silver'
    }
     
  8. brownjamesa, Sep 21, 2016
    Last edited: Sep 21, 2016

    brownjamesa thread starter macrumors member

    Joined:
    Sep 9, 2016
    #8
    The stores are below:


    $StoresHT = @{
    'R659'='Apple Watch at Selfridges'
    'R227'='Bentall Centre'
    'R113'='Bluewater'
    'R340'='Braehead'
    'R163'='Brent Cross'
    'R496'='Bromley'
    'R135'='Buchanan Street'
    'R118'='Bullring'
    'R252'='Cabot Circus'
    'R391'='Chapelfield'
    'R244'='Churchill Square'
    'R245'='Covent Garden'
    'R393'='Cribbs Causeway'
    'R545'='Drake Circus'
    'R341'='Eldon Square'
    'R482'='Festival Place'
    'R270'='Grand Arcade'
    'R308'='Highcross'
    'R242'='Lakeside'
    'R239'='Liverpool ONE'
    'R215'='Manchester Arndale'
    'R153'='Meadowhall'
    'R423'='Metrocentre'
    'R269'='Milton Keynes'
    'R328'='Princes Street'
    'R279'='Princesshay'
    'R092'='Regent Street'
    'R335'='SouthGate'
    'R334'='St Davids 2'
    'R410'='Stratford City'
    'R176'='The Oracle'
    'R255'='Touchwood Centre'
    'R136'='Trafford Centre'
    'R372'='Trinity Leeds'
    'R363'='Union Square'
    'R313'='Victoria Square'
    'R527'='Watford'
    'R174'='WestQuay'
    'R226'='White City'
    }


    Updated first post
    --- Post Merged, Sep 21, 2016 ---
    You can then do a where-object query like this:


    PS C:\> IphoneCheck | Where-Object {$_.Store -like 'Bullring'}

    Store Phone Status Last Updated
    ----- ----- ------ ------------
    Bullring iPhone 7 Plus 256GB Rose Gold NONE 21/09/2016 18:49:05
    Bullring iPhone 7 Plus 32GB Rose Gold NONE 21/09/2016 18:49:05
    Bullring iPhone 7 Plus 256GB Jet Black NONE 21/09/2016 18:49:05
    Bullring iPhone 7 Plus 128GB Rose Gold NONE 21/09/2016 18:49:05
    Bullring iPhone 7 32GB Gold UNLOCKED 21/09/2016 18:49:05
    Bullring iPhone 7 256GB Gold UNLOCKED 21/09/2016 18:49:05
    Bullring iPhone 7 256GB Rose Gold UNLOCKED 21/09/2016 18:49:05
    Bullring iPhone 7 Plus 128GB Jet Black NONE 21/09/2016 18:49:05
    Bullring iPhone 7 Plus 256GB Black NONE 21/09/2016 18:49:05
    Bullring iPhone 7 128GB Black UNLOCKED 21/09/2016 18:49:05
    Bullring iPhone 7 256GB Jet Black NONE 21/09/2016 18:49:05
    Bullring iPhone 7 Plus 32GB Silver NONE 21/09/2016 18:49:05
    Bullring iPhone 7 32GB Rose Gold UNLOCKED 21/09/2016 18:49:05
    Bullring iPhone 7 256GB Black UNLOCKED 21/09/2016 18:49:05
    Bullring iPhone 7 Plus 128GB Silver NONE 21/09/2016 18:49:05
    Bullring iPhone 7 128GB Gold UNLOCKED 21/09/2016 18:49:05
    Bullring iPhone 7 Plus 256GB Silver NONE 21/09/2016 18:49:05
    Bullring iPhone 7 Plus 32GB Gold NONE 21/09/2016 18:49:05
    Bullring iPhone 7 256GB Silver UNLOCKED 21/09/2016 18:49:05
    Bullring iPhone 7 Plus 128GB Gold NONE 21/09/2016 18:49:05
    Bullring iPhone 7 32GB Black NONE 21/09/2016 18:49:05
    Bullring iPhone 7 Plus 256GB Gold NONE 21/09/2016 18:49:05
    Bullring iPhone 7 Plus 32GB Black NONE 21/09/2016 18:49:05
    Bullring iPhone 7 Plus 128GB Black NONE 21/09/2016 18:49:05
    Bullring iPhone 7 32GB Silver UNLOCKED 21/09/2016 18:49:05
    Bullring iPhone 7 128GB Silver UNLOCKED 21/09/2016 18:49:05
    Bullring iPhone 7 128GB Jet Black NONE 21/09/2016 18:49:05
    Bullring iPhone 7 128GB Rose Gold UNLOCKED 21/09/2016 18:49:05

    or

    PS C:\> IphoneCheck | Where-Object {$_.Store -like 'Bullring' -AND $_.Status -ne 'None'}

    Store Phone Status Last Updated
    ----- ----- ------ ------------
    Bullring iPhone 7 32GB Gold UNLOCKED 21/09/2016 18:50:05
    Bullring iPhone 7 256GB Gold UNLOCKED 21/09/2016 18:50:05
    Bullring iPhone 7 256GB Rose Gold UNLOCKED 21/09/2016 18:50:05
    Bullring iPhone 7 128GB Black UNLOCKED 21/09/2016 18:50:05
    Bullring iPhone 7 32GB Rose Gold UNLOCKED 21/09/2016 18:50:05
    Bullring iPhone 7 256GB Black UNLOCKED 21/09/2016 18:50:05
    Bullring iPhone 7 128GB Gold UNLOCKED 21/09/2016 18:50:05
    Bullring iPhone 7 256GB Silver UNLOCKED 21/09/2016 18:50:05
    Bullring iPhone 7 32GB Silver UNLOCKED 21/09/2016 18:50:05
    Bullring iPhone 7 128GB Silver UNLOCKED 21/09/2016 18:50:05
    Bullring iPhone 7 128GB Rose Gold UNLOCKED 21/09/2016 18:50:05
    --- Post Merged, Sep 21, 2016 ---
    PS C:\> IphoneCheck | Where-Object {$_.Status -ne 'None'}

    Store Phone Status Last Updated
    ----- ----- ------ ------------
    Highcross iPhone 7 32GB Gold UNLOCKED 21/09/2016 18:51:05
    Highcross iPhone 7 256GB Gold UNLOCKED 21/09/2016 18:51:05
    Highcross iPhone 7 256GB Rose Gold UNLOCKED 21/09/2016 18:51:05
    Highcross iPhone 7 Plus 256GB Black UNLOCKED 21/09/2016 18:51:05
    Highcross iPhone 7 128GB Black UNLOCKED 21/09/2016 18:51:05
    Highcross iPhone 7 256GB Black UNLOCKED 21/09/2016 18:51:05
    Highcross iPhone 7 Plus 128GB Silver UNLOCKED 21/09/2016 18:51:05
    Highcross iPhone 7 128GB Gold UNLOCKED 21/09/2016 18:51:05
    Highcross iPhone 7 256GB Silver UNLOCKED 21/09/2016 18:51:05
    Highcross iPhone 7 Plus 32GB Black UNLOCKED 21/09/2016 18:51:05
    Highcross iPhone 7 Plus 128GB Black UNLOCKED 21/09/2016 18:51:05
    Highcross iPhone 7 32GB Silver UNLOCKED 21/09/2016 18:51:05
    Highcross iPhone 7 128GB Silver UNLOCKED 21/09/2016 18:51:05
    Highcross iPhone 7 128GB Rose Gold UNLOCKED 21/09/2016 18:51:05
    Bullring iPhone 7 32GB Gold UNLOCKED 21/09/2016 18:51:05
    Bullring iPhone 7 256GB Gold UNLOCKED 21/09/2016 18:51:05
    Bullring iPhone 7 256GB Rose Gold UNLOCKED 21/09/2016 18:51:05
    Bullring iPhone 7 128GB Black UNLOCKED 21/09/2016 18:51:05
    Bullring iPhone 7 32GB Rose Gold UNLOCKED 21/09/2016 18:51:05
    Bullring iPhone 7 256GB Black UNLOCKED 21/09/2016 18:51:05
    Bullring iPhone 7 128GB Gold UNLOCKED 21/09/2016 18:51:05
    Bullring iPhone 7 256GB Silver UNLOCKED 21/09/2016 18:51:05
    Bullring iPhone 7 32GB Silver UNLOCKED 21/09/2016 18:51:05
    Bullring iPhone 7 128GB Silver UNLOCKED 21/09/2016 18:51:05
    Bullring iPhone 7 128GB Rose Gold UNLOCKED 21/09/2016 18:51:05
    --- Post Merged, Sep 21, 2016 ---
    Query just for pluses:

    PS C:\> IphoneCheck | Where-Object {$_.Status -ne 'None' -AND $_.Phone -match 'Plus'}

    Store Phone Status Last Updated
    ----- ----- ------ ------------
    Highcross iPhone 7 Plus 256GB Black UNLOCKED 21/09/2016 18:52:09
    Highcross iPhone 7 Plus 128GB Silver UNLOCKED 21/09/2016 18:52:09
    Highcross iPhone 7 Plus 32GB Black UNLOCKED 21/09/2016 18:52:09
    Highcross iPhone 7 Plus 128GB Black UNLOCKED 21/09/2016 18:52:09
     
  9. hk_willis_chan macrumors newbie

    hk_willis_chan

    Joined:
    Sep 22, 2016
    #9
    Just curious, can make this able to run on Powershell v4?
     

Share This Page