コンテンツへスキップ

作成中

<# 
    パラメータ
    # network
    ifName,ifIndex,Ipaddress,MacAddress,Gateway
    # bonding
    @(ifIndex1,ifIndex2),Ipaddress,MacAddress,Gateway
    # routing
#>

$server = New-Object System.Collections.Hashtable

# ルーティング
$routing1 = ("aのルーティング","bのルーティング")
$routing2 = "cのルーティング"

$server.s001 = @{
    # key は ifIndex
    "network" = @{
        1 = @{
            "name"      = "インターフェース1";
            "ipaddress" = "192.168.1.100";
            "netmask"   = "255.255.255.0";
        };
        2 = @{
            "name"      = "インターフェース2";
            "ipaddress" = "192.168.2.100";
            "netmask"   = "255.255.255.0";
        };
        3 = @{
            "name"      = "インターフェース3";
            "ipaddress" = "";
            "netmask"   = "";
        };
        4 = @{
            "name"      = "インターフェース4";
            "ipaddress" = "";
            "netmask"   = "";
        };
    };

    "bonding" = @{ 
        1 = @{
            "interfaceList" = @(3,4);
            "ipaddress"     = "192.168.3.100";
            "netmask"       = "255.255.255.0";
        };
    };

    "routing" = @($routing1,$routing2);
}

$server.s002 = @{
    "network" = @{
        1 = @{
            "name"      = "インターフェース1";
            "ipaddress" = "192.168.1.101";
            "netmask"   = "255.255.255.0";
        };
        2 = @{
            "name"      = "インターフェース2";
            "ipaddress" = "192.168.2.101";
            "netmask"   = "255.255.255.0";
        };
        3 = @{
            "name"      = "インターフェース3";
            "ipaddress" = "";
            "netmask"   = "";
        };
        4 = @{
            "name"      = "インターフェース4";
            "ipaddress" = "";
            "netmask"   = "";
        };
    };

    "bonding" = @{ 
        1 = @{
            "interfaceList" = @(3,4);
            "ipaddress"     = "192.168.3.101";
            "netmask"       = "255.255.255.0";
        };
    };

    "routing" = $routing;
}
<#
#>

param(
    $servername
)

#
$s = $server.$servername

# Network Adapter設定
write-host("# ネットワークアダプター設定")
foreach($key in $s.network.keys) {
    $nic = $s.network.$key
    if($nic.ipaddress){
        write-host("ifIndex=[{0}],name=[{1}],ipaddress=[{2}],netmask=[{3}]" -f $key,$nic.name,$nic.ipaddress,$nic.netmask)
    }
}

# Bonding設定
write-host("# Bonding設定")
foreach($key in $s.bonding.keys){
    $bond = $s.bonding.$key
    if($bond.ipaddress){
        write-host("bondInterface=[{0}],ipaddress=[{1}],netmask=[{2}]" -f ($bond.interfaceList -join ","),$bond.ipaddress,$bond.netmask)
    }
}

# ルーティング設定
write-host("# Routhing設定")
if($routing){
        write-host("[{0}]" -f $routing)
}