title: User Input into Variable Containing Special Characters and Wild Cards not passing into Powershell Command
body: <p>I have been stuck on this problem for awhile now and cannot seem to find a solution that works. I have a situation where I cannot get a variable, created from user input for multiple file extensions, to work inside of a command in Power Shell. In the script below, if I manually enter the arguments for the file extensions using wild cards, and enclose each one in quotes separated by a comma, it works, but if I try to substitute the $Extensions variable created from the read-host function by typing the exact same string, it does not work. Two code examples below: The first one works, but the second one does not.</p>
  
  <pre><code>#This works
  $AllVariables = Get-Variable
  function CompareVariables {
  Compare-Object (Get-Variable) $AllVariables -Property Name -PassThru | Where -Property Name -ne "AllVariables"
  }
  
  #write-host 'Enter Extensions'
  #$Script:getsomeinput = read-host
  
  $Script:File_Path = "E:\Play Station1 Roms\_1 New Downloads"
  #$Script:Extensions = "$getsomeinput"
  $Script:Output_Path = "R:\"
  $Script:Output_File = "List.txt"
  
  $Script:numfilescount = (Get-ChildItem -path "$File_Path" -recurs -include "*.bin", "*.pbp").count
  $Script:ListFiles = Get-ChildItem -path "$File_Path" -recurse -include "*.bin", "*.pbp" | format-list | Out-File -Append -FilePath $Output_Path$Output_File
  
  CompareVariables
  ""
  '{0}{1}' -f $Output_Path,$Output_File
  write-host "$Output_Path$Output_File"
  ""
  read-host
  #*******************************************************************************************
  
  
  #This Does Not work when "*.bin", "*.pbp" is typed as input into the variable from the console.
  $AllVariables = Get-Variable
  function CompareVariables {
  Compare-Object (Get-Variable) $AllVariables -Property Name -PassThru | Where -Property Name -ne "AllVariables"
  }
  
  write-host 'Enter Extensions'
  $Script:getsomeinput = read-host
  
  $Script:File_Path = "E:\Play Station1 Roms\_1 New Downloads"
  $Script:Extensions = "$getsomeinput"
  $Script:Output_Path = "R:\"
  $Script:Output_File = "List.txt"
  
  $Script:numfilescount = (Get-ChildItem -path "$File_Path" -recurs -include "$Extensions").count
  $Script:ListFiles = Get-ChildItem -path "$File_Path" -recurse -include "$Extensions" | format-list | Out-File -Append -FilePath $Output_Path$Output_File
  
  CompareVariables
  ""
  '{0}{1}' -f $Output_Path,$Output_File
  write-host "$Output_Path$Output_File"
  ""
  read-host
  </code></pre>
  
  <p>I have tried a variety of things. I have tried splitting strings. I have tried putting the input from the variable into an array. I have tried string formatting, single quotes, double quotes... everything I could find online to output the data from the input into a format that the variable would pass to the command correctly and to no avail. I declared all of the variables in the script as script to avoid scope issues while trouble shooting, and I the added the compare variables functions so I could see the output and form of all of the variables created during the test. </p>
  
  <p>I was able to get the $Extensions variable to show the correct format, with wild cards and all, several times using several methods, but I could never get that input to work in the command even though the output inside the variable appears to be correct. Please help, as I am a novice. This is the last obstacle in my way stopping me from finishing my script.</p>