Skip to content

Instantly share code, notes, and snippets.

@mtcoffee
mtcoffee / setBanner.js
Created October 29, 2023 23:57
Set Name and Clone date in ServiceNow Banner
// Create an SVG string
var currentDate = new GlideDate();
var instanceName = gs.getProperty('instance_name');
var svgContent = '<svg width="550" height="100" xmlns="http://www.w3.org/2000/svg">' +
'<text x="20" y="50" style="font-family: Arial; font-weight: bold; font-size: 60; fill: #ffffff;">' + instanceName + '</text>' +
'<text x="20" y="90" style="font-family: Arial; font-size: 40; fill: #ffffff;">Cloned ' + currentDate + '</text>' +
'</svg>';
// Run functions to create an image and set it as the logo
var imageFileName = createImageRecord(svgContent);
@mtcoffee
mtcoffee / sntrivia.js
Last active November 20, 2023 00:44
ServiceNow Trivia Table Generator
//Instant Trivia Game with a simple background script.
//This script will create a Trivia table in your CMDB and load it with trivia questions from the Open Trivia Database, opentdb.com
var table_name = 'trivia',
extends_table = 'cmdb_ci',
fields = ['question', 'answer'];
createTable(table_name, extends_table, fields);
fetchAndInsertTriviaData(20);
@mtcoffee
mtcoffee / SNPowerShellTableAPIExport.ps1
Created November 30, 2023 15:11
LargeServiceNowExportwithPowerShell
<#
Since ServiceNow will only allow 10,000 records to be exported by default we need to use pagingation for large exports.
This script will query the table api for the selected table and loop through blocks of 10,000 until all records are retrived.
It then converts the JSON payload to a CSV
#>
# Set ServiceNow credentials
$username = "admin"
$password = "pass"
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
@mtcoffee
mtcoffee / gist:c535c32577d8e780014147d32340bf8e
Created December 2, 2023 13:01
vsphere terraform error
│ Error: Missing required argument
│ with vsphere_virtual_machine.vm,
│ on instance.tf line 95, in resource "vsphere_virtual_machine" "vm":
│ 95: windows_options {
│ "clone.0.customize.0.windows_options.0.domain_admin_password": all of
│ `clone.0.customize.0.windows_options.0.domain_admin_password,clone.0.customize.0.windows_options.join_domain`
│ must be specified
@mtcoffee
mtcoffee / main.tf
Created December 10, 2023 17:08
terraform_aws_windows_ec2_t2micro
provider "aws" {
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
region = "us-west-2"
}
resource "aws_instance" "ec2_instance" {
ami = "${var.ami_id}"
instance_type = "${var.instance_type}"
key_name = "${var.ami_key_pair_name}"
@mtcoffee
mtcoffee / variables.tf
Created December 10, 2023 17:14
terraform_aws_windows_ec2_t2micro_variables
variable "access_key" {
description = "Access key to AWS console"
}
variable "secret_key" {
description = "Secret key to AWS console"
}
variable "instance_name" {
description = "Name of the instance to be created"
@mtcoffee
mtcoffee / terraform.tfvars
Last active December 10, 2023 17:18
terraform_aws_windows_ec2_t2micro_tfvars
access_key = "SampleAccesKeyAKIA5HQPIDLAFRCZVQ88"
secret_key = "SamplePrivateKeylmy+asdfasdsdfaa3424g32gfasdfaS"
@mtcoffee
mtcoffee / findrecords.js
Last active December 20, 2023 21:13
Find all references to an existing record in ServiceNow
/*
Borrowing from https://servicenowguru.com/system-definition/find-references-specific-record/
This background script finds all references to an existing record, e.g., a company, or group
and exports them to a CSV saved in the sys_data_source table.
*/
var table = 'core_company';
var rec_sys_id = '0e8b8e650a0a0b3b004f285ffbb1a4fc';
var references = findReferencesToCoreRecord(table, rec_sys_id);
@mtcoffee
mtcoffee / CreateNginxOnK3s.sh
Last active February 10, 2024 00:23
nginx on K3s with traefik ingress
kubectl create -f - <<EOF
---
apiVersion: v1
kind: Namespace
metadata:
name: nginxweb
labels:
name: nginx
---
apiVersion: apps/v1
@mtcoffee
mtcoffee / CreatePortainerOnK3s.sh
Last active February 10, 2024 00:34
portainer on K3s with traefik ingress
kubectl create -f - <<EOF
---
kind: Namespace
apiVersion: v1
metadata:
name: portainer
labels:
name: portainer
---
apiVersion: apps/v1