Last active
October 23, 2019 19:11
-
-
Save chris1984/7b8c1c49e737d646c6df2b963ae07fae to your computer and use it in GitHub Desktop.
Test datastore permissions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Create a folder on a datastore | |
.DESCRIPTION | |
Script used to test folder creation on a datastore with a user account. This will test permissions as well as provide debug output | |
for foreman_bootdisk debugging | |
Replace Line# 19 with your vCenter URL and username/password you are going to authenticate with | |
Replace Line# 21 Datastore1 with the datastore you are wanting to test against | |
Replace Line# 20/21 with username in Windows found in C:/Users/ | |
.NOTES | |
File Name : folder-create.ps1 | |
Author : Chris Roberts [email protected] | |
Prerequisite : PowerShell V2 | |
.LINK | |
Script posted at: | |
http://github.com/chris1984/vmware-scripts | |
#> | |
# Create log file of operations and store in variable | |
New-Item -Path C:/Users/<user> -Name "script_results.txt" -ItemType "file" -Value "Output of script" | |
$ScriptLog = 'C:/Users/<user>/script_results.txt | |
# Connect to the VMware vCenter | |
Connect-VIServer -Server <vcenterfqdn> -User <adminuser> -Password <adminpassword> | |
# Store datastore as variable so we can use it for folder creation | |
$DataStore = Get-Datastore -Name Datastore1 | Out-File $ScriptLog -Append | |
# Set datastore as a PowerShell drive so we do not have to mess with Linux/Windows local file creation | |
New-PSDrive -Location $datastore -Name DS -PSProvider VimDatastore -Root "\" | |
# Create the directory on the datastore | |
New-Item -Path DS:\foreman_isos\test -ItemType Directory | Out-File $ScriptLog -Append | |
# Let user know directory was created | |
Write-Host "Directory powershell_directory has been created on datastore $DataStore" | Out-File $ScriptLog -Append | |
# Remove PowerShell drive | |
Remove-PSDrive -Name DS -Confirm:$false | |
# Let user know script is finished | |
Write-Host "Script finished, please verify in vCenter that the directory is present" | Out-File $ScriptLog -Append |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment