PoshCode Archive  Artifact [10d31e2eac]

Artifact 10d31e2eac45c7bb173d4baeaf99a8474d115c9ea321efb06cb8989d829703cc:

  • File Scratchfolder-creation.ps1 — part of check-in [6fab58ad83] at 2018-06-10 14:10:23 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: 1485)

# 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: 6206
# x-archived: 2016-03-19T00:35:18
# 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
}