Start-Transcript C:\ITDSCRIPT\Logs\GetIPs.txt -Append
#Add-PSSnapin VMware.VimAutomation.Core
Set-PowerCLIConfiguration -DefaultVIServerMode multiple -Scope Session -Confirm:$false

#Connect
Connect-VIServer itdvmvc1.nd.gov, itdvmvc2.nd.gov


##Windows


#Output File
$OutFileWin = "c:\inetpub\wwwroot\Win.txt"
$Date = Get-Date -UFormat "%Y%m%d%H%M%S"
Get-Item -Path $OutFileWin | Copy-Item -Destination "D:\Backup\Win\$Date-Win.txt"
Remove-Item $OutFileWin
Start-Sleep -Seconds 5


#Get Powered On VM's
$vmwin = get-VM | Where-Object { $_.PowerState -eq "PoweredOn" `
        -and ($_.GuestID -eq "windows7Guest" `
            -or $_.GuestID -eq "windows7_64Guest" `
            -or $_.GuestID -eq "windows7Server64Guest" `
            -or $_.GuestID -eq "windows8_64Guest" `
            -or $_.GuestID -eq "windows8Server64Guest" `
            -or $_.GuestID -eq "windows9Server64Guest" `
            -or $_.GuestID -eq "winLonghorn64Guest" `
            -or $_.GuestID -eq "winLonghornGuest" `
            -or $_.GuestID -eq "winNetStandardGuest" `
            -or $_.GuestID -eq "winNetEnterpriseGuest" `
            -or $_.GuestID -eq "windows9_64Guest") }
$vmviewwin = $vmwin | Get-View

$Outputwin = ""

#Loop through VM's, NIC's, and IP addresses.
Foreach ($v in $vmviewwin) {
    Foreach ($nic in $v.Guest.Net) {
        Foreach ($IP in $nic.IPAddress) {
            If ($IP -notlike "fe80*" -and $IP -notlike "192.168.*" -and $IP -notlike "172.16*") {
                    $OutputWin += $IP + "`n"
            }
        }
    }
}

#If ($Outputwin -ne "") {$OutputWin | Out-File $OutFileWin -Encoding utf8 -NoNewline}
If ($Outputwin -ne "") { $OutputWin | Out-File $OutFileWin -Encoding ASCII -NoNewline }



##Linux

#Output File
$OutFileLin = "c:\inetpub\wwwroot\Lin.txt"
$Date = Get-Date -UFormat "%Y%m%d%H%M%S"
Get-Item -Path $OutFileLin | Copy-Item -Destination "D:\Backup\Lin\$Date-Lin.txt"
Remove-Item $OutFileLin
Start-Sleep -Seconds 5

#Get Powered On VM's
$vmLin = get-VM | Where-Object { $_.PowerState -eq "PoweredOn" `
        -and ($_.GuestID -eq "centos6_64Guest" `
            -or $_.GuestID -eq "centos64Guest" `
            -or $_.GuestID -eq "centos7_64Guest" `
            -or $_.GuestID -eq "oracleLinux64Guest" `
            -or $_.GuestID -eq "oracleLinux7_64Guest" `
            -or $_.GuestID -eq "rhel4Guest" `
            -or $_.GuestID -eq "rhel5Guest" `
            -or $_.GuestID -eq "rhel5_64Guest" `
            -or $_.GuestID -eq "rhel6Guest" `
            -or $_.GuestID -eq "rhel6_64Guest" `
            -or $_.GuestID -eq "rhel7_64Guest" `
            -or $_.GuestID -eq "sles11_64Guest" `
            -or $_.GuestID -eq "sles12_64Guest" `
            -or $_.GuestID -eq "ubuntu64Guest") }
$vmviewlin = $vmLin | Get-View

$OutputLin = ""

#Loop through VM's, NIC's, and IP addresses.
Foreach ($v in $vmviewlin) {
    Foreach ($nic in $v.Guest.Net) {
        Foreach ($IP in $nic.IPAddress) {
            If ($IP -notlike "fe80*" -and $IP -notlike "192.168.*" -and $IP -notlike "172.16*") {
                    $OutputLin += $IP + "`n"
            }
        }
    }
}

#If ($OutputLin -ne "") {$OutputLin | Out-File $OutFileLin -Encoding utf8 -NoNewline}
If ($OutputLin -ne "") { $OutputLin | Out-File $OutFileLin -Encoding ASCII -NoNewline }


Stop-Transcript