powershell

Querying the JC Decaux API using PowerShell

JC Decaux have released an official API that can be used to query the Dublin Bikes scheme as well as other schemes they manage, e.g. Dublin Bikes in Dublin (Ireland) & Cyclocity in Vilnius (Lithuania).
I threw together a quick and dirty PowerShell script for querying the API. If you'd like to play around, you'll need to register for an API key at https://developer.jcdecaux.com/


#
#	Title :: JC Decaux OpenData Client
#	Purpose :: Can be used to query city bike schemes managed by JC Decaux, e.g. Dublin Bikes
#	
#

## Variables
$api = "API KEY GOES HERE"

$contractsURL = "https://api.jcdecaux.com/vls/v1/contracts"
$stationsURL = "https://api.jcdecaux.com/vls/v1/stations"

## Functions
function invoke-jcdclient {
param (
		[string]
		$url,
		[string]
		$contract
)
	#
	
	$response = Invoke-RestMethod -Uri $url -Method Get -ContentType 'application/json'
	return $response
}

function get-jcdcontracts {
param(
		[string]
		$apikey
)
	#
	$response = invoke-jcdclient -url "$($contractsURL)?apiKey=$($apiKey)"
	return $response
}

function get-jcdstations {
param(
		[string]
		$apikey,
		[string]
		$contract
)
	#
	
	$response = invoke-jcdclient -url "$($stationsURL)?contract=$($contract)&apiKey=$($apiKey)"
	return $response
}

function get-jcdstation {
param(
		[string]
		$apikey,
		[int]
		$number,
		[string]
		$contract
)
	#
	#Write-Host "$($stationsURL)/$($number)?contract=$($contract)&apiKey=$($apiKey)"
	$response = invoke-jcdclient -url "$($stationsURL)/$($number)?contract=$($contract)&apiKey=$($apiKey)"
	return $response
}

## Runtime

# Get list of all 'contracts' aka JCD locations
$contracts = get-jcdcontracts -apikey $api

# Get all stations in 'contract' location, e.g. Dublin, Vilnius
# Output results to table
$stations = get-jcdstations -apikey $api -contract 'dublin'
$stations | ft -AutoSize

# Get specific station number in a specific 'contract' location
# e.g. Station 40 (Jervis Street) in Dublin
$station = get-jcdstation -number 40 -apikey $api -contract 'dublin'

$station
# Convert the milliseconds since epoch into DateTime
#([timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds((0 + $station.last_update)/1000))).DateTime

Office 365 : Reclaiming licenses

Migrated to Office 365? Running low on licenses and want to do a review of existing license assignments?

In work, we recently had to do a reclamation of licenses from users who had left the company but had somehow managed to retain their licensing status in Office 365.

To help with this I created a powershell script that would get a list of disabled Active Directory accounts who had a UPN (UserPrincipalName) that was formatted for use in Office 365 and cross reference that with the list of licensed users in Microsoft Online Services. Surprisingly Microsoft haven't included something like this in the existing views. I'm sure it'll be added in an upgrade...

Behold the results! Make sure you change the UPN value being queried below as I'd be surprised if ye're using DOMAIN.COM! All comments and suggestions on improvements are welcome. I'm relatively new to Powershell.

Import-Module ActiveDirectory
Import-Module msonline

Connect-MsolService -Credential (Get-Credential)

#$ErrorActionPreference = $SilentlyContinue

# Create counter and results array
[int]$i = 0
$results = @()

# Query AD for all accounts with UPN needed for Office365 that are disabled and save to array
$disabledUsers = Get-ADUser -Filter ({UserPrincipalName -like "*@DOMAIN.COM" -AND enabled -eq $false}) | select UserPrincipalName

# For all entries in $disabledUsers, query their licensing status on MS Online and save to $results
for ($i=0; $i -le ($disabledUsers.count-1); $i++) {
	$results += get-msoluser -UserPrincipalName $disabledUsers[$i].UserPrincipalName -ErrorAction SilentlyContinue
}
# For all $results where isLicensed is TRUE, output the DisplayName and License status
for ($i=0; $i -le ($results.count-1); $i++){
	if ($results[$i].isLicensed -eq "True"){
		$results[$i] | select DisplayName, IsLicensed 
	}
}