November 11, 2020 at 6:24 pm #270811
I’m trying to copy a file to a new folder on a remote server but its creating the new folder on my computer, not on the server. NEED HELP!
This is what I have:
$AO = New-PSSession -ComputerName “computer” -Credential “user”
Copy-Item -Path “C:\Test1.txt” -Destination (New-Item -Path “C:\Tools\prac” -ItemType “directory”) -Force -ToSession $AO
- This topic was modified 3 weeks ago by ArtOli67.
November 11, 2020 at 7:22 pm #270817ParticipantTopics: 9Replies: 170Points: 836Rank: Major Contributor
New-Item -ItemType Directory -Path '\\computer\c$\tools\prac'
Not sure if you are using the PSSession for other things but it is not necessary here if you have admin on the remote system.
November 11, 2020 at 8:38 pm #270841
November 11, 2020 at 10:44 pm #270877ParticipantTopics: 9Replies: 677Points: 2,680Rank: Community Hero
No, when you tab complete it makes it a capital d. It’s not required but it does look better imo. The single quotes prevent the dollar sign from being interpreted as a variable. In this case it isn’t required because it’s not followed by a number or letter, it’s a good idea to get in the habit of only using double quotes when you need variable expansion.
November 11, 2020 at 10:58 pm #270886ParticipantTopics: 0Replies: 1Points: 54Rank: Member
I know this has been answered, but I do this with every server I build to add a file based on the server type. I don’t use a PSSession, this a snippet of the needed code.
Computers = Get-Content C:\Powershell\Text\servers.txt
foreach ($Computer in $Computers)
$destinationFolder = “\\$computer\C$\Temp”
if (!(Test-Path -path $destinationFolder))
New-Item $destinationFolder -Type Directory
November 12, 2020 at 1:39 pm #271132ParticipantTopics: 9Replies: 170Points: 836Rank: Major Contributor
One other point of note that I really like about New-Item is that it will create the full path you define if it does not exist 🙂
November 12, 2020 at 1:50 pm #271141
Thank You so much everyone. I’m teaching myself powershell for work so I’m still learning the correct syntax and stuff. 🙂
- You must be logged in to reply to this topic.