Saturday, November 5, 2016

Change fixed DNS setting via PSExec to deploy and run the PowerShell

Change fixed DNS setting via PSExec and PowerShell

1. Copy the "change_dns.ps1" to the target machine "C:\source\PSTools\change_dns\"

The "change_dns.ps1" content:

$dnsservers = ""
$computers = Get-Content env:computername
foreach ($comp in $computers)

$adapters = gwmi -q "select * from win32_networkadapterconfiguration where ipenabled='true'" -ComputerName $comp
foreach ($adapter in $adapters)

2. PsExec command to run the PowerShell remotely:
(Copy the "change_dns.ps1" into the same folder of PSExec)

C:\source\PSTools\change_dns>PSExec \\Computer1 -u "admin" -p PASSWORD PowerShell -NoProfile -ExecutionPolicy Bypass C:\source\PSTools\change_dns\change_dns.ps1

If success, will return the following value:

PsExec v2.2 - Execute processes remotely
Copyright (C) 2001-2016 Mark Russinovich
Sysinternals -

__GENUS          : 2
__CLASS          : __PARAMETERS
__RELPATH        :
__DERIVATION     : {}
__SERVER         :
__NAMESPACE      :
__PATH           :
ReturnValue      : 0


PowerShell exited on Computer1 with error code 0.


Print Friendly and PDF

No comments:

Post a Comment