Can not see written function again if I start the new powershell window RRS feed

  • Question

  • Hello All, 

    I am learning powershell and wrote down the function to convert excel file to csv , Once I execute it , I can see created function name in the list  if I do dir function: , but if I close my power shell window and restart and execute the same command I can not see the newly created function again, How can I keep and make function available to others as well so I do not have to write codes again ?

    Thank you for your help !

    Thursday, November 15, 2018 9:16 PM


All replies

  • Functions do not get saved.  To make a function permanent either place it in you profile or create a module that contains the function.

    I recommend learning PowerShell first then all of these basic issues will be obvious.

    1. Microsoft Virtual Academy - Getting Started with Microsoft PowerShell
    2. PowerShell Documentation
    3. PowerShell Style Guidelines


    Thursday, November 15, 2018 9:39 PM
  • Thank you JRV , I followed the steps and tried but getting an error message, Saved function to .ps1 file and tried to recall it ,still not working .

    ..\F1.ps1 ExportToCSV -excelFileName "Sample"

    Can someone help me to figure this out ?

    --- Update, 

    I saved the function to profile and tried to see using dir function: but not showing up , I followed couple of articles but not sure whats wrong I am doing 

    • Edited by rommy08 Friday, November 16, 2018 9:55 PM
    Friday, November 16, 2018 9:31 PM
  • To load a function in a PS1 file it is necessary to dot source the file.  It is far easier to remove the function wrapper and just call the file.


    Friday, November 16, 2018 9:46 PM
  • I tried using command above , if that is not correct , can you pls help me to fix it ?

    ..\F1.ps1 ExportToCSV -excelFileName "Sample"


    ./F1.ps1 ExportToCSV -excelFileName "Sample"
    The term '../F1.ps1' 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:10
    + ../F1.ps1 <<<<  ExportToCSV -excelFileName "Sample"
        + CategoryInfo          : ObjectNotFound: (../F1.ps1:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
    • Edited by rommy08 Friday, November 16, 2018 10:04 PM
    Friday, November 16, 2018 10:03 PM
  • . .\F1.ps1
    ExportToCSV -excelFileName Sample

    Please read all of this carefully.

     help about_scripts -ShowWindow




    • Edited by jrv Friday, November 16, 2018 10:38 PM
    • Marked as answer by rommy08 Friday, November 16, 2018 11:35 PM
    Friday, November 16, 2018 10:35 PM
  • Thank you , It worked finally with your help , I compared the syntax and realized that I was missing space between 2 dots ,
    Friday, November 16, 2018 11:35 PM