Powershell: Bulk Creation of HP-BL Virtual Connect Profiles
####################################################################################################
#
# clone-profile.ps1
#
# Copy a template and associate with physical server
# INPUT: CSV file containing list of profile names, IP# of enclosure, and Bay
#
$vcuser = "admin"
$inputfile = ".\servers.csv"
$pw = Read-Host "Enter Password for $vcuser" -AsSecureString
$profiles = get-content $inputfile
$tempfile = ".\\cmdfile.txt"
$today = get-date
$day = $today.Day
$mth = $today.Month
$year = $today.Year
$hour = $today.Hour
$min = $today.Minute
$sec = $today.Second
$date = "$year-$mth-$day-$hour$min$sec"
$logfile = ".\create-profile-$date.log"
write "$date Create HP BL Profiles" | out-file $logfile -encoding ascii
clear-host
foreach ($profile in $profiles) {
"--------------------------------------------------------------------------------" | out-file $logfile -encoding ascii -append
$profile
$profile | out-file $logfile -encoding ascii -append
$server = ($profile -split',')
$name = $server[0]
$vcip = $server[1]
$bay = $server[2]
if ($vcip -eq "10.2.9.147") { $template = "Template01" }
if ($vcip -eq "10.2.9.177") { $template = "Template_2" }
#create command file
write "copy profile $template $name" | out-file $tempfile -encoding ascii
write "poweroff server $bay -force" | out-file $tempfile -encoding ascii -append
write "assign profile $name $bay" | out-file $tempfile -encoding ascii -append
#convert $pw to plain text
$pass = [Runtime.InteropServices.Marshal]::PtrToStringAuto(
[Runtime.InteropServices.Marshal]::SecureStringToBSTR($pw))
$result = (./plink.exe -batch -ssh -l $vcuser -pw $pass $vcip -m $tempfile) | out-string
$pass ='' #erase plain txt pw
$result
$result | out-file $logfile -encoding ascii -append
}#end foreach
"--------------------------------------------------------------------------------" | out-file $logfile -encoding ascii -append
No comments:
Post a Comment