bloodyrulz
Goto Top

Powershell Hinzufügen von alternativen IP Adressen zu einem Netzwerkadapter funktioniert im ISE per Skript nicht

Hallo,

ich hoffe Ihr könnt mir helfen, ich bin am verzweifeln.

Das Skript welches folgende Aufgabeben durchführen soll:
- "Ethernet0" -> Rename -> Zu "FLAN" -> Funktioniert auch
- Hinzufügen einer Primären IP Adresse -> Funktioniert auch

- Hinzufügen mehrerer Alternativ IP Adressen -> Funktioniert NICHT !!!!!!

Auch die Fehlermeldung (Zeilenangaben etc.) bringen mich nicht weiter, da es ja im ISE funktioniert.

Fehlermeldung:
New-NetIPAddress : A positional parameter cannot be found that accepts argument 'â€PrefixLength 24 â€SkipAsSource'.  
At D:\_ScriptePS\K8-NIC_IP_config_rename.ps1:20 char:67
+                                                $configLAN8_FLAN | New-NetIPAddre ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [New-NetIPAddress], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,New-NetIPAddress

New-NetIPAddress : A positional parameter cannot be found that accepts argument '24'.  
At :\_ScriptePS\K8-NIC_IP_config_rename.ps1:21 char:67
+                                                $configLAN8_FLAN | New-NetIPAddre ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [New-NetIPAddress], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,New-NetIPAddress

Wenn ich das Script im ISE rein kopieren und es laufen lasse, funktioniert alles wunderbar. Nur als *.ps1 nicht.
Kann mir wer sagen was ich machen muss das es auch mit Skriptaufruf funktioniert.
Ich hab schon mehrere Versionen der
" $configLAN8_FLAN | New-NetIPAddress -IPAddress "192.168.187.12" –PrefixLength 24 –SkipAsSource $True"
versucht.

Kurzum er fügt mir die alternativen IP Adresen im LAN Adapter "FLAN" nicht hinzu.
Ich bin blutiger Powershell Anfänger und hoffe daher auf eure Hilfe.

K8-NIC_IP_config_rename.ps1:
Write-Host -ForegroundColor Cyan  "LAN NIC Konfiguration"  
Add-Type -AssemblyName System.Windows.Forms
 
$oReturn=[System.Windows.Forms.MessageBox]::Show("Starten? "," Netzwerkadapter Rename und IP Konfiguration",[System.Windows.Forms.MessageBoxButtons]::OKCancel)        
switch ($oReturn)
{
    "OK" {  
           # Rename-NetAdapter
           Rename-NetAdapter -Name "Ethernet0"                          -NewName LAN  
           Start-Sleep -Seconds 10
           
           # Configuration zwischenspeichern
           $configLAN8_LAN =                    Get-NetAdapter "LAN"                             | Get-NetIPConfiguration  
 
           # ****** Konfiguration start *********

           # --------- Konfiguration Ethernet8  / FLAN  Server1 ---------------
           $configLAN8_FLAN | New-NetIPAddress -IPAddress "192.16.182.2" -DefaultGateway "192.16.182.1" -PrefixLength 24  
           Start-Sleep -Seconds 5
           $configLAN8_LAN | New-NetIPAddress -IPAddress "192.16.182.14" –PrefixLength 24 –SkipAsSource $True  
           $configLAN8_LAN | New-NetIPAddress –IPAddress "192.16.182.15" –PrefixLength 24 –SkipAsSource $True  
           $configLAN8_LAN | New-NetIPAddress -IPAddress "192.16.182.17" –PrefixLength 24 –SkipAsSource $True  
           $configLAN8_LAN | New-NetIPAddress –IPAddress "192.16.182.20" –PrefixLength 24 –SkipAsSource $True  
 
           # **** Bestimmte Netzwerkbindings deaktivieren ****
           Start-Sleep -Seconds 5
           # Antwort auf Verbindungsschicht-Topologieerkennung
           Disable-NetAdapterBinding -InterfaceAlias "*" -ComponentID ms_rspndr  
           # E/A-Treiber für Verbindungsschicht-Topologieerk
           Disable-NetAdapterBinding -InterfaceAlias "*" -ComponentID ms_lltdio  
           # Microsoft-Multiplexorprotokoll für Netzwerkadapter
           Disable-NetAdapterBinding -InterfaceAlias "*" -ComponentID ms_implat  
           # Client für Microsoft-Netzwerke
           Disable-NetAdapterBinding -InterfaceAlias "*" -ComponentID ms_msclient  
           # QoS-Paketplaner
           Disable-NetAdapterBinding -InterfaceAlias "*" -ComponentID ms_pacer  
           # Datei- und Druckerfreigabe für Microsoft-Netzwerke
           Disable-NetAdapterBinding -InterfaceAlias "*" -ComponentID ms_server  
           # Internetprotokoll Version 6 (TCP/IPv6)
           Disable-NetAdapterBinding -InterfaceAlias "*" -ComponentID ms_tcpip6  
           ncpa.cpl
    } 
    "Cancel" {  
        [System.Windows.Forms.MessageBox]::Show("IP Konfiguration und Rename auf dem Server wurde ABGEBROCHEN, bitte pruefen","Abbruch - Interface Rename und IP Konfiguration",0)  
                               ncpa.cpl
    } 
}
Write-Host -NoNewLine 'Press any key to continue...';  
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');  


Vielen Dank für eure Hilfe

Danke
Gruß
Andreas

Content-Key: 508525

Url: https://administrator.de/contentid/508525

Printed on: April 25, 2024 at 10:04 o'clock

Mitglied: 141575
Solution 141575 Oct 25, 2019 updated at 13:26:35 (UTC)
Goto Top
Auch die Fehlermeldung (Zeilenangaben etc.) bringen mich nicht weiter, da es ja im ISE funktioniert.
Eigentlich schon, siehe:
â€PrefixLength 24 â€SkipAsSource'.
Tipp: Gedankenstrich statt Bindestrich für Parameternamen genutzt. Das kommt vom zu viel Copy n Paste aus dem Web face-wink.

Typischer Freitag also ...