Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Borrowed from http://www.vhersey.com/2013/12/enable-software-iscsi-and-add-sendtargets-with-powercli/
- #FQDNs or IP addresses of ESXi Hosts to Configure
- #Enclose each host in quotes and separate with a comma.
- #Example: $ESXiHosts = "192.168.1.1","192.168.1.2"
- $ESXiHosts = "esx0", "esx3", "esx4", "esx5", "esx6", "esx7", "esx8", "esx10"
- # Prompt for ESXi Root Credentials
- # $esxcred = Get-Credential
- # Connect to each host defined in $ESXiHosts
- # Connect-viserver -Server $ESXiHosts -Credential $ESXiCreds
- # Set $targets to the SendTargets you want to add. Enclose each target in quotes and separate with a comma.
- # Example: $targets = "192.168.151.10", "192.168.151.11", "192.168.151.12", "192.168.151.13"
- $targets = "belomor"
- foreach ($esx in $ESXiHosts) {
- # Enable Software iSCSI Adapter on each host
- Write-Host "Enabling Software iSCSI Adapter on $esx ..."
- Get-VMHostStorage -VMHost $esx | Set-VMHostStorage -SoftwareIScsiEnabled $True
- # Just a sleep to wait for the adapter to load
- $slpsec = 19
- Write-Host "Sleeping for $slpsec Seconds..." -ForegroundColor Green
- Start-Sleep -Seconds $slpsec
- Write-Host "OK Here we go..." -ForegroundColor Green
- Write-Host "Adding iSCSI SendTargets..." -ForegroundColor Green
- $hba = get-vmhost $esx | Get-VMHostHba -Type iScsi | Where {$_.Model -eq "iSCSI Software Adapter"}
- foreach ($target in $targets) {
- # Check to see if the SendTarget exist, if not add it
- if (Get-IScsiHbaTarget -IScsiHba $hba -Type Send | Where {$_.Address -cmatch $target}) {
- Write-Host "The target $target does exist on $esx" -ForegroundColor Green
- }
- else {
- Write-Host "The target $target doesn't exist on $esx" -ForegroundColor Red
- Write-Host "Creating $target on $esx ..." -ForegroundColor Yellow
- New-IScsiHbaTarget -IScsiHba $hba -Address $target
- }
- }
- }
- # Write "`n All Done."
- Write "`n Done - Disconnecting from $ESXiHosts"
- Disconnect-VIServer -Server * -Force -Confirm:$false
- Write-Host "Done! Now go manually add the iSCSI vmk bindings to the Software iSCSI Adapter and Rescan." -ForegroundColor Green
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement