Skip to main content

Powershell: SkipAsSource Flag

Finally ran into an issue where the removal of the primary ip address after Server 2003 caused an issue. Since if you have a multihomed nic the routing table will be set to use the closest IP address to the gateway as the source interface. Here is a fix from  James Kehr to run on your server to set an ip address to be the "Primary" ie Source. I did edit his script by putting a menu and removing the need to put a interface alias. This should only work with 2012 and above with powershell 3.0 and above. For other OS check the heyscriptingguy link.

http://blogs.technet.com/b/heyscriptingguy/archive/2013/01/24/use-powershell-to-change-ip-behavior-with-skipassource.aspx
KB969029

Thank you James Kehr
# set some constants
clear
Import-Module NetTCPIP

Get-NetIPAddress | Where {$_.PrefixOrigin -eq "Manual"} | select IPaddress,InterfaceAlias,SkipasSource | format-table

$primaryIP = Read-Host "Which ip address should be set as primary?"
$Alias = Get-NetIPAddress $primaryIP -EA stop | select -expand InterfaceAlias

Write-Host "Setting $Alias primary IP to $primaryIP"

# get all the IP addresses on the interface, filtered by IPv4 and excluding

# the $primaryIP

[array]$IPs = Get-NetIPAddress -InterfaceAlias $Alias | Where-Object {$_.AddressFamily -eq "IPv4" -and $_.IPAddress -ne $primaryIP}

 

# set primary IP SkipAsSource to false

Set-NetIPAddress -IPAddress $primaryIP -InterfaceAlias $Alias -SkipAsSource $false

 

# set other IP addresses with SkipAsSource equal to true

Set-NetIPAddress -IPAddress $IPs.IPAddress -InterfaceAlias $Alias -SkipAsSource $true
Write-Host "Please review the output False under SkipasSource means the ip can be a source"
Get-NetIPAddress | Where {$_.PrefixOrigin -eq "Manual"} | select IPaddress,InterfaceAlias,SkipasSource | format-table

Comments

Popular posts from this blog

Excel document for pinging list of computers VBA

Here is an excel document I created that will ping a list of nodes in column A and give results in column B. There are much better tools that can be used such as angry ip scanner  http://www.angryip.org/w/Home . I just wrote this as an example Requirements: Tested with Office 2010 Download: Download

Powershell - Com+ Application Recycle

Needed a script to recycle a com+ application nightly and this is what i came up with. This script will write each recycle it does to the event log under application. Run locally or via a scheduled task. #Recycle COM+ Application and write to the event log the status # 1.0 Release # Run script locally # Write to the event log ######################################## #Configurable ######################################## #Com+ ApplicationName $ComPlusLikeAppName = "Put the name of Com+ Application here a like statement is used to eval so you can get away with putting part of it" #EventLog to write to. $eventlog = "Application" #Source for eventlog. $source = "RecycleComObject" #Successful Event ID $SEventID = 0 #Error Event ID $EEventID = 666 #Process that COM+ runs under $process = "dllhost.exe". ######################################## #Clear $CurrentMemory = $null $PRocessID = $null $Commandline = $null $GUID = $null $AppID = $null $Messag

Powershell : Certutil Find Expired Certs on CA server

Wrote this to get certificate expiration information for certificates that expired 5 days ago to ones that expire in 90 days. Wrap an invoke-command around this for remote query. $Before = (get-date).adddays(90).ToString("MM/dd/yyyy") $After = (get-date).AddDays(-5).ToString("MM/dd/yyyy") <# https://blogs.technet.microsoft.com/poshchap/2016/01/01/powershell-and-certutil-exe/ We create a date range with $Before, i.e. certificates expiring before this date, and $After, i.e. certificates expiring after this date. These values are converted into something that certutil can understand - $Restrict. This is then used with the certutil -restrict parameter. #> $Restrict = "NotAfter<=$Before,NotAfter>=$After" $Report = @() $cmd = & certutil.exe -view -restrict $Restrict -out "RequesterName,CommonName,Certificate Expiration Date","Certificate Template" $SplitLines = $cmd.Split("`n`r") $Index = 0 foreach ($line in $Sp