Posts

Find the Vnet details of an Azure VM -Powershell

FInd the azure powershell script to get the VNET of an azure VM  Import-Module -Name Az  Login-AzAccount $vmname=Read-host "Enter the name of your VM"  $vmName=Get-AzVM -Name $vmname $VM = Get-azVM -ResourceGroupName $vmName.ResourceGroupName -Name $VMName.name  $VMNicName = $vmname.NetworkProfile.NetworkInterfaces.Id.Split("/")[-1]  $VMNic=Get-AzNetworkInterface -ResourceGroupName $RG -name $VMNicName  $VMvNetName = $VMNic.IpConfigurations.Subnet.Id.Split("/")[8]  $vNet = Get-AzVirtualNetwork  -ResourceGroupName $RG -Name $VMvNetName Write-host "Vnet of the VM is : " $vNet.Name  

Convert Dynamic IP to static IP in a Windows computer or server

Make sure the Powershell should be opened with  elevated privilege  $Domain =  read-host "Enter the domain name for the DNS Suffix " #Collect Network Configuration variables $IfName = (Get-NetIPInterface -AddressFamily IPv4 -Dhcp Enabled).InterfaceAlias $IfIndex = (Get-NetIPInterface -AddressFamily IPv4 -Dhcp Enabled).ifIndex $IP = (Get-NetIPConfiguration -InterfaceIndex $IfIndex | Select-Object -ExpandProperty IPv4Address).IPv4Address Start-Sleep -Seconds 20 Write-host "IP Address set as: $IP." $Gateway = (Get-NetIPConfiguration -InterfaceIndex $IfIndex | Select-Object -ExpandProperty IPv4DefaultGateway).NextHop Write-host "Gateway set as: $Gateway." $PrefixLength = Get-NetIPAddress -InterfaceIndex $IfIndex | Select-Object -ExpandProperty PrefixLength $DNSServers = @() $DNS = @() $DNS = Get-DnsClientServerAddress -InterfaceIndex $IfIndex | Select-Object -ExpandProperty ServerAddresses foreach($item in $DNS) {     $DNSServers += $item } Write-host  "S

Login into Azure using Powershell

Import-Module -Name Az Login-AzAccount  # This will prompt for the username and password get-azsubscription $getallSubscriptions = Get-AzSubscription $getallSubscriptions  will have the complete list of subscriptions 

Export Azure VM details to CSV with Tags

Import-Module -Name Az Login-AzAccount get-azsubscription $getallSubscriptions = Get-AzSubscription foreach($subscription in $getallSubscriptions) { Select-AzSubscription $subscription $vms = Get-AzVM foreach($vm in $vms) { { $TagOut =$nulll foreach($tag in $vm.tags.keys) { $Tagz=$tag+ ":" + $vm.tags.$tag+ "," $TagOut=$TagOut+$Tagz }    $value = $($subscription.Id) + "," + $($rg.ResourceGroupName)  + "," + $vm.Name + ","  + "," +$vm.Id   + "," +  $TagOut  Add-content -path "C:\azure-Vm.txt" -value $value $TagOut will have the complete tags with comma separated you can rename the output file to csv and make use of it 

Powershell commands for DNS Management

Get DNS Record  Remove All Root Hints   Get-DnsServerResourceRecord -ZoneName "..roothints" | Remove-DnsServerResourceRecord -Force -ZoneName "..roothints" Remove A Record  Remove-DnsServerResourceRecord -ZoneName "MyZone" -RRType "A" -Name "Host01" -RecordData "10.10.3.11" Search C-Name  Get-DnsServerResourceRecord -RRType CName -ZoneName "contoso.com" | ? {$_.RecordData.HostNameAlias -eq "hostname.contoso.com." -and $_.HostName -eq "web1.yourdomain.com" Add C-Name Add-DnsServerResourceRecordCName -ComputerName DNSSrvr01 -ZoneName 'Myzone' -Name MyHostname -HostNameAlias MyHostnameAlias Remove C-Name  Remove-DnsServerResourceRecord    -ZoneName ' M yzone.com ' -ComputerName  D nSSrvr001  -RRType CName -Name " M yCname"  -Force Where  MyZone is the zone name ComputerName is the DNS Server to which you want to connect. Ignore this switch if yo