get rit of @{text

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

I haven’t tested your code, but it looks like all you probably need to do is use the -ExpandProperty parameter in Select-Object. Try changing:

# This:
$MACAdres = Get-NetworkAdapter -VM $computername | select-Object MacAddress

# to this:
$MACAdres = Get-NetworkAdapter -VM $computername | Select-Object -ExpandProperty MacAddress

I threw this example together that seems to display the information in the format you want…

$StrComp = (gwmi Win32_NetworkAdapterConfiguration -Comp computername | select *)
$MACad =  ($StrComp.MacAddress -replace ':','-')

As a note, the text doesn’t actually “include” the @{}. Those characters are how PowerShell displays an array of information - because a NIC can have more than one physical address. As Dave noted, using -ExpandProperty will ‘expand’ the array into individual items you can get to.

thanks Dave and Don,

i was thinking that i have to do something with the variable and was not attending to the options in select-object.
now i can finally get starting to deploy all the VDI desktop’s automatically