Hello,
I thought I’d create a new post regarding this now I have go this far. So this script is running on a Windows server which is on the domain and can retrieve the modified date of the file listed below. The issue I have is trying to get this info from a Windows device not on the domain and on a remote network. I ran it and I could see the firewalls blocking TCP 5985/5986 (WinRM), I go these opened and I get an access denied message now.
Error
[10.7.17.140] Connecting to remote server 10.7.17.140 failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (10.7.17.140:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : AccessDenied,PSSessionStateBroken
Script
$user = 'user1'
$file = 'C:\temp\pwd.txt'
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $user, (Get-Content $file | ConvertTo-SecureString)
$ComputerNameList = Get-Content 'c:\temp\devices.txt'
$Output =
foreach ($ComputerName in $ComputerNameList) {
if (Test-Connection -ComputerName $ComputerName -Count 1 -Quiet) {
Invoke-Command -ComputerName $ComputerName -Credential $credentials -ScriptBlock {
Get-ChildItem -Path '\\$ComputerName\c$\ProgramData\data.xml' -ErrorAction SilentlyContinue
} |
Select-Object -Property PSComputerName, LastWriteTime, Name
}
}
$Output |
Export-Csv -Path 'c:\temp\dataxml123.csv' -NoTypeInformation
I can Telent to 10.7.17.140 on 5985 (not 5986), I had to get someone to enable WinRM on the remote machine, do I need to do anything on the server?
I’ve ran this too:
winrm s winrm/config/client '@{TrustedHosts="10.7.17.140"}
I can browse to the file location too:
I did get a username and password prompt and as it’s a local username I have to enter as .\user1 but I’m not sure how I do that in the script.
Any ideas/help on the above issue would be great.
Thanks