locked
Powershell script requiring Powershell 2.0 not working in v5.1 Start-Process : A parameter cannot be found that matches parameter name 'Path' RRS feed

  • Question

  • I'm absolutely sure this script needs work; but, I'm not sure where to start except, let's start with Is there a list of requirements or a update path for scripting changes from Powershell version 2.0 to 5.1?
    This issue right from the get go is that it's not accepting parameter 'name's.  I've noticed that the parameters don't have any explicit declaration except in checking the values in the param section, but the errors are for line 1, in the parameters being passed and it's failing not recognizing the name "Path" as in the following line.
    Start-Process NewScript.ps1 -Path "C:\ValidPath" or

    both "Path" and "XML" as in

    Start-Process PsFCIV -Path C:\tmp -XML DB.XML

    Can someone point me in the right direction to handle this... Yes, I'm new to Powershell scripting; but, I have an extensive programming background in many languages.  My biggest issue is that most of the TechNet articles, and Documents are not specific to Version 5.1, and well... knowing what's now needed versus what was needed then for earlier versions is proving problematic.  I feel like this is related to parsing the command line variables, but it's not failing at the data; but at the stored variable name for the parameter like it doesn't know it exists.  Since originally this was in Version 2 or 2.5 (hard to tell), it seems some kind of declaration is missing for the parameters.  In a script where there are multiple parameters being passed, it's failing on the "-ParameterName" part of the command line, not the data itself.  

    If I leave out the designation for the name, it will accept the parameter, but fail at the next
    -Name2 "stringdata" designated @ -Name2 just like the first parameter... if I also leave out the parameter name, it continues to the next one, accepts the string "data", and fails on the 3rd parameter name.  I have no idea what's being accepted where...  

    Thanks so much for any help whatsoever.


    Chip Cooper







    • Edited by Cyberchipz Saturday, August 5, 2017 6:27 PM
    Saturday, August 5, 2017 6:16 PM

Answers

  • If you are trying to run the PS FCIV utility command then you need to carefull ready the instructions and exam-les for the PS1 file.

    TO execute a PS1 file you must specify the path. 

    c:\temp\PsFCIV_2.5.ps1

    The extension is also required.

    To load a PS1 that contains a function you must dot source it:

    . c:\temp\PsFCIV_2.5.ps1

    To get help for the function after laoding type:

    help Start-PsFCIV -full

    TO get help with the script post to the author: https://gallery.technet.microsoft.com/PowerShell-File-Checksum-e57dcd67/view/Discussions#content

    If you had learned PowerShell you would already have known all of this.


    \_(ツ)_/

    • Marked as answer by Cyberchipz Sunday, August 6, 2017 8:05 AM
    Saturday, August 5, 2017 7:18 PM

