PoshCode Archive  Artifact Content

Artifact b4ffdf7c42905f1bace83c51ad95b2f36ee8e79103271263e9274c38cd80c363:

  • File Scratchfolder-creation.ps1 — part of check-in [4c999c28b3] at 2018-06-10 14:10:24 on branch trunk — Script creates unique scratch folders on the provided datastore for all ESXi hosts in csv file and sets the advanced host settings to correspond to this location. (user: Kimberly Anne A size: 1512)

# encoding: ascii
# api: powershell
# title: Scratchfolder creation
# description: Script creates unique scratch folders on the provided datastore for all ESXi hosts in csv file and sets the advanced host settings to correspond to this location.
# version: 0.1
# type: script
# author: Kimberly Anne A
# license: CC0
# x-poshcode-id: 6207
# x-derived-from-id: 6237
# x-archived: 2016-05-17T01:02:47
# x-published: 2016-02-08T18:30:00
#
#
# Script to create scratch location directory per host
# By Leon Scheltema AVANCE ICT Groep Nederland

# Begin variables
$Datastore = ""
# End variables

#connect to all host from csv sequentially

Import-CSV file.csv | ForEach-Object {
$hostname = $_.vmhost

connect-viserver $hostname -user root -password ""

#Mount a datastore read/write as a PSDrive
New-PSDrive -Name "mounteddatastore" -Root \ -PSProvider VimDatastore -Datastore (Get-Datastore $Datastore)

#Access the new PSDrive
Set-Location mounteddatastore:

#Create a uniquely-named directory for this ESXi host
New-Item ".locker-$hostname" -ItemType directory

#Unmount a datastore read/write as a PSDrive
CD G:
Remove-PSDrive Mounteddatastore

#Change the Scratch location by specifying the full path to the directory created earlier
Set-VMHostAdvancedConfiguration -Name "ScratchConfig.ConfiguredScratchLocation" -Value "/vmfs/volumes/$Datastore/.locker-$hostname"

# Disconnect from vCenter server
Disconnect-VIServer -server $hostname -Force -Confirm:$false
}