Learning and Sharing
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
No Result
View All Result

Import-Csv Cannot Find Drive, A Drive with the Name ‘”C’ Does not Exist

September 10, 2023
in Blog, Powershell
0
ADVERTISEMENT

Table of Contents

Drive with the Name ‘”C’ Does not Exist

When starting write a PowerShell script. We want to prompt to enter a user list (.csv) using the Read-Host cmdlet. We add the file path by right clicking the file and choose copy as path and pasting into the below command. Looks like this: “C:\users.csv”. 

This makes life easier as we can drag, drop or copy/paste rather than full typing the path.

PS C:\> $users = Read-Host "What is the file path of the csv file"
What is the file path of the csv file: "C:\users.csv"

PS C:\> Import-Csv -Path $users

Then we import using Import-Csv cmdlet. However, when we do that, it is saying below error:

Import-Csv : Cannot find drive. A drive with the name ‘”C’ does not exist.
At line:1 char:1
+ Import-Csv -Path $users
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (“C:String) [Import-Csv], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.ImportCsvCommand

The problem is that PowerShell keeps throwing errors, saying it can’t find the drive “X:. This seems to be being caused by the quotes around the path. PowerShell treating the quote as part of the path rather than just a quote.

PS C:\> $users
"C:\users.csv"

If we add the path without quotes, it will work just fine. Here is how it is captured:

PS C:\> $users = Read-Host "What is the file path of the csv file"
What is the file path of the csv file: C:\users.csv
PS C:\> Import-Csv -Path $users

OldUPN                                  NewUPN
------                                  ------
[email protected]    [email protected]
[email protected]    [email protected]
[email protected] [email protected]
[email protected]   [email protected]

Read-Host treats the variable type a string, so you are adding the quotes as part of your entry to Read-Host will lead the issue. To fix it, you can replace the quotations in your path so that Import-Csv sees it without quotes. See below example .

$users = Read-Host "What is the file path of the csv file"
$users = $users.trim('"')
Import-Csv -Path $users.trim('"')
PS C:\> $users = Read-Host "What is the file path of the csv file"
What is the file path of the csv file: "C:\users.csv"

PS C:\> $users = $users.trim('"')

PS C:\> $users
C:\users.csv

PS C:\> Import-Csv -Path $users

OldUPN                                  NewUPN
------                                  ------
[email protected]    [email protected]
[email protected]    [email protected]
[email protected] [email protected]
[email protected]   [email protected]

# Shorten your script
# Import-Csv -Path $users.trim('"')

Alternatively, you can use the below method to remove the double quotes from the user’s input strings.

$users = Read-Host "What is the file path of the csv file"
$users = $users.Replace('"', '')
Import-Csv -Path $users
PS C:\> $users = Read-Host "What is the file path of the csv file"
What is the file path of the csv file: "C:\users.csv"
PS C:\> $users = $users.Replace('"', '')
PS C:\> Import-Csv -Path $users

OldUPN                                  NewUPN
------                                  ------
[email protected]    [email protected]
[email protected]    [email protected]
[email protected] [email protected]
[email protected]   [email protected]

Conclusion

When running a PowerShell script requires user input:

  • Educate users enter input without the double quotes.
  • Or you can edit your codes to remove the doube quotes, then you don’t need to care about user imput with or without double quotes.

Not a reader? Watch this related video tutorial:

Rate this post
Previous Post

How to Remove the Message Press any key to boot from CD or DVD

Next Post

Mount-DiskImage The Filename, Directory Name, or Volume Label Syntax is Incorrect

Related Posts

Running Hyper-V and VMware Workstation on The Same Machine

August 15, 2024

How to Uninstall All Autodesk Products At Once Silently

July 29, 2024
Ftr5

How to Uninstall the Autodesk Genuine Service on Windows

July 29, 2024
Ftr19

How to Fix Windows Cannot Read the ProductKey From the Unattend Answer File in VirtualBox

July 26, 2024
Ftr25

How to Update Windows Terminal in Windows 10/11

July 26, 2024

How to Disable The Beep Sound in WSL Terminal on Windows

July 26, 2024

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How To Turn On uBlock Origin Extension in Chrome (2025)
  • Images Hidden Due To Mature Content Settings In CivitAI
  • Azure OpenAI vs Azure AI Hub, How to Choose the Right One for Your Needs

Categories

Stay in Touch

Discord Server

Join the Discord server with the site members for all questions and discussions.

Telegram Community

Jump in Telegram server. Ask questions and discuss everything with the site members.

Youtube Channel

Watch more videos, learning and sharing with Leo ❤❤❤. Sharing to be better.

Newsletter

Join the movement and receive our weekly Tech related newsletter. It’s Free.

General

Microsoft Windows

Microsoft Office

VMware

VirtualBox

Technology

PowerShell

Microsoft 365

Microsoft Teams

Email Servers

Copyright 2025 © All rights Reserved. Design by Leo with ❤

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory