Skip to content

Instantly share code, notes, and snippets.

Avatar

Alain Assaf alainassaf

View GitHub Profile
@alainassaf
alainassaf / My VSCode User Snippets for PowerShell
Created Jan 28, 2022
My VSCode USer snippets for PowerShell
View My VSCode User Snippets for PowerShell
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
View stop-idleProcess.ps1
<#
.SYNOPSIS
Searches Citrix sessions that are running a certain published application and stops it if a session is idle for a certain time.
.DESCRIPTION
Searches Citrix sessions that are running a certain published application and stops it if a session is idle for a certain time. Logs are generated in the same directory as the script runs.
.PARAMETER deliverycontroller
Mandatory string parameter. Which Citrix Delivery Controller (farm) to query for session.
.PARAMETER pubApp
Mandatory string parameter. Which published application to stop.
.PARAMETER idletime
@alainassaf
alainassaf / open-WemConsole.ps1
Last active Feb 5, 2021
Script to open the Citrix WEM Console
View open-WemConsole.ps1
<#
.SYNOPSIS
Opens WEM Mgmt Console connected to entered WEM Infrastrucure Server
.DESCRIPTION
Opens WEM Mgmt Console connected to entered WEM Infrastrucure Server
.PARAMETER WEMServer
Optional string parameter. The WEM Infrastrucure server the WEM Console will connect to.
.EXAMPLE
PS> open-WemConsole.ps1
Opens the WEM Console connected to the last WEM infrastrcuture server.
@alainassaf
alainassaf / get-pixabayImage.ps1
Created Apr 20, 2020
Function to query and download a Pixabay Image
View get-pixabayImage.ps1
function get-pixabayImage {
[CmdletBinding()]
param (
[parameter(Position = 0, Mandatory = $True )]
[ValidateNotNullOrEmpty()]
[string]$query,
[Parameter(Mandatory = $true)]
[ValidateSet("backgrounds", "fashion", "nature", "science", "education", "feelings", "health", "people", "religion", "places", "animals", "industry", "computer", "food", "sports", "transportation", "travel", "buildings", "business", "music")]
$category,
@alainassaf
alainassaf / deleteVM.ps1
Created Dec 7, 2018
Code to delete XenServer VM and its disks
View deleteVM.ps1
$vmtodelete = Get-XenVM | Where-Object {$_.is_a_snapshot -eq $false -and $_.is_a_template -eq $false -and $_.is_control_domain -eq $false -and $_.name_label -eq $virtualMachine}
if ($vmtodelete) {
if ($vmtodelete.power_state -eq "Halted") {
Write-Verbose "$virtualmachine is powered off. Deleting $virtualmachine from $xsn"
$vmtodelete.VBDs | Remove-XenVBD #Deletes attached disks
$vmtodelete | Remove-XenVM #Deletes VM
Get-XenSession -Server $_ | Disconnect-XenServer
Exit 0
} else {
Write-Warning "$virtualmachine is not powered off. Exiting script"
@alainassaf
alainassaf / get-xsvmcount.ps1
Last active Jul 27, 2018
Getting, counting, saving
View get-xsvmcount.ps1
# Retrieve the information
$XenServerVMs = Get-XenVM | Where-Object {$_.is_a_snapshot -eq $false -and $_.is_a_template -eq $false -and $_.is_control_domain -eq $false -and $_.power_state -eq 'running'} | Select-Object name_label
$vmCount = $XenServerVMs.count
$objctxsrv = new-object System.Object
$objctxsrv | Add-Member -type NoteProperty -name XenServer -value $xsn
$objctxsrv | Add-Member -type NoteProperty -name 'VM Count' -value ($vmCount)
$finalout += $objctxsrv
# Disconnect from the XenServer pool
Get-XenSession -Server $_ | Disconnect-XenServer
@alainassaf
alainassaf / get-xsvmcount.ps1
Created Jul 27, 2018
Switch to change to name
View get-xsvmcount.ps1
switch ($_) {
"192.168.50.1" {$xsn = "XenServerPool1"; break}
"192.168.50.2" {$xsn = "XenServerPool2"; break}
default {"UNKNOWN XENSERVER"; break}
}
@alainassaf
alainassaf / get-xsvmcount.ps1
Last active Jul 27, 2018
Looping through XS Poolmasters
View get-xsvmcount.ps1
# Loop through list of hosts (poolmaster)
$xenserver_poolmaster | ForEach-Object {
# Connect to XenServer pool
Connect-XenServer -Server $_ -Creds $xenserver_credential -SetDefaultSession -NoWarnNewCertificates
@alainassaf
alainassaf / showflow.ps1
Last active Mar 6, 2018
showflow example
View showflow.ps1
# *** START: ShowFlow *********************************************************
if ($ShowFlow) {
# Install GraphViz from the Chocolatey repo
#Register-PackageSource -Name Chocolatey -ProviderName Chocolatey -Location http://chocolatey.org/api/v2/
Find-Package graphviz | Install-Package -ForceBootstrap
# Install PSGraph from the Powershell Gallery
Find-Module PSGraph | Install-Module
# Import Module PSGraph