Skip to content

Instantly share code, notes, and snippets.

@deangrant
deangrant / setResourceElementMimeType.js
Created Sep 14, 2018
setResourceElementMimeType.js
View setResourceElementMimeType.js
// Retrieves the resource element as a mime attachment from the specified input parameter (resourceElement).
var content = resourceElement.getContentAsMimeAttachment();
System.debug('The resource element ' + resourceElement.name + ' has been returned with the mime type ' + content.mimeType)
content.mimeType = mime;
// Sets the mime attachement to the type specifed from the input parameter (mime).
resourceElement.setContentFromMimeAttachment(content);
System.log('The resource element ' + resourceElement.name + ' mime type type has been set to ' + mime)]]
@deangrant
deangrant / setResourceElementMimeType.js
Last active Sep 13, 2017
com.deangrant.library.vro/setResourceElementMimeType
View setResourceElementMimeType.js
// Retrieves the resource element as a mime attachment from the specified input parameter (resourceElement).
var content = resourceElement.getContentAsMimeAttachment();
System.debug('The resource element ' + resourceElement.name + ' has been returned with the mime type ' + content.mimeType)
content.mimeType = mime;
// Sets the mime attachement to the type specifed from the input parameter (mime).
resourceElement.setContentFromMimeAttachment(content);
System.log('The resource element ' + resourceElement.name + ' mime type type has been set to ' + mime)
@deangrant
deangrant / getRestHostByName.js
Last active Aug 16, 2017
com.deangrant.http-rest/getRestHostByName
View getRestHostByName.js
// Returns a collection of REST:RESTHost object types from the inventory service plugin
var getHosts = RESTHostManager.getHosts()
// Iterates the collection to return the REST:RESTHost object type and perform a match on the name attribute provided as an input parameter and returns the REST:RESTHost type if true.
for(var restHostId in getHosts){
var restHost = RESTHostManager.getHost(getHosts[restHostId])
if(restHost.name == name){
return restHost
} // if(restHost.name == name)
} // var restHost = RESTHostManager.getHost(getHosts[restHostId])
@deangrant
deangrant / Regular Expression Cheat Sheet
Last active Jul 22, 2016
Regular Expression Cheat Sheet
View Regular Expression Cheat Sheet
# Validate Base64 string.
[0-9a-zA-Z\+=]{20,}
# Validate Subnet in CIDR notation.
^(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5])\/(\d{1}|[0-2]{1}\d{1}|3[0-2])$
# Validate IP address range.
^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})){3}-(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})){3}$
# Validate IP address.
View Get-Uptime.ps1
Function Get-Uptime {
<#
.SYNOPSIS
Gets the uptime for a local or remote computer.
.DESCRIPTION
The Get-Uptime function gets the uptime for specified computers by retrieving the LastBootUpTime from Win32_OperatingSystem WMI class. The uptime period is calculated in days by comparing the interval between the LastBootUpTime and the current date and time.
The function sends an Internet Control Message Protocol (ICMP) echo request packet to determine if a the specified computer may be contacted. If the computer is offline this will report a status of 'Offline. If an echo reponse is received, the uptime status will
View Send-ToSlack_POSTmessage
# Generates POST message to be sent to the slack channel.
$PostMessage = @{token="$Token";channel="$Channel";text="$Text";username="$Bot";icon_url="$Icon"}
View Send-ToSlack_Process
Process
{
Try
{
# Sends HTTPS request to the Slack Web API service.
$WebRequest = Invoke-WebRequest -Uri $Uri -Body $PostMessage
# Conditional logic to generate custom error message if JSON object response contains a top-level error property.
If ($WebRequest.Content -like '*"ok":false*')
{
# Terminates with error if the response contains an error property, parses the error code and stops processing of the command.
View Scripting_Games_December_2015.ps1
# http://powershell.org/wp/2015/12/05/december-2015-scripting-games-puzzle/
$List = @"
1 Partridge in a pear tree
2 Turtle Doves
3 French Hens
4 Calling Birds
5 Golden Rings
6 Geese a laying
7 Swans a swimming
View Get-VulnerabilityRSSFeed_InvokeWebRequest
Try
{
# Conditional logic to determine if the switch to retrieve information from the Microsoft Security Bulletin RSS feed has been specified.
If ($Microsoft)
{
# Retrieves content from the Microsoft Security Bulletin RSS feed.
[xml]$WebRequest = Invoke-WebRequest -Uri https://technet.microsoft.com/en-us/security/rss/bulletin
# Selects objects retrieved where the published date is greater or equal to the timespan speficied.
$Items = $WebRequest.rss.channel.item | Where-Object {$_.pubDate -ge "$Date"}
# Performs action on each item returned to calculate expressions for output object.
View Get-VulnerabilityRSSFeed_CmdletBindling
[CmdletBinding()]
Param (
[String] $Days = "1",
[Switch] $Microsoft,
[Switch] $NVD,
[String] $Keywords = "Ubuntu|Tomcat|MySQL"
)