Author Posts

August 7, 2014 at 11:23 am

I am Trying to copy a folder from a UNC path to a remote PC and add registry Key and value on that remote PC also. The Registry piece seems to work but the file copy dose not. Any ideas?
Thanks

$servername = "serv1"

copy-item -Path "\\shares\home\user\AdminTools\bginfo\" -Recurse -Destination "\\$servername\c$\BGInfo"

Invoke-Command -ComputerName $servername -ScriptBlock {

$baseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", $servername)
$key = $baseKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run\", $true)
$key.SetValue('bginfo', 'c:\\bginfo\\bginfo.bat')
}

August 7, 2014 at 11:40 am

I just tried it and it did seem to work for me so might not necessarily be the code.

Do you get any error messages?

August 8, 2014 at 2:39 am

Looks like it might be a problem with Windows 2012 , it does seem to work with 2008. On 2012 it creates an object on the root of C with the folder name but is not a folder. No errors...

August 8, 2014 at 2:40 am

hmm that's strange as i tested on server 2012 too

August 8, 2014 at 2:53 am

On windows 2012 File and Print sharing is not enabled by default. that means your administrative shares like \\server\c$ are not available. That's why your copy fails.
To enable file and print sharing on Server 2012 you can try:

    Invoke-Command -ComputerName MyServer { netsh advfirewall firewall set rule group=”File and Printer Sharing” new enable=Yes } 

August 8, 2014 at 3:12 am

Thanks Sam tried that but didn't change its behavior..
just creates a 7KB inaccessible file called BGInfo. In addition noticed that the registry key creation and value work on 2012 but not 2008? Ugh
In the 2008 Registry issue I do reciev an error, but WinRM service is running...

ERROR: the WinRM service: "winrm quickconfig". For more information, see the about_Remote_Troubleshooting Help topic.
ERROR: + CategoryInfo : OpenError: (tools01:String) [], PSRemotingTransportException
ERROR: + FullyQualifiedErrorId : CannotConnect,PSSessionStateBroken
ERROR: [tools01] Connecting to remote server tools01 failed with the following error message : The client cannot connect to the destination specified in the request.
ERROR: Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on
ERROR: the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure
ERROR: the WinRM service: "winrm quickconfig". For more information, see the about_Remote_Troubleshooting Help topic.
ERROR: + CategoryInfo : OpenError: (tools01:String) [], PSRemotingTransportException
ERROR: + FullyQualifiedErrorId : CannotConnect,PSSessionStateBroken

August 8, 2014 at 3:18 am

So ran winrm quickconfig on the 2008 server and modified the listener, now that works but is there a way to enable that via powershell?

August 8, 2014 at 3:45 am

the lines

$servername = "serv1"
copy-item -Path "\\shares\home\user\AdminTools\bginfo\" -Recurse -Destination "\\$servername\c$\BGInfo"

have been tested to work as intended from server 2012 r2 to server 2012 r2

August 8, 2014 at 4:07 am

Thanks Sam must be something with our Windows set up...