All replies

  • PowerShell scripts written for PS 2 work in PS 5.1

    You example is supported the same way in all versions of PowerShell.

    I recommend that you start by either learning PowerShell or by contacting the author of the script to find out why it is not working.

    To declare a script as being for a specific version "#requires -version 2" just set the minimum level of support and does not, in any way, restrict a script to that version.

    Parameters are defined in the called script.  If the called script has no "param" statement with a parameter called "$Path then passing a parameter of that name will not work in any version of PowerShell.

    Without some better understanding of PowerShell you will not be able to ask a question that is useful.  You have also failed to post the full error or any script example.


    \_(ツ)_/

    Saturday, August 5, 2017 6:28 PM
  • As mentioned posting a link to the script would help, others could test it. This one?

    If so the Useful examples down the page may help;

    Start-PsFCIV -Path C:\tmp -XML DB.XML

    Saturday, August 5, 2017 6:52 PM
  • Read the help for Start-Process.  Your issue has nothing to do with PS versions it is just an incorrect use of a common PS CmdLet.

    help Start-Process -full

    Use names for all of the parameters.  Take some time to learn PowerShell so you don't make these simple errors.

    Also, in PowerShell, we do not need to use Start-Process to execute an external program.  Just type it in like you would on any command line.

    c:\temp\PsFCIV -XML DB.XML

    Try it at a prompt. To get the correct parameters type this:

    c:\temp\PsFCIV /?

    "=Path" on any Windows command assumes a file path.  The help will tell you that "Path"  is not valid for Start-Process.  The parameter is "FilePath".

    Always use help to learn how to use any CmdLet you are not used to.  Learn PowerShell before proceeding.


    \_(ツ)_/


    • Edited by jrv Saturday, August 5, 2017 7:07 PM
    Saturday, August 5, 2017 7:04 PM
  • If you are trying to run the PS FCIV utility command then you need to carefull ready the instructions and exam-les for the PS1 file.

    TO execute a PS1 file you must specify the path. 

    c:\temp\PsFCIV_2.5.ps1

    The extension is also required.

    To load a PS1 that contains a function you must dot source it:

    . c:\temp\PsFCIV_2.5.ps1

    To get help for the function after laoding type:

    help Start-PsFCIV -full

    TO get help with the script post to the author: https://gallery.technet.microsoft.com/PowerShell-File-Checksum-e57dcd67/view/Discussions#content

    If you had learned PowerShell you would already have known all of this.


    \_(ツ)_/

    • Marked as answer by Cyberchipz Sunday, August 6, 2017 8:05 AM
    Saturday, August 5, 2017 7:18 PM
  • Very helpful, from this I was able to understand the param statements, especially why $Path did not require -Path for parameter, and why '-XML' did.
    The comment "PowerShell scripts written for PS 2 work in PS 5.1" addressed a specific issue as well as  "...does not, in any way, restrict a script to that version"
    I now see I did not able to ask a question that was useful... but, you gleaned something from it and provided what I needed. Thank you.

    Chip Cooper

    Sunday, August 6, 2017 7:19 AM
  • Yes, I see that it would, as you would have been able to instantly recognize it contained a function, and in fact is a function. Thank you.  The useful examples were not useful to me until I dot sourced the function. Nothing is mentioned in HELP, so it also was not useful in that regard.  We are only 'once' new to a language, my perspective is not unique, as an experience programmer with a new language.  I learn fastest once I have a working script that produces expected results.  From the script I glean the syntax, structure, and looking up individual words, I gain an understanding by their placement and from that, their intent.  

    The key point in here was the reason why the cmdlet after Start- which is PsFCIV is used, especially after I dot sourced the function, and when typing into the console, the ISE tried to autocomplete Start-[Start-PsFCIV]! (light-bulb)
    Thank you for your help.

    Chip Cooper

    Sunday, August 6, 2017 7:28 AM
  • Spot on!  I read all your replies, and found them extremely helpful, you spotted my problem.  I correlated the dot sourcing as 'similar' but not equivalent to an #include in compiled languages, instantly cogniting (having a cognition) on 'not' #include, but the declaration and inserting of the script as a function cmdlet into the powershell environment for use with other scripts, if needed.  

    Ironically it was the next post you made finalized the connection between this script and it as a cmdlet.  Every bit was helpful.  I will not claim that I instantly grokked the connection; I did make many fits and starts.  This is experience, I wasn't afraid to break anything.

    The biggest issue I discovered on my own, and this says it all... I needed to Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process; and CD C:\FCIV didn't hurt any. XD.  Until I worked out the $Path and $XML requirements, working from a single directory was helpful; now it doesn't matter.

    Thank you again! 

    Chip Cooper

    Sunday, August 6, 2017 7:39 AM
  • Again, I could call the HELP file up in the usual way... Microsoft is pretty consistent about this, thank goodness; but, I was also reading the script, which contained the HELP file.  It was not useful, and assumed the user knew the script had to be dot sourced into the environment to be used.  In fact, pretty much every fail popped up the Help file.  All examples are for after it becomes available as a cmdlet... naturally. XD ...in this case.

    Absolutely True, "If I had learned PowerShell I would already have known all of this." It has been a good first day!

    So, plaudits you're savvy to an experienced programmer nerd encountering this new environment and language. 
    I would only have contacted the developer as a last resort... I hadn't confirmed there was anything other than an ID10T problem.  It's awfully embarrassing as it is... but, I could not narrow down where to start; and being as experienced as you are, you know how quickly one can get overwhelmed, and bored going over old and obvious considerations in a language after the first half dozen more or less languages learned.  I've been around enough to make the transition from Top-Down programming to OOP event driven Languages.  In fact, I'm early enough to have been using and developing an 'original' but early form of OOP re-inventing that wheel over and over, without knowing how beneficial and ubiquitous it would ultimately become!

    IOW, the days when Top-Down program had become nothing but a keystroke monitor, even before the existence of a mouse; passing what are now called tokens as background operations during idle time in a keystroke driven world. :-)  pushing and pulling various stacks created in that higher level language that without reiteration, I digress.

    Bottom, line, thanks for the link to the author.  But, I am not void of questions.
    I can not express my gratitude enough for the help you gave, and the time you took. Kudos, and thanks.

    To summarize:

    Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process

    $DebugPreference = "Continue"

    CD C:\FCIV

    . c:\FCIV\PsFCIV2.5.ps1

    Start-PsFCIV C:\FCIV -XML C:\FCIV\NEWdB.XML -HashAlgorithm "SHA256"

    I'm not counting all the syntax, grammar and words I've learned today... :-/  the full Hashing algorithm is yet to come... but not required right now.

    But what I want to know is how this SHA256 looks nothing like the one sent by the distributor with the file I downloaded.  This was both puzzling and disappointing, and (sigh) I'm definitely missing something here.

    And, find an ExecutionPolicy I'm comfortable with... too much SCHTUFF going on out there... 
    I learned a lot... Thank you so much.

    Have a great day!



    Chip Cooper


    • Edited by Cyberchipz Sunday, August 6, 2017 8:12 AM
    Sunday, August 6, 2017 8:04 AM
  • The correct place to start with any new technology is to always RTFM.


    \_(ツ)_/

    Sunday, August 6, 2017 4:30 PM
  • BOCTAOE some questions are beyond the scope of the manual.  So, sure, where is 'the' manual?  Found tons of articles, but haven't run across what I'd call a 'manual' yet; or is that in the manual too? :-)

    Chip Cooper

    Monday, August 7, 2017 4:16 PM