Deployment Marker using power shell script

Hi,

I am sharing my script for deployment marker created in power shell, it goes through your environments list and marks deployments.

# created on 9th Feb 2018
# Author: Manas Khanna
# get all applications Invoke-WebRequest -Uri https://api.newrelic.com/v2/applications.json -Method GET -Headers @{'X-Api-Key'='$yourkey'} 

#function to write log to file.
Function LogWrite
{
   Param ([string]$logstring)

   Add-content $Logfile -value $logstring
}

# function to provide timestamp for logs.
function Get-TimeStamp {
    
    return "[{0:MM/dd/yy} {0:HH:mm:ss}]" -f (Get-Date)
    
}

#Declare variables with process details and log location.
$revision = Read-Host -Prompt 'Provide the revision number'
$changelog = Read-Host -Prompt 'Provide Change log number'
$description = Read-Host -Prompt 'Provide description'
$user = Read-Host -Prompt 'Provide your email id here'
$Logfile = "C:\temp\releasescript.txt"
Write-Host "Log string path where you are running the script -> ${Logfile}"



#write log 
LogWrite("$(Get-TimeStamp): Starting the script for Deplyoment Marker")
#	

$bodyvalue = @{"deployment" = @{"revision" = ${revision}; "changelog" = ${changelog}; "description" = ${description};  "user" = ${user}}}
$jsonbody = ConvertTo-Json $bodyvalue
Write-Host $jsonbody

Write-Host "Starting the script for Deplyoment Marker"
#application id List.
$appid1 =  #appid1
#"name": "addnamefor tracking",

$appid2 = #appid2
#"name": "addnamefor tracking",

$APPICATIONID = $appid1, $appid2
#Read-Host -Prompt "Press any key to continue or CTRL+C to quit" 


Foreach ($APPID in $APPICATIONID)
{

Invoke-WebRequest -Uri https://api.newrelic.com/v2/applications/${APPID}/deployments.json -Method POST -Headers @{'X-Api-Key'='$addyourkey'} -ContentType 'application/json' -Body $jsonbody
#write log 
    LogWrite("$(Get-TimeStamp): ${APPID} Deployments marked")
    Write-Host "${APPID} Deployment Marked"
    #Read-Host -Prompt "Press any key to continue or CTRL+C to quit" 
}
    


#write log 
    LogWrite("$(Get-TimeStamp): Deployments marked")
     Write-Host "Script ended Deployments marked"
## Script ends.

hope it helps.

enjoy
Manas

8 Likes

Thanks so much @MKhanna! I bet a lot of folks are going to find this VERY handy!

1 Like

@hross happy to contribute and help.

2 Likes