I have bunch of Servers I need to push this patch through. Normally I would load up a WSUS or equivalent. However I would like to get this working in a DSC enviroment. So I am testing scripts to put into place for this workflow.
PowerShell complains it cannot find folder.
Copy-Item $HostedRegFile -Destination $newfile "unauthorized"
Apparently I am not passing credentials correctly. I have tried everything I can think of using sessions to not using sessions..
$servers = Get-Content "d:\Powershell\Servers.txt"
$Session = New-PSSession -computername $servers -credential $MyCredential
$HostedRegFile = "\\Contra2\D:\reg\Player2.reg"
foreach ($server in $servers)
{
#$Session = New-PSSession -computername $server -credential $MyCredential
$newfile = "\\$server\c$\Utils\"
New-Item -ErrorAction SilentlyContinue -ItemType directory -Path \\$server\C$\Utils\
Copy-Item $HostedRegFile -Destination $newfile
Invoke-Command -computername $server -ScriptBlock {
Start-Process -filepath "C:\windows\regedit.exe" -argumentlist "/s C:\Utils\Player2.reg"
}
}
What am I doing wrong? Is there a better way (there always is)?