0

Hello Guys i would like your help in the following. I have a folder that contains some msi files that i am installing with powershell. the code is as follows.

Start-Process -FilePath $(Join-Path -Path $PSScriptRoot -ChildPath "VS2010_Runtimes_x86.msi") -ArgumentList '/qb' -Wait

i use the same command to install the rest of the msi files. I have a different folder thats called Project that lives inside the original folder. I would like to copy all the files that are inside project folder to a different directory.

Copy-Item -Path $(Join-Path -Path $PSScriptRoot -ChildPath "Project") -Destination "C:\Program Files (x86)\Hewlett Packard Enterprise\Records Manager" -Recurse

The code for copying files does not work :(

My entire code is:

Start-Process -FilePath $(Join-Path -Path $PSScriptRoot -ChildPath "VS2010_Runtimes_x86.msi") -ArgumentList '/qb' -Wait
Start-Process -FilePath $(Join-Path -Path $PSScriptRoot -ChildPath "VS2013_Runtimes_x86.msi") -ArgumentList '/qb' -Wait
Start-Process -FilePath $(Join-Path -Path $PSScriptRoot -ChildPath "HPE_RM_x86.msi") -ArgumentList '/qb' -Wait

Remove-Item 'C:\Users\Public\Desktop\HPE RM Queue Processor.lnk'
Remove-Item 'C:\Users\Public\Desktop\HPE RM Desktop.lnk'

Copy-Item -Path $(Join-Path -Path $PSScriptRoot -ChildPath "Project") -Destination "C:\Program Files (x86)\Hewlett Packard Enterprise\Records Manager" -Recurse
mjsqu
  • 5,151
  • 1
  • 17
  • 21
  • 1
    I can't reproduce the error, can you run the `Copy-Item` with the `-Verbose` switch and include the output in your question? – mjsqu Nov 19 '19 at 23:20
  • Please elaborate on "does not work". Is your code running under an account that can write files to a subdirectory of ``C:\Program Files (x86)\``? – Lance U. Matthews Nov 19 '19 at 23:35
  • it does not copy files, i get an error message Join-Path : Cannot bind argument to parameter 'Path' because it is an empty string. – Yevgeniy Karazhov Nov 19 '19 at 23:46
  • @BACON yes, my account has rights. i am an admin on the computer. – Yevgeniy Karazhov Nov 19 '19 at 23:49
  • https://stackoverflow.com/questions/44474074/powershell-psscriptroot-is-null – mjsqu Nov 20 '19 at 00:11
  • Your `Start-Process` lines should also fail with the same error. Can you include the entire output in your question please. – mjsqu Nov 20 '19 at 00:42
  • @mjsqu Start-Process does not fail. it executes installation of the msi just fine. When i run single line of code that should copy files from Project Folder i get the following error. Join-Path : Cannot bind argument to parameter 'Path' because it is an empty string. At line:1 char:35 + Copy-Item -Path $(Join-Path -Path $PSScriptRoot -ChildPath "Project") ... + ~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Join-Path], ParameterBindin if this is not the correct way of copying the files, what would be the correct way? – Yevgeniy Karazhov Nov 20 '19 at 17:19
  • 1
    I would extract your project path resolution into a separate line so you can print and verify that the result of `Join-Path` is what you expect it to be (e.g. `$projectPath = Join-Path -Path $PSScriptRoot -ChildPath "Project"; Write-Host "\`$projectPath: $projectPath"; Copy-Item -Path $project Path -Destination '...' -Recurse`); evidently it's somehow an empty string. No idea why `Join-Path` would work in the prior invocation of `Start-Process` but not when passed to `Copy-Item`, but that's just something that'll have to be debugged. Also, those error details should be added to the question. – Lance U. Matthews Nov 20 '19 at 18:38

0 Answers0