Trying to create application to

Welcome Forums General PowerShell Q&A Trying to create application to

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
10 months, 2 weeks ago.

  • Author
    Posts
  • #90857

    Participant
    Points: 0
    Rank: Member

    Hey,

    I am trying create a script that copies a file from the current directory and sends it to a path. I tried to use .\ this script works if I type a the full path name. THe powershell script and the file would be in the same directory and sccm would download it locally and run it locally. The source path can not be static because the source could be different on every machine.

    The script below. I changed the source path for security purposes.

    path = "D:\install\support\logon\scripts"
    If(!(test-path $path))
    {
    New-Item -ItemType Directory -Force -Path $path
    }

    $Source = "\\192.168.1.1\TEST"
    $Destination = "D:\install\support\logon\Scripts\"

    $ExcludeItems = @()
    if (Test-Path "$Destination\*.dli")
    {
    $ExcludeItems += "*.dli"

    }

    Copy-Item "$Source\*" -Destination "$Destination" -Exclude $ExcludeItems -Recurse -Force

  • #90860

    Participant
    Points: 22
    Rank: Member

    Just want to verify, the $Source variable is what you're trying to dot-source, right?

    • #90863

      Participant
      Points: 22
      Rank: Member

      Let me elaborate a little more.
      When you run a script and .\ a location, it .\ in the default directory, not necessarily the invocation path. (Someone can correct me if I'm mistaken here)

      Instead of .\, try something like this:

      $Source = Split-Path -Parent $MyInvocation.MyCommand.Path

The topic ‘Trying to create application to’ is closed to new replies.