search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Adding file and secondary IP to remote host with Powershell
Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 13,391 views | 20/11/2009 02:18

You need to add secondary ip to external host? You only need to Powershell and Psexec. Psexec is a small and free program. You can download Psexec from Microsoft Technet. It works great!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# VM Config Tool
# Created By Yusuf Ozturk
# In God We Trust, All Others We Use Powershell
 
# PsTools: http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
 
$VMName = Get-VM VDS*
 
foreach ($VM in $VMName)
{
    $IP = ($VM.Name).TrimStart('VDS00')
 
    $Server = "10.10.10." + $IP
 
    $IP1 = "10.10.11." + $IP
    $IP2 = "10.10.12." + $IP
    $IP3 = "10.10.13." + $IP
 
    $PSExecPath = "\\10.10.10.2\yusufozturk$\PsTools\psexec.exe"
 
    $Command1 = "netsh interface ipv4 add address ""Local Area Connection"" $IP1 255.255.255.0"
    $Command2 = "netsh interface ipv4 add address ""Local Area Connection"" $IP2 255.255.255.0"
    $Command3 = "netsh interface ipv4 add address ""Local Area Connection"" $IP3 255.255.255.0"
    $Command4 = "xcopy \\10.10.10.2\yusufozturk$\IIS\default.asp C:\inetpub\wwwroot\"
 
    $Shell1 = $PSExecPath + " \\" + $Server + " -u Administrator -p Password123 " + $Command1
    $Shell2 = $PSExecPath + " \\" + $Server + " -u Administrator -p Password123 " + $Command2
    $Shell3 = $PSExecPath + " \\" + $Server + " -u Administrator -p Password123 " + $Command3
    $Shell4 = $PSExecPath + " \\" + $Server + " -u Administrator -p Password123 " + $Command4
 
    cmd.exe /c $Shell1
    cmd.exe /c $Shell2
    cmd.exe /c $Shell3
    cmd.exe /c $Shell4
 
}

You need to add /c switch for cmd.exe to execute scripts in a script. You need to accept Eula of Psexec first.



Leave a Reply