none
Set default value for variables ERROR RRS feed

  • Question

  • Hello, below is the code and when I run it, I get an error which I don't know how to fix? Or understand why it is happening?

    function do-something {
    [CmdletBinding()]
    
    param(
    [Parameter(Mandatory=$true,ValueFromPipeLine=$true,Position=0)][String[]]$ServerName
    )
    [String]$Path = "C:\Temp\$Site"
    
    
        Invoke-Command -ComputerName $Server -ScriptBlock {
                
                New-Item -ItemType directory -path $Path
           
    
        }
    
    }
    
    
    

    But If I run the debugger to see what's happening then the variables do have preset values???



    Can someone please help me with this issue and also explain why of it.


    • Edited by strike3test Tuesday, October 30, 2018 6:46 PM
    Tuesday, October 30, 2018 8:44 AM

Answers

  • You are not passing the variable to the "invoke".

    See help for how to pass variables:

    help invoke-command -online


    \_(ツ)_/

    • Marked as answer by strike3test Tuesday, October 30, 2018 6:46 PM
    Tuesday, October 30, 2018 8:51 AM