Dot-source in ISE versus PS window RRS feed

  • Question

  • I am having a strange problem, and I need help figuring out what might be causing it.

    I downloaded a function.  I ensured it was unblocked so I could run it without warnings.  I load it into ISE and click the execute script icon.  In ISE's command line window I can now see and use the function. (get-command <functionname>)

    I open a PowerShell command line window, not part of ISE.  I dot-source execute the script.  The function is not recognized in the PowerShell window.  I have tried with both elevated and non-elevated windows.  Tried on two different systems and get the same results.  From one of the windows I manually key in a simple function definition.  It is available.

    Appreciate any hints on why it seems to work fine from ISE but not from a PowerShell window.  Can't find anything in the script that seems to be testing for ISE presence.

    . : | : . : | : . tim

    Friday, August 21, 2015 8:15 PM


  • Yes, that is what I did.


    You need another dot.

    . .\Convert-WindowsImage.ps1


    Friday, August 21, 2015 10:05 PM

All replies

  • Post steps to reproduce and commands that illustrate it isn't working.

    -- Bill Stewart [Bill_Stewart]

    Friday, August 21, 2015 8:18 PM
  • Load function script into ISE.

    F5 to execute.

    Go to ISE command window and execute get-command <function-name>; Function is listed.  enter function name and it executes.

    Move to a PowerShell window.

    dot-source execute function script.

    get-command <function-name> does not show function.

    <function-name> returns error 'The term 'function-name' is not recognized as the name of a cmdlet, function, script file, or operable program.

    . : | : . : | : . tim

    Friday, August 21, 2015 8:23 PM
  • Just tried it on a third system - same result.  Windows 8.1 and Server 2012 R2.

    It is a function that has been downloaded from the gallery over 65,000 times (Convert-WindowsImage), so I don't think it would be a problem in the download itself.  I am guessing it is something in my environments, that's why I'm looking for hints on what I might try.

    . : | : . : | : . tim

    Friday, August 21, 2015 8:41 PM
  • In CLI you must dot source the file.


    Friday, August 21, 2015 9:11 PM
  • Yes, that is what I did.


    PS C:\users\tcerling\documents\scripts> convert-windowsimage
    convert-windowsimage : The term 'convert-windowsimage' is not recognized as the name of a cmdlet, function, script
    file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
    and try again.
    At line:1 char:1
    + convert-windowsimage
    + ~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (convert-windowsimage:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
    Suggestion [3,General]: The command convert-windowsimage was not found, but does exist in the current location. Windows
    PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\conv
    ert-windowsimage". See "get-help about_Command_Precedence" for more details.
    And trying the suggestion of dot sourcing the command doesn't do anything either.

    . : | : . : | : . tim

    Friday, August 21, 2015 9:39 PM
  • Yes, that is what I did.


    You need another dot.

    . .\Convert-WindowsImage.ps1


    Friday, August 21, 2015 10:05 PM
  • Thank you!  I figured it had to be something I was doing.  I was unaware of the dot-space-dot requirement.  I took the instructions to dot-source it literally.  I guess it is really dot-space-dot-source.

    . : | : . : | : . tim

    Friday, August 21, 2015 10:26 PM
  • FYI - .\ does not refer to dot sourcing.  .\ refers to current folder.  Try it:

    dir .

    .. refers to the parent of the current folder.

    dir ..

    dot sourcing means to xecute in current scope

    . c:\scripts\

    You can also use import-module to get the same effect.


    Friday, August 21, 2015 11:05 PM

  • In the example given by Mike the first dot (counting left to right) is the
    dot-sourcing dot. 

    The second dot is just a part of a file path that means "current directory".

    If you need to see more separation, you can code several spaces between the dots:

    .    .\Convert-WindowsImage.ps1

    • Edited by LarryWeiss Tuesday, August 25, 2015 3:28 AM
    Tuesday, August 25, 2015 3:26 AM
  • I think you are all a bit dotty.


    Tuesday, August 25, 2015 3:46 AM