Need Powershell Script to pull TXT from Remote share location.

I have a PowerShell script that works perfectly when the TXT file is found locally. I want to have the TXT file be remote, the script is unhappy.
The errors I get are:

Access is denied
    + CategoryInfo          : PermissionDenied: (\\server\files\temp\text.txt:String) [Get-Content], UnauthorizedAcce
    + FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetContentCommand
    + PSComputerName        :

Cannot find path '\\server\files\temp\text.txt' because it does not exist.
    + CategoryInfo          : ObjectNotFound: (\\server\files\temp\text.txt:String) [Get-Content], ItemNotFoundExcept
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
    + PSComputerName        :

Script is:

$app = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null

$TextFile = "C:\Temp\text.txt"
$Text = [System.Security.SecurityElement]::Escape((Get-Content -Path $TextFile -Raw))

$Template = [Windows.UI.Notifications.ToastTemplateType]::ToastImageAndText01

# Gets the Template XML so we can manipulate the values
$ToastTemplate = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent($Template).GetXml()

$ToastTemplate = @"
<toast launch="action=viewAlarm&amp;alarmId=3" scenario="alarm">
		<binding template="ToastGeneric">
			<image placement="appLogoOverride" hint-crop="circle" src="" />
			<image placement="hero" src="" />
		<action activationType="system" arguments="snooze" content="" />
		<action activationType="background" arguments="dismiss" content="Dismiss"/>

$ToastXml = New-Object -TypeName Windows.Data.Xml.Dom.XmlDocument

$Notify = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($app)


Open in new window

Glenn MSystems Engineer / ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jose Gabriel Ortega CastroCEOCommented:
you need to modify, line 4
$TextFile = "C:\Temp\text.txt"
to the remote computer in a shared drive with permissions.

The script is unhappy because you don't have access to that directory with the user that is running the script.
The error is pretty clear:
Access is denied
PermissionDenied: (\\server\files\temp\text.txt:String) [Get-Content], UnauthorizedAccessException
Glenn MSystems Engineer / ManagerAuthor Commented:
Yes, I understand where I need to make the change, for example: $TextFile = "\\server\files\temp\text.txt"
My problem is that I DO have permissions to that share and I am running this as a "domain users" have RWXD permissions and access to that share.

I don't think NTFS or Share permissions are the issue here.
Jose Gabriel Ortega CastroCEOCommented:
Just double check you need permissions on the "security" tab and in the "share" tab of your shared folder

Probably is something related to double-hop.
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Glenn MSystems Engineer / ManagerAuthor Commented:

Jose Gabriel Ortega CastroCEOCommented:
Ok did you check the link?
Try with this in front of the name

something like this in line 4:
Glenn MSystems Engineer / ManagerAuthor Commented:
forgive me... I'm not super savvy here.
I understand what needs to be replaced on line 4. The Part before that, where does that need to do?
Jose Gabriel Ortega CastroCEOCommented:
This should be pretty simple:

$target= Microsoft.PowerShell.Core\FileSystem::\\<targetserver>\<sharedfolder>
Copy-Item -Path $source -Destination $target -Recurse -Recurse

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Glenn MSystems Engineer / ManagerAuthor Commented:
I was hoping that someone would put it all together, with the script I provided and the answers given. I am attempting to see if I can splice it is. I am assuming this will help. Thanks in advance...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.