install from any location

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Curtis Smith Curtis Smith 1 month ago.

  • Author
    Posts
  • #73861
    Profile photo of Rawdogz
    Rawdogz
    Participant

    hi all. currently i have a script that is coded to run from the desktop, i would like to change it to run form anywhere.it has files it calls on that is located in a sub folder in the same parent folder
    .\script\ de.ps1 (main script)
    .\script\bin\test.* (file it calls)

    this is what i have so far. but it not locating the Test.*

    
    Function get-location
    {
    $invocation = (get-variable myinvocation -scope 1).value
    split-path $invocation.mycommand.path
    }
    $dir = get-location
    copy-item $dir\bin\test.* 'c:program files\'
    
    

    thanks for any help

  • #73864
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    Your $invocation.mycommand.path is not returning what you want.

    Try one of these based on your need:

    -------------------------------------------
    For PS 2.0: $MyInvocation.MyCommand.Definition
    C:\temp\test.ps1
    -------------------------------------------
    For PS 2.0: Split-Path -parent $MyInvocation.MyCommand.Definition
    C:\temp
    -------------------------------------------
    For PS 3.0 and later: $PSCommandPath
    C:\temp\test.ps1
    -------------------------------------------
    For PS 3.0 and later: Split-Path -parent $PSCommandPath
    C:\temp
    -------------------------------------------
    For PS 3.0 and later: $PSScriptRoot
    C:\temp
    -------------------------------------------

You must be logged in to reply to this topic.