I'm using a script that imports values from a CSV file to implement our Sites and Services design. Whilst doing this for one of our sites, I'm running into trouble. The code at fault follows:
new-ADReplicationSiteLink-Name"Datacentre to $Site.description"-cost$Site.costtodatacentre -SitesIncluded"$Site.name","DataCentre"-ReplicationFrequencyInMinutes15
I get an error (sorry I can't copy it directly, it's in an isolated environment) which roughly says:
Identity info provided in the extended attribute: 'SitesIncluded' could not be resolved. Reason: 'Cannot find an object with identity: @{Name=Site01;Description=That site;cost=216}
The problem is that within the double quote marks ("), the dot after $Site is no longer considered part of the variable - it's considered text. So the entire $Site object is passed into the name and sitesincluded parameters, instead of the property I want to select.
I could work around this by using code like this:
$SiteDescription=$Site.description
$SiteName
=$Site.name
new-ADReplicationSiteLink
-Name"Datacentre to $SiteDescription"-cost$Site.costtodatacentre -SitesIncluded"$SiteName","DataCentre"-ReplicationFrequencyInMinutes15
But it seems so wasteful! It's not really extensible code and if I have to do it for more than a couple of attributes I'll get very wound up!
How can I reference a specific property of an object within quotation marks, or is there an efficient alternative?