Norskyi
Norskyi

Reputation: 151

PS Script to install software from remote domain share

I am working on creating a PowerSell script to install software from a remote share located on a different domain that requires authentication. So, from a target server if I try browsing to remote domain share, I have to type in username/password (from remote domain) to authenticate.

Is there a way to account for this authentication in PowerShell? Would I be using PSCredential for this purpose?

My script would copy the files from remote share to a local computer and then run the installers

Param{
   [ValidateScript({Test-Path $_})]   
      [String]$RemoteShare="\\remote.domain\share"
}

$Localfolder = "C:\temp"
$Software1 = "Examplesoftware.exe"

Copy-Item -Path (Join-Path -Path $RemoteShare -Childpath $Software1) -Destination $Localfolder

error:

WARNING: , System.Management.Automation.ItemNotFoundException
WARNING: Cannot find path '\\remote.domain\share\Examplesoftware.exe' because it does not exist.

Thank you

Upvotes: 0

Views: 321

Answers (1)

Alex_P
Alex_P

Reputation: 2950

First enable PSRemoting:

Enable-PSRemoting -Force

Afterwards, create a new PS session:

New-PSSession -Session $session -Credential Domain01\User01

And finally you can try something like this:

Copy-Item -FromSession $session C:\Programs\temp\test.txt -Destination C:\Programs\temp\test.txt

Here are two informative links:

PowerShell explained - PS remoting

PSRemoting

Copy files

Upvotes: 1

Related Questions