Skip to content

Instantly share code, notes, and snippets.

# Added from http://bretty.me.uk/save-money-using-citrix-octoblu-automation-for-power-management/
# Author: Dave Brett
function Lab-Shutdown {
$ErrorActionPreference = 'Continue'
import-module XenServerPSModule
connect-xenserver -url http://xs.bretty.local -username USERNAME -password PASSWORD
$file = "c:\Scripts\vmlist.txt"
$VMNames = Get-Content $file
foreach($VMName in $VMNames)
$vmListFilePath = "c:\Scripts\vmlist.txt"
. c:\scripts\Set-LabPowerState.ps1
if (Test-Path -Path "$vmListFilePath")
{
$setLabPower = @{
Credential = Import-Clixml -Path "c:\scripts\XenCred.xml"
XenServerUrl = "http://xs.bretty.local"
Shutdown = $true
}
function Set-LabPowerstate
{
<#
.Synopsis
Sets powermode for VMs on XenServer
.DESCRIPTION
This can shutdown or restart a VM or a collection of VMs. The function supports WhatIf. The XenServerPSModule
and vaild credentials on the XenServer is required to run this function. This function supports pipelineinput
for the VMname parameter.
$cred = Import-CliXml -Path c:\scripts\XenCred.xml
$cred = Get-Credential
Export-Clixml -Path c:\temp\XenCred.xml -Depth 3 -InputObject $cred
# Or as one line:
Get-Credential | Export-Clixml -Path c:\temp\XenCred.xml -Depth 3
function Test-String
{
param(
[parameter(Valuefrompipeline)]
[string]$InputObject
)
Begin
{}
$Source = @”
using System;
namespace ArrayTest
{
public static class ArrayStuff
{
public static sample ForEach(System.Array _items, int[] Id)
{
foreach (sample item in _items)
foreach($count in (0..10))
{
$id1 = $CollectionOfIDs | Get-Random
$id2 = $CollectionOfIDs | Get-Random
[gc]::Collect()
$measureHash += Measure-Command -Expression {
$csvHash[$id1,$id2]
}
}
$csvHash = @{}
foreach($obj in $csvObjects)
{
$csvHash[$obj.id] = $obj
}
$measureWhere = @()
foreach ($count in (0..10))
{
$id1 = $CollectionOfIDs | Get-Random
$id2 = $CollectionOfIDs | Get-Random
[gc]::Collect()
$measureWhere += Measure-Command -Expression {
$csvObjects.Where({$_.id -eq $id1 -or $_.id -eq $id2})
}
}