Home > database >  Remove @{} from output and place in command
Remove @{} from output and place in command

Time:10-13

I am trying to figure out how to remove the @{} from the output of the $list coming from the CSV file.

I am trying to run the Command "Complete-DomainJoin -Identity $line -DagNumber 023" for each line inside the CSV file

#Complete-DomainJoin (MultipleObjects)

$csv = Import-Csv C:\Temp\DEPTComputers023DEPTComputers023.csv
foreach ($line in $csv) {
    Complete-DomainJoin -Identity $line -DagNumber 023 
} 

When I run this powershell script it errors out because its placing the line item from the CSV into the command as @{xxxx}, from reading around it seems the common way to fix the issue is by adding -ExpandProperty variable but I have not found where to place it or I am not understanding how to implement it correctly.

CodePudding user response:

If everything is in the first column with no header row, then you can try this:

# Name the first column
$csv = Import-Csv C:\Temp\DEPTComputers023DEPTComputers023.csv -Header 'ComputerName'
foreach ($row in $csv) {
    # use the ComputerName property
    Complete-DomainJoin -Identity $row.ComputerName -DagNumber 023 
} 

If there aren't any commas in the file at all, then just replace Import-Csv with Get-Content

the @{property=value} syntax means that your object has sub-properties, instead of being a single string

  • Related