How to copy files from one server to other server with powershell when the shared path contains '$' symbol -
i have 3 remote servers in hand. let server x, server y , server z. running powershell script local machine login remote server x. server x base server has access other 2 servers. want use server x base server , want copy files server y server z impossible through local machine because of access permissions. logged in server x using admin credentials has access 3 servers. after logging in, mentioning copy-item command copy files shared path of server y shared path of server z.
this similar question many in website here goes twist. when debugging, showing completed not getting results. tried running powershell script directly in server x contains copy-item command , source , destination paths of shared folders. when debugging getting error that, user doesn't have permissions or path not found. when trying copy , paste files shared path manually using same credentials, working. through powershell script, it's working. know reason. it's because of symbol '$' in shared paths. need solution this. not allowing '$' symbol in source , destination paths. there alternative this? if try remove symbol , copy files, 'access denied' error shared path, e drive should prefixed $ symbol.
here goes code:
#calling server name, credentials app.config file $currentdirectory = [io.path]::getdirectoryname($myinvocation.mycommand.path) $appconfigfile = [io.path]::combine($currentdirectory, 'app.config') $appconfig = new-object xml $appconfig.load($appconfigfile) $servername = $appconfig.configuration.appsettings.add[0].value $username = $appconfig.configuration.appsettings.add[1].value $password = convertto-securestring -string $appconfig.configuration.appsettings.add[2].value -asplaintext -force $cred = new-object -typename system.management.automation.pscredential -argumentlist $username,$password logging server x using credentials , copying files server y server z
invoke-command -computername $servername -credential $cred -scriptblock { copy-item "\\servery\e$\sourcetestfolder\test.docx" "\\serverz\e$\desttestfolder" }
first idea: replace " '. powershell stops fall on $-symbols. way have written says: "hey powershell, go ahead , variable named $e , put in there".
Comments
Post a Comment