prashant1987

I was participating in Powershell TechNet forum and someone asked question about how to add the ‘A’ Records and ‘PTR’ Records in DNS server . I thought it will be a good excercise for me , ( As I still have sleepless night when I think of Powershell :))

After working for long hours , I have built below script.

Note- One should have C:\DNS.CSV with columns as Hostname and IP address which needs to assinged. 

PowerShell Script

#Script to add DNS ‘A’ Records ‘PTR’ Records to DNS Servers
$dns = “DC” # Your DNS Server Name Goes here
$Zone = “AD.COM” # Your Forward Lookup Zone Name Goes here
$ReverseZone = “1.168.172.in-addr.arpa” # Your ReverseLookup Zone Name Goes Here
$a = import-csv C:\DNS.csv

#Preparing the C:\Reverse.csv from C:\DNS.CSV for Adding PTR Records
$b = $a | Select-Object -expand IP
$c = $b | %{$_.Split(“.”) | Select-Object -Index 3}
$d = $a | Select-Object -Expand Name
$e = $d | %{$_.Insert($_.length,”.ad.com”)}
for($i=0;$i -le ($e.Length);$i++)
{
(‘”{0}”,”{1}”‘ -f $c[$i],$e[$i]) | Out-File C:\Reverse.csv -Append -Encoding ascii
}

$header = “IP”,”Name”
$f = Import-Csv C:\Reverse.csv  -Header $header

#Adding ‘A’ Record to DNS Forward Lookup Zone
$a | %{dnscmd $dns /recordadd $Zone $($_.Name)A $($_.IP)}

#Adding ‘PTR’ Record to DNS Reverse Lookup Zone
$f | %{dnscmd $dns /recordadd $ReverseZone $($_.IP)PTR $($_.Name)}

Script will produce one more CSV File C:\Reverse.CSV which contains IP and FQDN Name Columns for PTR Record creation

Hope this script help AD Administrators 🙂

Regards,

_Prashant_

 

 

Advertisements

If you are a windows server administrator then , one or the other day you will be asked to get the UPTime report of list of windows servers (Most of the times your Boss will ask this :))

Below Script will help you to get the UPtime report of listed servers

Before you run the script ,

  • Create a text file servers.txt in C:\ Drive and list the servers against which you need to run this query (The Script will list out the UPtime report of listed server)

Description –

This script will make use of WMI Query (Class – win32_Operatingsystem) and get the lastboottime of listed server. Script will produce 2 TXT Files namely , UPtimeReport.txt and Offline.txt in your C:\ Drive

Note – If all the servers are online then offline.txt will not be created and Vice Versa . i.e if all the servers are offline then UPTimeReport.txt will not be created.

PowerShell Script

#Title – Script for querying windows server UPTime/Lastboot

#Description – This script queries windows servers listed in Servers.txt file (WMI Query) and get their last bootuptime

$servers = Get-Content C:\Servers.txt
foreach ($s in $servers)
{
try
{
$a=Get-WmiObject -ComputerName $s -Class Win32_OperatingSystem -ErrorAction ‘Stop’
$b = $a.convertToDateTime($a.Lastbootuptime)
[TimeSpan]$LastBoot = New-TimeSpan $b $(Get-Date)
(‘{0} {1}Day(s),{2}Hour(s),{3}Min(s),{4}Seconds’ -f $s,$LastBoot.Days,$lastboot.Hours,$LastBoot.Minutes,
$LastBoot.Seconds) | out-file C:\UptimeReport.txt -append -Encoding ascii
}
Catch
{
(‘{0} Server is notreachable’ -f $s)| Out-File C:\offline.txt -Append -Encoding ascii
}
}

I Hope this script will help , and it will make your BOSS Happy as well 🙂

Regards,

_Prashant_

To Much of Garbage , We need to Clean it up . This applies to your Active Directory As well.

This week , I was having some time to play around with PowerShell(Power) .

( I Always call it as power , Because It has a capacity to accomplish each and everything task in Windows :))

Since I have made up my mind to list out the servers which are not used anymore , I thought I will create a script for this.

Below is my script .

