# Double quotes  added therefore cannot ping pcnames in $pclist file

**URL:** <https://forums.powershell.org/t/double-quotes-added-therefore-cannot-ping-pcnames-in-pclist-file/5930>\
**Category:** PowerShell Help\
**Created:** [March 6, 2016, 8:37am UTC](https://forums.powershell.org/t/double-quotes-added-therefore-cannot-ping-pcnames-in-pclist-file/5930 "2016-03-06T08:37:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![darrendu-du](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@darrendu-du](https://forums.powershell.org/u/darrendu-du)\
**Post date:** [March 6, 2016, 8:37am UTC](https://forums.powershell.org/t/double-quotes-added-therefore-cannot-ping-pcnames-in-pclist-file/5930/1 "2016-03-06T08:37:44Z")

</div>

hi,  
For some reason I cannot search for each names in my $pclist file . Found out export-csv adds double quotes “” to pc names in each row in the pclist file therefore cannot ping PC names which is expected and only way I found around this issue is use the -replace “” removes double quotes . But have another issue cannot use my $pclist in a variable , see # I commented it out below … Also the fist row it add “names” which I cannot figure out how to remove from pclist file . I just need the actual pc names in the pclist file.. hope this is not all to confusing what I need ..🙂

$DayofWeek = Get-Date -Format ddd  
$4m = (Get-Date).AddDays(-120)

# Specify the varibles where the accounts are located

$OUdn = “OU= Computers,DC=domain,DC=com”  
$OUdisable = “ou=disabled accts,DC=domain,DC=com”  
$logdetail = “C:\complog.txt”  
$pclist = “C:\pcs.csv”  
$logpcsnotping = “C:$DayofWeek-pcsnotping.txt”  
Get-ADComputer -Property Name,lastLogonDate -Filter {lastLogonDate -lt $4m} -SearchBase $OUdn | select name | Export-csv $pclist -NoTypeInformation

${c:\pcs.csv} = ${c:\pcs.csv} -replace ‘"’  
#$pclist = $pclist -replace ‘"’

```
$names = Get-Content $pclist

```

foreach ($name in $names){  
if (Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue){  
# Write-Host “$name,up”  
Add-Content $logdetail “$name,up”  
}  
else{  
Add-Content $logpcsnotping “$name”  
}  
}

---

<div class="post-metadata">

**Author:** ![wilfredo-perez](https://avatars.discourse-cdn.com/v4/letter/w/e99b99/32.png) [@wilfredo-perez](https://forums.powershell.org/u/wilfredo-perez)\
**Post date:** [March 6, 2016, 12:34pm UTC](https://forums.powershell.org/t/double-quotes-added-therefore-cannot-ping-pcnames-in-pclist-file/5930/2 "2016-03-06T12:34:58Z")

</div>

You have to import-csv not get-content

---

<div class="post-metadata">

**Author:** ![darrendu-du](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@darrendu-du](https://forums.powershell.org/u/darrendu-du)\
**Post date:** [March 7, 2016, 2:44am UTC](https://forums.powershell.org/t/double-quotes-added-therefore-cannot-ping-pcnames-in-pclist-file/5930/3 "2016-03-07T02:44:25Z")

</div>

ok… I tried import-csv but am having a problem $pc variable when do GET-ADComputer … Get-ADComputer : Cannot bind parameter ‘Identity’. Cannot convert value “@{name=Desktop-60851}” to type  
“Microsoft.ActiveDirectory.Management.ADComputer”. Error: “Cannot convert the “@{name=Desktop-60851}” value of type  
“System.Management.Automation.PSCustomObject” to type “Microsoft.ActiveDirectory.Management.ADComputer”.”  
At line:11 char:30

- $ADComputer = Get-ADComputer $pc -Properties Description…

* * *

\>\>\>\>\>\>\>\>\>\>\>  
$pcs = import-csv “C:\pcsnotping.csv”  
ForEach ($pc in $pcs)

{ $ADComputer = $null  
$ADComputer = Get-ADComputer $pc -Properties Description

If ($ADComputer)

{ Add-Content $logdetail -Value “Found $pc , disabled and moved to Disabled Computers OU”

Set-ADComputer $ADComputer -Description “Computer Disabled on $(Get-Date)” -Enabled $false

Move-ADObject $ADcomputer -targetpath $OUdisable

}

Else

{ Add-Content $logdetail -Value “$pc not in Active Directory”

}

}

---

<div class="post-metadata">

**Author:** ![bobmccoy](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/bobmccoy/32/650_2.png) [@bobmccoy](https://forums.powershell.org/u/bobmccoy)\
**Post date:** [March 7, 2016, 3:52am UTC](https://forums.powershell.org/t/double-quotes-added-therefore-cannot-ping-pcnames-in-pclist-file/5930/4 "2016-03-07T03:52:14Z")

</div>

I am assuming Name is the column header, yes? In that case …

```
$ADComputer = Get-ADComputer $($pc.Name) -Properties Description
```

---

<div class="post-metadata">

**Author:** ![jeremy-murrah](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/jeremy-murrah/32/391_2.png) [@jeremy-murrah](https://forums.powershell.org/u/jeremy-murrah)\
**Post date:** [March 7, 2016, 3:55am UTC](https://forums.powershell.org/t/double-quotes-added-therefore-cannot-ping-pcnames-in-pclist-file/5930/5 "2016-03-07T03:55:41Z")

</div>

if you truly only want a single list of computer names, then try changing your output code from

```
select name | Export-csv $pclist -NoTypeInformation
```

to something like this

```
select -expandproperty Name | out-file $pclist
```

that will give you a text file with no headers or any other formatting data. You shouldn’t need to replace any quotes, and you’ll want to use get-content to pull them into a list.

---

<div class="post-metadata">

**Author:** ![darrendu-du](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@darrendu-du](https://forums.powershell.org/u/darrendu-du)\
**Post date:** [March 13, 2016, 8:20am UTC](https://forums.powershell.org/t/double-quotes-added-therefore-cannot-ping-pcnames-in-pclist-file/5930/6 "2016-03-13T08:20:51Z")

</div>

Fantastic! Thanks to all

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:42pm UTC](https://forums.powershell.org/t/double-quotes-added-therefore-cannot-ping-pcnames-in-pclist-file/5930/7 "2024-05-16T20:42:39Z")

</div>

Closed on May 16, 2024, 8:42pm UTC


