Note that there are some explanatory texts on larger screens.

plurals
  1. POPowershell Get-WebVirtualDirectory : Specified cast is not valid
    primarykey
    data
    text
    <p>I've narrowed my code down to this-</p> <pre><code>Function Check-VirtualPhysicalPath{ Param([Parameter(Mandatory=$True)] [AllowEmptyString()][String]$Page) #This creates an arraylist of items that are our virtual/physical paths $WebVD= Get-WebVirtualDirectory } </code></pre> <p>when I run this script in a function setting the results of 'Get-WebVirtualDirectory' returns a casting error. This has me baffled because when i try to run the line </p> <pre><code> $WebVD= Get-WebVirtualDirectory </code></pre> <p>in either a script or merely on the console there are no errors returned and i can access the variable and the data is correct. What am I doing wrong?</p> <p>Now as a side-note this is merely the problematic code so i'm not including everything, but even when i comment everything else out i end up just running what you see here with problems just the same. </p> <p>i'm calling the code with this in a separate script</p> <pre><code>$page = [string]$(gc "C:\page.txt") . C:\VP.ps1 $(Check-VirtualPhysicalPath($page)) </code></pre> <p>Powershell is reacting like i'm casting the $WebVD variable, I'm not sure if this is a bug or if i'm missing something entirely...</p> <p><b>Edit:</b></p> <p>it looks like i forgot to pull out that part of the code. I'm code crawling, the point of the hashtable is that i'm storing the number of times a resource is used in a hash table with the key being the file name and the value how many times it has been used so i use regular expressions to determine that. My question is unrelated to my other code because it's having problems even when my code only contains what you see above.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload