Copy Files from Folder

Hello all, i am working on the project that i am struggling a little bit. I am tasked with creating a shortcut for a website but i need to use a custom icon for it. Here is my folder structure.


And here is the Powershell script that i am using to accomplish that.

}

Param(
     [parameter(Mandatory=$true)]
     [ValidateSet("ADD","REMOVE")]
     [String]$ShortcutType
   )


Function  Push-OneStreamWebAll{
$Shell1 = New-Object -ComObject ("WScript.Shell")
$ShortCut1 = $Shell1.CreateShortcut("C:\Users\Public\Desktop\Service-Now.lnk")
$ShortCut1.TargetPath ="C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
$ShortCut1.Arguments = "https://service-now.com/sp"
$ShortCut1.WorkingDirectory = "C:\Program Files (x86)\Microsoft\Edge\Application"
$ShortCut1.WindowStyle = 1
$ShortCut1.IconLocation = "C:\ProgramData\altas.ico"
$ShortCut1.Save()

}

The icon that i MUST use is located in a Spport Files Folder. Somehow i need to tell the script to copy that file from Support folder to “C:\ProgramData” and i don’t really know how to do that. Any help would be great.
thank you.

Eugene,
Welcome to the forum. :wave:t4:

I’m unsure if I got what your issue really is. To copy a file in PowerShell we use:

If that’s not what you wanted to ask you may elaborate a little more detailed.

Thank you for your reply. Here is the scenario. I will be building a package with SCCM to deploy the shortcut. it will end up on a users computer in a cache folder with some random name. So it will look like this.
SCCM Cache folder with a random name → ServiceNow Web Shortcut. Inside that folder there will be Powershell Script and another folder called Supported Files. Script needs to copy file from the Support Files folder to C:\ProgramData.
I just don’t know how to point the script to that Support Files Folder since there is no way for me to know that would be a name of that cache folder that SCCM will create.

If the script is running from the same folder as the Support Files folder, just use the relative path:

Copy-Item -Path '.\Support Files\atlas.ico' -Destination C:\ProgramData\

Or you could use the automatic variable $PSScriptRoot what points to the path of the script. :wink:

1 Like

no. the folder structure is like this. SCCM Cache folder with some name → ServiceNow Web Shortcut. Inside ServiceNow Web Shortcut folder is the powershell script and another folder called SupportFiles.

So you might adapt your folder structure to your needs. I used to place the script in the root of the package or application source. :wink:

I ended up using this code. But i am wondering if there is something shorter that i can use.

If (Test-Path -LiteralPath 'variable:HostInvocation') { $InvocationInfo = $HostInvocation } Else { $InvocationInfo = $MyInvocation }
$scriptDirectory = Split-Path -Path $InvocationInfo.MyCommand.Definition -Parent

Copy-Item $scriptDirectory\SupportFiles\atlas.ico -Destination C:\ProgramData\ -Recurse -Force

If I got it right this should work …

Copy-Item $PSScriptRoot\SupportFiles\atlas.ico -Destination C:\ProgramData\ -Recurse -Force

Copy-Item $PSScriptRoot\SupportFiles\atlas.ico -Destination C:\ProgramData\ -Recurse -Force

Nope, that didn’t work :slight_smile:

OK, I actually did not get where your script files is saved but you could make your life easier by placing it in the root folder of the package source. Then this would work. :wink:

But since you seem satisfied with the solution you have all is fine now. :wink:

yeah :slight_smile: I am just trying to follow example of PSAppDeploy and have everything organized and put all the files in to their prospective folders.