Hi everyone,
I need some assistance with an issue I have.
I need to run a script on a local machine to connect to a remote machine to search a directory for a folder and delete the folder.
I'm using the following command to connect to the remote computer: -
The connection to the remote computer is fine and works as i get: -
[remotePC]: PS C:\Users\Documents>
What i need to do then is go to a specified directory, search for a folder by name and if that folder is found, delete it. I have tried the following commands in a separate powershell instance manually and it works: -
However if i attempt to run any commands on the remote PC within the script on my local machine, none of the commands pass to the remote machine. Any assistance would be much appreciated Thanks
I need some assistance with an issue I have.
I need to run a script on a local machine to connect to a remote machine to search a directory for a folder and delete the folder.
I'm using the following command to connect to the remote computer: -
Code:
$PShostSession = Enter-PSSession -computername $UserCheckHost
The connection to the remote computer is fine and works as i get: -
[remotePC]: PS C:\Users\Documents>
What i need to do then is go to a specified directory, search for a folder by name and if that folder is found, delete it. I have tried the following commands in a separate powershell instance manually and it works: -
Code:
Invoke-Command -ScriptBlock {set-location "C:\Users\"}
However if i attempt to run any commands on the remote PC within the script on my local machine, none of the commands pass to the remote machine. Any assistance would be much appreciated Thanks