My goal is to remotely make 2 quick files containing mappings for mapped drives and network printer connections and place the files in the remote c:\temp folder.
When i run the code it applies everything to my own pc. However, if i type each line individually, it works perfect.
side note: I noticed that i had to use the userid and password of the person that was currently logged in to the remote system to get to the point i’m currently at.
$userid= Read-Host 'Enter Userid'
$pcname= read-host 'Enter PC Name'
Enter-PSSession -ComputerName $pcname -Credential domain\$userid
Get-ChildItem -Path HKCU:\Network | Out-File c:\temp\Drives.txt -Force
Get-ChildItem -Path HKCU:\Printers\Connections | Out-File c:\temp\printers.txt -Force
Exit-PSSession
Any ideas why i cant run this all at once?
Thanks again!
-michael
This won’t work if your goal is to run it all at once, instead of one line at a time. Read-host doesn’t work that way. Saving Read-host to $userid and $pcname will not prompt for input when those variables are used as parameters. Check out the help on Read-host.
The best approach is to create a function with mandatory parameters called $userid and $pcname that accept string data. For example: