New-Item: Cannot find drive. A drive with the name '(Get-Item C' does not exist.

Topics: Feedback
Oct 24, 2013 at 8:14 AM
Edited Oct 24, 2013 at 8:15 AM
This error occurs due to the path in $env:TEMP not being properly formatted and passed down to the script.
PowerShell in Windows 2012

Script Line 50:
[String]$UpdateLocation = "(Get-Item $env:TEMP).FullName",
This line actually gives the following string as a result
$UpdateLocation = (Get-Item C:\Users\ADMINI~1\AppData\Local\Temp\2).FullName
As we can see the quotation marks prevent the proper execution of the script as it is not identifying the rest as commands. The whole thing is grayed in the graphical editor meaning its considered text. And as i remember commands don't get executed if they are in quotation marks only variables get resolved to their respective values.

The fix is simple:
[String]$UpdateLocation = "" + (Get-Item $env:TEMP).FullName + "",
As you can see we keep the quotation characters in the passing of the variable to allow for path name with spaces, but remove the quotes in their separate string component part to allow for the rest to be outside of the string enclosure.

This will fix your script if you encounter the problem
Nov 4, 2013 at 3:13 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.