update
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
Start-Transcript C:\itdscript\Logs\GetIPsAzureB.txt -Append
|
||||
$VerbosePerfrence = "Continue"
|
||||
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
$OutputPath = "C:\inetpub\wwwroot"
|
||||
|
||||
$WindowsIPs = ""
|
||||
$LinuxIPs = ""
|
||||
$OutFileWin = $OutputPath + "\AzureWin.txt"
|
||||
$OutFileLin = $OutputPath + "\AzureLin.txt"
|
||||
Remove-Item $OutFileWin
|
||||
Remove-Item $OutFileLin
|
||||
|
||||
|
||||
$username="svcitdazurescript@nd.gov"
|
||||
$usernameg="svcitdazurescript@ndstate.onmicrosoft.com"
|
||||
#Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File C:\Users\svcitdazurescript\AppData\Local\Microsoft\sac.bat
|
||||
$password=Get-Content C:\Users\svcitdazurescript\AppData\Local\Microsoft\sac.bat | ConvertTo-SecureString
|
||||
$passwordg=Get-Content C:\Users\svcitdazurescript\AppData\Local\Microsoft\sacg.bat | ConvertTo-SecureString
|
||||
$AdminCred=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$password
|
||||
$AdminCredg=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $usernameg,$passwordg
|
||||
|
||||
Login-AzureRMAccount -Credential $AdminCred -Environment AzureCloud -Verbose
|
||||
|
||||
$Subscriptions = Get-AzureRMSubscription | Where-Object {$_.Name -ne "sandbox"}
|
||||
foreach($subscription in $subscriptions)
|
||||
{
|
||||
Set-AzureRMContext -SubscriptionObject $subscription
|
||||
$WindowsVMs = Get-AzureRMVM | Where-Object {$_.StorageProfile.osdisk.ostype -match "Windows"}
|
||||
$LinuxVMs = Get-AzureRMVM | Where-Object {$_.StorageProfile.osdisk.ostype -match "Linux" -and $_.StorageProfile.ImageReference.Publisher -ne "infoblox" -and $_.StorageProfile.ImageReference.Publisher -ne "paloaltonetworks" -and $_.StorageProfile.ImageReference.Publisher -ne "juniper-networks"}
|
||||
$nics = Get-AzureRMNetworkInterface | Where-Object {$_.VirtualMachine -NE $null}
|
||||
|
||||
foreach($vm in $WindowsVMs)
|
||||
{
|
||||
$vmnicinterfaces = $vm.Networkprofile.NetworkInterfaces.id
|
||||
foreach($vmnicinterface in $vmnicinterfaces)
|
||||
{
|
||||
$nic = $nics | Where-Object {$_.Id -eq $vmnicinterface}
|
||||
$privateip = $nic.IpConfigurations | Select PrivateIPAddress
|
||||
|
||||
If($privateip.count -gt 1)
|
||||
{
|
||||
foreach($private in $privateip)
|
||||
{
|
||||
$WindowsIPs += $private.privateIPAddress + "`n"
|
||||
}
|
||||
}
|
||||
elseIf($privateip.privateIPAddress -ne $null)
|
||||
{
|
||||
$WindowsIPs += $privateip.privateIPAddress + "`n"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($vm in $LinuxVMs)
|
||||
{
|
||||
$vmnicinterfaces = $vm.Networkprofile.NetworkInterfaces.id
|
||||
foreach($vmnicinterface in $vmnicinterfaces)
|
||||
{
|
||||
$nic = $nics | Where-Object {$_.Id -eq $vmnicinterface}
|
||||
$privateip = $nic.IpConfigurations | Select PrivateIPAddress
|
||||
|
||||
If($privateip.count -gt 1)
|
||||
{
|
||||
foreach($private in $privateip)
|
||||
{
|
||||
$LinuxIPs += $private.privateIPAddress + "`n"
|
||||
}
|
||||
}
|
||||
elseif($privateip.privateIPAddress -ne $null)
|
||||
{
|
||||
$LinuxIps += $privateip.privateIPAddress + "`n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Login-AzureRMAccount -EnvironmentName AzureUSGovernment -Credential $AdminCredg
|
||||
|
||||
$Subscriptions = Get-AzureRMSubscription | Where-Object {$_.Name -ne "sandbox"}
|
||||
foreach($subscription in $subscriptions)
|
||||
{
|
||||
Set-AzureRMContext -SubscriptionObject $subscription
|
||||
$WindowsVMs = Get-AzureRMVM | Where-Object {$_.StorageProfile.osdisk.ostype -match "Windows"}
|
||||
$LinuxVMs = Get-AzureRMVM | Where-Object {$_.StorageProfile.osdisk.ostype -match "Linux" -and $_.StorageProfile.ImageReference.Publisher -ne "infoblox" -and $_.StorageProfile.ImageReference.Publisher -ne "paloaltonetworks" -and $_.StorageProfile.ImageReference.Publisher -ne "juniper-networks"}
|
||||
$nics = Get-AzureRMNetworkInterface | Where-Object {$_.VirtualMachine -NE $null}
|
||||
|
||||
foreach($vm in $WindowsVMs)
|
||||
{
|
||||
$vmnicinterfaces = $vm.Networkprofile.NetworkInterfaces.id
|
||||
foreach($vmnicinterface in $vmnicinterfaces)
|
||||
{
|
||||
$nic = $nics | Where-Object {$_.Id -eq $vmnicinterface}
|
||||
$privateip = $nic.IpConfigurations | Select PrivateIPAddress
|
||||
If($privateip.count -gt 1)
|
||||
{
|
||||
foreach($private in $privateip)
|
||||
{
|
||||
$WindowsIPs += $private.privateIPAddress + "`n"
|
||||
}
|
||||
}
|
||||
elseIf($privateip.privateIPAddress -ne $null)
|
||||
{
|
||||
$WindowsIPs += $privateip.privateIPAddress + "`n"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($vm in $LinuxVMs)
|
||||
{
|
||||
$vmnicinterfaces = $vm.Networkprofile.NetworkInterfaces.id
|
||||
foreach($vmnicinterface in $vmnicinterfaces)
|
||||
{
|
||||
$nic = $nics | Where-Object {$_.Id -eq $vmnicinterface}
|
||||
$privateip = $nic.IpConfigurations | Select PrivateIPAddress
|
||||
|
||||
If($privateip.count -gt 1)
|
||||
{
|
||||
foreach($private in $privateip)
|
||||
{
|
||||
$LinuxIPs += $private.privateIPAddress + "`n"
|
||||
}
|
||||
}
|
||||
elseif($privateip.privateIPAddress -ne $null)
|
||||
{
|
||||
$LinuxIps += $privateip.privateIPAddress + "`n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
If ($WindowsIPs -ne "" -and $WindowsIPs.Length -gt 150) {$WindowsIPs | Out-File $OutFileWin -Encoding ASCII -NoNewline -Force}
|
||||
If ($LinuxIPs -ne ""-and $LinuxIPs.Length -gt 150) {$LinuxIPs | Out-File $OutFileLin -Encoding ASCII -NoNewline -Force}
|
||||
Reference in New Issue
Block a user