Remote Synch Schema
Here is the script to synch remotely ...
#Important! Execute Enable-PSRemoting on every remote machine.
Porwershell
$Username = 'domain\user' #Domain admin user
$Password = '123456789'
#Create credential object
$SecurePassWord = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $Username, $SecurePassWord
foreach($line in [System.IO.File]::ReadLines("local path\hosts.txt")) #ip addresses list of the remote machines
{
$line
set-item wsman:\localhost\Client\TrustedHosts -value $line -Force
#Create session object with this
$Session = New-PSSession -ComputerName $line -credential $Cred
#Invoke-Command
$Script_Block = "remote path\SynchThis.ps1" #This file is needed on every remote machine
$Script = $executioncontext.invokecommand.NewScriptBlock($Script_Block)
$Job = Invoke-Command -Session $Session -Scriptblock $Script
#Close Session
Remove-PSSession -Session $Session
}
Comentarios
Publicar un comentario