# Powershell 3.0 Remoting

**URL:** <https://forums.powershell.org/t/powershell-3-0-remoting/1826>\
**Category:** PowerShell Help\
**Created:** [August 21, 2013, 11:45pm UTC](https://forums.powershell.org/t/powershell-3-0-remoting/1826 "2013-08-21T23:45:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul-brutus](https://avatars.discourse-cdn.com/v4/letter/p/c67d28/32.png) [@paul-brutus](https://forums.powershell.org/u/paul-brutus)\
**Post date:** [August 21, 2013, 11:45pm UTC](https://forums.powershell.org/t/powershell-3-0-remoting/1826/1 "2013-08-21T23:45:07Z")

</div>

I am new to Powershell. I am attempting to create a powershell script that will archive a â€œLOGSâ€ folder located in the root of â€œCâ€ drive from a workstation. The â€œLOGSâ€ folder consisted of several subfolders. Each subfolder holds different types of logs. The script should create a folder with the computername on the server share, create a subfolder with todayâ€™s date and move the â€œLOGSâ€ folder to the server share inside the todayâ€™s date subfolder which is inside the computername folder.

When I open a powershell console on a local computer and run the script, it moved the â€œLOGSâ€ folder to the server share without any issues. The problem is that I would like to run the script on a remote computer. Letâ€™s say, copy the script to a remote computer and run it remotely. These are the commands I have tried:

Invoke-Command â€“filepath c:\backup.ps1 â€“computername computer002  
Invoke-Command â€“Computername computer002 â€“ScriptBlock {C:\backup.ps1} â€“Credential DOMAIN\User  
Invoke-Command â€“Computername computer002 â€“b.exe {C:\backup.ps1}

If I copy the script â€œbackup.ps1â€ on the local computer and run it from a DOS command prompt with this command : â€œpowershell.exe C:\backup.ps1â€. It worked just fine. If run it in a powershell console on the local computer it worked fine as well. How do you run a powershell script on a remote computer? Thanks!

This is what the script looks like:  
[string]$btoday = Get-Date â€“format â€œMM-dd-yyyyâ€  
[string]$backuppath = New-Item “\server0009\archivedata${Env:ComputerName}$btoday” â€“Type directory â€“Force  
Move-Item â€“Path C:\TEST1 â€“Destination $backuppath

---

<div class="post-metadata">

**Author:** ![powerschill](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/powerschill/32/942_2.png) [@powerschill](https://forums.powershell.org/u/powerschill)\
**Post date:** [August 21, 2013, 11:59pm UTC](https://forums.powershell.org/t/powershell-3-0-remoting/1826/2 "2013-08-21T23:59:54Z")

</div>

Your examples will not work unless the backup.ps1 script exists in the C:\ folder on the remote machines. Since your script is very simple I would suggest just passing the code in a script block like so:

`$ScriptBlock = {
[string]$btoday = Get-Date â€“format â€œMM-dd-yyyyâ€
[string]$backuppath = New-Item â€œ\server0009\archivedata${Env:ComputerName}$btodayâ€ â€“Type directory â€“Force
Move-Item â€“Path C:\TEST1 â€“Destination $backuppath
}`

`
`

`Invoke-Command -ComputerName Computer002 -ScriptBlock $ScriptBlock
`

---

<div class="post-metadata">

**Author:** ![paul-brutus](https://avatars.discourse-cdn.com/v4/letter/p/c67d28/32.png) [@paul-brutus](https://forums.powershell.org/u/paul-brutus)\
**Post date:** [August 22, 2013, 3:46am UTC](https://forums.powershell.org/t/powershell-3-0-remoting/1826/3 "2013-08-22T03:46:58Z")

</div>

I copied the backup.ps1 script in the C:\ on the remote machine and still doesn’t work. I can run it locally on any machine and it will work. Thanks!

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:57pm UTC](https://forums.powershell.org/t/powershell-3-0-remoting/1826/4 "2024-05-16T20:57:38Z")

</div>

Closed on May 16, 2024, 8:57pm UTC


