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)?
$HostedRegFile
appears to be a UNC path, but you have a colon in the path. You need to changeD:
toD$
The
regedit
fails because it prompts for UAC upon launch but you're not running with a GUI to acknowledge and allow that. To allow the the UAC launch add-verb runas
to theStart-Process
invocation.If the end goal is to run via DSC, you will need to create some normal shares that computer accounts in the domain will have access to. Domain Computers do not have access to admin shares like D$ and C$.
To avoid regedit and UAC issues, use native powershell cmdLets:
Set-ItemProperty -Path HKLM:\Software\XYZ -Name Color -Value Blue -Type String
-Type can also be DWORD, QWORD, Binary, ExpandStringIt also possible to push registry entries via GPO.
Here is what I ended up with.
Course UAC and WinRM had to be taken care of before this works.