TechnoGist

gist (jst)# The central idea; the essence…

Archive for the ‘Windows 2003’ tag

Getting Remote Registry WSUS Config

without comments

Using PowerShell to examine the registry is a simple process but to really get the power from PowerShell you need the data in an object.
Once in the object it is far easier to manipulate the data in a fashion that you are used to in the PowerShell command line.

I used the below PowerShell script to verify the “Automatic Update” configuration on a Windows 2003 Sp2 Server. The servers being analyzed are stored in a .txt file on the C:\ partition.
The path of the input list file is stored in the $File string. This method of using a custom object can be very usefull for non-object based data.

Code:

$WSUSREGALL = @()
[String]$File = "C:\server.txt"
$Servers = Get-Content $File
ForEach($Server In $Servers)
{
$Registry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Server)
$RegKey0 = $Registry.OpenSubKey("Software\policies\Microsoft\Windows\WindowsUpdate\" )
$RegKey1 = $Registry.OpenSubKey("Software\policies\Microsoft\Windows\WindowsUpdate\AU\")
 
$WSUSREG = New-Object System.Object
$WSUSREG | Add-Member -MemberType NoteProperty -Name "Server" -Value $Server
$WSUSREG | Add-Member -MemberType NoteProperty -Name WUServer -Value $RegKey0.GetValue("WUServer")
$WSUSREG | Add-Member -MemberType NoteProperty -Name WUStatusServer -Value $RegKey0.GetValue("WUStatusServer")
$WSUSREG | Add-Member -MemberType NoteProperty -Name TargetGroupEnabled -Value $RegKey0.GetValue("TargetGroupEnabled")
$WSUSREG | Add-Member -MemberType NoteProperty -Name AcceptTrustedPublisherCerts -Value $RegKey0.GetValue("AcceptTrustedPublisherCerts")
$WSUSREG | Add-Member -MemberType NoteProperty -Name AUOptions -Value $RegKey1.GetValue("AUOptions")
$WSUSREG | Add-Member -MemberType NoteProperty -Name NoAutoUpdate -Value $RegKey1.GetValue("NoAutoUpdate")
$WSUSREG | Add-Member -MemberType NoteProperty -Name NoAUShutdownOption -Value $RegKey1.GetValue("NoAUShutdownOption")
$WSUSREG | Add-Member -MemberType NoteProperty -Name NoAUAsDefaultShutdownOption -Value $RegKey1.GetValue("NoAUAsDefaultShutdownOption")
$WSUSREG | Add-Member -MemberType NoteProperty -Name ScheduledInstallDay -Value $RegKey1.GetValue("ScheduledInstallDay")
$WSUSREG | Add-Member -MemberType NoteProperty -Name ScheduledInstallTime -Value $RegKey1.GetValue("ScheduledInstallTime")
$WSUSREG | Add-Member -MemberType NoteProperty -Name UseWUServer -Value $RegKey1.GetValue("UseWUServer")
$WSUSREG | Add-Member -MemberType NoteProperty -Name RescheduleWaitTimeEnabled -Value $RegKey1.GetValue("RescheduleWaitTimeEnabled")
$WSUSREG | Add-Member -MemberType NoteProperty -Name RescheduleWaitTime -Value $RegKey1.GetValue("RescheduleWaitTime")
$WSUSREG | Add-Member -MemberType NoteProperty -Name NoAutoRebootWithLoggedOnUsers -Value $RegKey1.GetValue("NoAutoRebootWithLoggedOnUsers")
$WSUSREG | Add-Member -MemberType NoteProperty -Name DetectionFrequencyEnabled -Value $RegKey1.GetValue("DetectionFrequencyEnabled")
$WSUSREG | Add-Member -MemberType NoteProperty -Name DetectionFrequency -Value $RegKey1.GetValue("DetectionFrequency")
$WSUSREG | Add-Member -MemberType NoteProperty -Name AutoInstallMinorUpdates -Value $RegKey1.GetValue("AutoInstallMinorUpdates")
$WSUSREG | Add-Member -MemberType NoteProperty -Name RebootWarningTimeoutEnabled -Value $RegKey1.GetValue("RebootWarningTimeoutEnabled")
$WSUSREG | Add-Member -MemberType NoteProperty -Name RebootWarningTimeout -Value $RegKey1.GetValue("RebootWarningTimeout")
$WSUSREG | Add-Member -MemberType NoteProperty -Name RebootRelaunchTimeoutEnabled -Value $RegKey1.GetValue("RebootRelaunchTimeoutEnabled")
$WSUSREG | Add-Member -MemberType NoteProperty -Name RebootRelaunchTimeout -Value $RegKey1.GetValue("RebootRelaunchTimeout")
$WSUSREG | Add-Member -MemberType NoteProperty -Name IncludeRecommendedUpdates -Value $RegKey1.GetValue("IncludeRecommendedUpdates")
$WSUSREG | Add-Member -MemberType NoteProperty -Name AUPowerManagement -Value $RegKey1.GetValue("AUPowerManagement")
$WSUSREGALL += $WSUSREG
}
$WSUSREGALL
$WSUSREGALL | Export-Csv "C:\DataWSUS.csv" -NoTypeInformation

Hope this helps.

All information is provided on an AS-IS basis, with no warranties and confers no rights.

Written by Paul Brice

September 25th, 2009 at 10:46 am

Exporting Data to Excel using PowerShell

without comments

I had to get a quick audit of systems and i needed to know OS Version, SP version, Memory and Disk Details.

One problem is that if you don’t know what disks you have exporting this to excel is difficult. I chose to dynamically create the headers for the excel file based on the drive letter names. This approach is by no means perfect as you rely on the fact that people have built the systems with sequential drive letters. Any drive letter out of sequence will disturb the excel header names.

Example: If you have 3 servers and two have letters C: and D: and the third has C: and E: this approach will not work for you. Luckily I know my servers have sequential drive letters.

Code:

$excel = New-Object -comobject Excel.Application
$excel.visible = $True
$wbook = $excel.Workbooks.Add()
$wsheet = $wbook.Worksheets.Item(1)
$wsheet.Cells.Item(1,1) = "Date"
$wsheet.Cells.Item(1,2) = "Server"
$wsheet.Cells.Item(1,3) = "Memory"
$wsheet.Cells.Item(1,4) = "OSName"
$wsheet.Cells.Item(1,5) = "SPVersion"
$iRow = 2
$InputFile = "C:\Server.txt" #Input File Containing Servers to be Scanned
$Servers = Get-Content $InputFile
ForEach($Server in $Servers) { $wsheet.Cells.Item($iRow,1) = Get-Date
$wsheet.Cells.Item($iRow,2) =$Server
$AllCS = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $Server | Select-Object TotalPhysicalMemory
ForEach($CS In $AllCS){$wsheet.Cells.Item($iRow,3) = $CS.TotalPhysicalMemory/1GB}
$AllOS = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Server
ForEach($OS In $AllOS){$OSVersion = $OS.Caption;$SPVersion = $OS.CSDVersion}
$wsheet.Cells.Item($iRow,4) = $OSVersion
$wsheet.Cells.Item($iRow,5) = $SPVersion
$logicalDisk = Get-WmiObject -Class Win32_LogicalDisk -ComputerName $Server -Filter "DriveType=3" | Select-Object Caption,Size
$j = 6
For($i=0;$i -le $LogicalDisk.Length - 1; $i++){ $wsheet.Cells.Item(1,$j) = $LogicalDisk[$i].Caption
$wsheet.Cells.Item($iRow,$j) = $LogicalDisk[$i].Size/1GB $j++} $iRow++ }
$range = $wsheet.UsedRange
$range.Interior.ColorIndex = 19
$range.Font.ColorIndex = 11
$range.Font.Bold = $True
$range.EntireColumn.AutoFilter()
$range.EntireColumn.AutoFit()
$excel.ActiveWorkbook.SaveAs("C:\Server_Data.xls")
$excel.ActiveWorkbook.Close
$excel.Application.Quit
If (ps excel) { kill -name excel}

Hope this helps.

All information is provided on an AS-IS basis, with no warranties and confers no rights.

Written by Paul Brice

August 20th, 2009 at 2:48 pm

Exporting Server Network Configuration to Excel using PowerShell

without comments

Win32_NetworkAdapterConfiguration
Win32_NetworkAdapter

Recently I had to examine over 100+ servers and their network configurations prior to a network IP address change. I also wanted the output in an Excel file for easy transport to my group. I used the above two WMI classes to gather all the required data i needed, the script requires the Excel application installed on the machine to have access to the excel.application COM object. I used an .TXT file as the input for the script, the file contains the servers that I wanted to scan. The file is formatted with one server name per line with no spaces.

All information is provided on an AS-IS basis, with no warranties and confers no rights.

Written by Paul Brice

March 8th, 2009 at 9:22 pm