Hello folks,
I’m currently working on a script to add new VM’s to PVS from Citrix.
and its all working well so far the only problem i got is the translation of the MACAdress in a value.
When i get the MACAddress back from VMware its separated with : so i need tot replace it with a -
but here come’s my problem.
when i read the value of my variable i get back “@{MacAddress=00-50-56-ac-37-8f}”
as fare i know its was possible to remove that so i only get “00-50-56-ac-37-8f” as content of the variable.
is there anyone who can tell me how to resolve this ?
The rest of the script is working without any problems.
The script that i’m using
#load necessary modules
Add-PSSnapin mcli*,vm*
#connect to VMWare and PVS server
Connect-VIServer -Server vm-management -Protocol https -User USERNAME
Mcli-Run SetupConnection -p server=vm-pvsp-1, Port=54321,user=USERNAME,domain=DOMAINNAME,password=PASSWORD!
#read CSV file to work with
$vdi_desktops = import-csv D:\temp\vdi_names_test.txt
foreach ($VDI in $vdi_desktops){
#split CSV file
$computername = $($VDI.computername)
$datastore = $($VDI.datastore)
$server = $($VDI.server)
#create VM by Template
New-vm -name $computername -Template VDI_Template -datastore $datastore -vmhost $server -Location desktops
#get MACAdres from created system and place in variable
$MACAdres = Get-NetworkAdapter -VM $computername | select-Object MacAddress
$MACAdres = $MACAdres -replace ':','-'
#Register VM in PVSP and add correct settings
Mcli-add device -R devicename=$computername, CollectionName='VDI Prod',DeviceMac=$MACAdres, SiteName='SITENAME',bootfrom=1,Type=0
Mcli-Run assigndisklocator -P deviceName=$computername, removeExisting=1,diskLocatorName=VDI-GoldenImage,siteName='SITENAME',storeName='SITE STORE'
Mcli-Run AddDeviceToDomain -P devicename=$computername, organizationUnit=Werkstations/VDI
}
Already thanks for the tips and advice