$a = Get-ADComputer -filter * -SearchBase “DN of the Domain” -properties` Operatingsystem
$list= @()
Foreach ($os in $a)

{
 If($os.Operatingsystem -match “windows server *”)
{
 $list += $os | Select-Object @{ L=’ComputerName’;E={$_.Name} }, @{L=’OperatingSystem’;E={$_.Operatingsystem}}
 
}


$list | Export-Csv -Path C:\file.csv -notype

$r = Import-Csv C:\file.csv | Select-Object -ExpandProperty Servername
foreach ($Server in $r)
{
 if(!(Test-Connection $Server -Quiet))
 {
 Write-Host “$server not reachable”
  }

  }

Note – One need to put DN of the domain Eg – “DC=AD,DC=COM” , In Place of “DN of the Domain”

The script will produce a Csv File C:\File.csv which contains List of windows server in specified domain.

&

The servers which are not reachable will be listed out in the Powershell Console.

I hope this information helps.

There will be some more Powershell Scripts which I will be building , Looks Like I am in Love with Powershell’s POWER

Regards,

_Prashant_

Ok , Now for me , Its time to learn PowerShell . So I started with it . Below is my First Script which will get me the IP Address information from list of servers which are specified in servers.txt file

Before running this script make sure you have stored the hostname of the servers in servers.txt and store it in C:\ Drive

Once the servers.txt is in place just run below powershell script.

Get-Wmiobject -Class win32_networkadapterconfiguration -Computername (Get-Content C:\servers.txt) | Select-Object -Property __server,IPEnabled,IPAddress | Where-Object {$_.IPEnabled -eq ‘true’} | Format-table @{l=’ServerName’;e={$_.__Server}},IPEnabled,IPAddress -autosize

Note – __server has two Underscores.

Hope this helps.

Cheers,

_Prashant_

Hello All, Prashant here again,

Since from few days I am getting my hands dirty with Microsoft update services. I am working in an environment where patching play’s very important and vital role . So , I built my lab to understand the process in depth and found some useful stuff which I want to share here.

Today , I will describe ,

  1.  Why WSUS over Microsoft Update site (Manual stuff )?
  2. Known Issues with WSUS 3.0 SP2 3.2.7600.226
  3. Can I download the updates from microsoft even my client systems are pointing to the internal WSUS server?

Question 1 : Why WSUS over Microsoft Update site (Manual stuff )?

Answer –  We all know WSUS is the central database software which distribute the updates which an administrator approves for all the server/client machines . WSUS Knocks down manual task of installing updates on all the computers ( I can not imagine , if I have 300 systems , I can not go to the systems one by one and check for updates manually every month) . Hence WSUS .

If any one what to know about this in deeper , I would suggest them to go through the below links ( Which even I did to understand the concepts)

http://technet.microsoft.com/en-us/windowsserver/bb332157.aspx

Above link has everything if you are looking to learn WSUS  ,Specially deployment guide and installation and operations guide.

Question 2.Known Issues with WSUS 3.0 SP2 3.2.7600.226?

One of the most encountered error with WSUS 3.2.7600.226 is 800B0001 . If you see this error code in your windowsupdate.log file then it is WUAgent Compatibility issue . The Reason behind this error code is WUAgent version , Basically If any one of your client (Where this error code is popping up) has this error then first you need to check its WUAgent Version ( How to check WUAgent Version is Here ) If the WUAgent version is 7.6.7600.256 (which is the latest ) then you need to download the agent to 7.4.76000.226.

WUAgent 7.6.7600.256 will not go well with the WSUS 3.0 SP2 3.2.7600.226 , This will cause the Agent to stop searching for updates from WSUS server . Below is the link which explains it better

http://msmvps.com/blogs/bradley/archive/2012/07/01/windows-update-error-800b0001.aspx

Downgrade procedure of WUAgent from 7.6.7600.256 to 7.4.76000.226

  • Download the WUAgent 7.4.76000.226 from here and store in it C:\Temp folder
  • Open command prompt and go to C:\Temp directroy
  • Run WindowsUpdateAgent30-<platform>.exe /quiet /norestart /wuforce . This is open up a dialog box and force the installation of WUAgent 7.4.7600.226
  • Again go to command prompt and run C:\wuauclt.exe /resetauthorization /detectnow . This is detect/reports the client to WSUS

Question 3 – Can I download the updates from microsoft even my client systems are pointing to the internal WSUS server?

Answer – Yes . You can download the udpates directly from microsoft , even if your client systems are pointing to the WSUS (Check Regsitry key on client system to know whether it is pointing to WSUS Server , Registry : HKLM/Software/Policies/Microsoft/Windows/WindowsUpdate/AU Key UseWUServer set to 1 it is using WSUS , if set to 0 then not using the WSUS).

One Can go to control panel , Automatic updates and click on install updates from “Windows Update Web Site”

Note – when you click on this , client system directly contacts and the windows update web site and  it will list out the appropriate updates . One can select the update and discard updates depending one the OS and the needs.

When you are carrying out this procedures you might see some error messages in windowupdate.log file , you can ignore them. Basically these are generated due to your client registry setting are made to contact your internal WSUS server for updates.

 

Hope this helps . This is what I have learnt in a month of my research 🙂 .

Thanks,

_Prashant_

Now I can say , I am a certified Master in Active Directory and Windows server 2008 Technology. It took around 2 months to achieve this. Finally I have got , What I wanted . I am Happy 🙂

Profile Link – http://www.experts-exchange.com/M_6413310.html

Cheers ,

_Prashant_

Windows Update Agent Shortly know as WUA , is responsible for generating the WSUS Client ID (Which is Unique).

 Recently I had to do a testing on one of our Client , which was having problem with reporting to WSUS. I thought of checking the WUA version on the client.

One method is to check the windows update manager log file , which I hate the most.

So, I though I will try to dig if there are some other method available for this. I got one from the internet.

Basically the WUA will be stored in c:\windows\system32 with the name wuaueng.dll file. Just we need to go to that location and right click on the wuaueng.dll file and need to go to the details. You will find the File version.

Hope this helps.

Thanks,

_Prashant_