Author Posts

January 5, 2018 at 4:52 pm


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 = "\\\TEST"
$Destination = "D:\install\support\logon\Scripts\"

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


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

January 5, 2018 at 5:01 pm

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

January 5, 2018 at 5:06 pm

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