Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / updateDescription.js
Created September 21, 2023 18:28
Script to Build a Modal from a ServiceNow UI Action
function showModal() {
// get current values from description
var currentOutageDetails = g_form.getValue('description');
var securityStatus = getCurrentValueSingle(currentOutageDetails, 'Potential Security Issue:');
var businessStatus = getCurrentValueSingle(currentOutageDetails, 'Business Operation Affected:');
var symptomStatus = getCurrentValueSingle(currentOutageDetails, 'Reported Symptoms:');
var descStatus = getCurrentValueMulti(currentOutageDetails, 'General Description:');
var gm = new GlideModal('Set Description');
gm.setTitle('Set Description');
@mtcoffee
mtcoffee / ServiceNowMIDServerTest.js
Created August 28, 2023 17:16
ServiceNow MID Server Test
/*
A background script to run a command and test MID Server connectivity to an endpoint.
Just set the value to your midserver name.
*/
//capture start time
var now = (new GlideDateTime());
var probe = SncProbe.get("Windows - Powershell");
var midServer = 'winmid06';
var psCommand = 'test-netconnection -port 443 192.168.1.1';
@mtcoffee
mtcoffee / GlideModalFormUIAction.js
Created August 28, 2023 15:18
GlideModalFormUIAction
//for use with ServiceNow UI Action client script to create a new Incident from a CI
function loadModal() {
var fieldquery = '';
var fields = [
'cmdb_ci=' + g_form.getUniqueValue(),
'caller_id=' + g_user.userID,
'contact_type=' + 'self-service',
'short_description=' + 'Incident for ' + g_form.getValue('name'),
];
fields.forEach(function(field) {
@mtcoffee
mtcoffee / CreateSeleniumServiceNowIncidentViaPortal.py
Created August 27, 2023 22:12
CreateSeleniumServiceNowIncidentViaPortal
import sys
if len(sys.argv) < 4:
warning = """
Please provide 3 parameters in the format "instancename username password"
e.g. dev1234 itiluser itiluserpassword
"""
print(warning)
sys.exit()
sninstance = "https://" + sys.argv[1] + ".service-now.com"