Powershell Examples

From Help
Jump to: navigation, search

These are scripts I have written to do various tasks. They can be used, modified, etc as your company sees a need.


Return to Main Page

Prerequisites

  • PowerShell 5 or higher

Return to Top

Coding notes

  • for clarity and documentation, make sure to have #comments for various segments

Return to Top

Snippets or Quick Useful Commands

PCs inside specific OU

  • Tabled list (Name, LastLoginDate)

-change inside the -Searchbase for your OU

Get-ADComputer -Filter * -Searchbase "OU=Servers,DC=tpfnd,DC=cat" -Properties *| FT Name, LastLogonDate -Autosize
  • sort on LastLogonDate
Get-ADComputer -Filter * -Searchbase "OU=Servers,DC=tpfnd,DC=cat" -Properties *| Sort LastLogonDate | FT Name, LastLogonDate -Autosize

Users not logged in 30 days

Get-ADUser -Filter * -SearchBase "CN=Users,DC=tpfnd,DC=cat" -Properties Name,SamAccountName,LastLogonDate | Where {($_.LastLogonDate -lt (Get-Date).AddDays(-30)) -and ($_.LastLogonDate -ne $NULL)} | Sort LastLogonDate | Select Name,SamAccountName,LastLogonDate
  • change inside the -Searchbase for your OU
  • change number in .AddDays to make period longer (60, 90, etc)

Get make / model of PC

Gwmi Win32_Computersystem | Format-List Name, manufacturer, model
  • other PC*
Gwmi Win32_Computersystem -computer "OTHER_PC_NAME" | Format-List Name, manufacturer, model

Combinations

All servers make and model

$ou = "OU=Servers,DC=tpfnd,DC=cat"

$serverlist = Get-ADComputer -filter * -Searchbase $ou -Properties * | Select Name

foreach ($x in $serverlist) {
	$server = $x.Name
	$mm = gwmi Win32_Computersystem -computer $server | Select manufacturer, model
	$manufacturer = $mm.manufacturer
	$model = $mm.model
	write-host "$server `n Manufacturer: $manufacturer `n Model: $model `n"
	}

Return to Top

Includes

To simplyfy information that multiple scripts use, the idea of "includes" is crucial. This will insert the code from another file into your scripts. They are use via a . "filepath" as such:

. "C:\PS\includes\rootvaribles.ps1"
. "C:\PS\includes\scope.ps1"

Here is my rootvaribles:

#define root varibles

#file and directory scructures
	#Root location of scripts
		$FileRoot = "C:\PS\"
	#sub-directory for output files from scripts
		$FileRootOutput = "OUTPUT\"
	#defining short-name file path
		$FRO = $FileRoot + $FileRootOutput

#output formatting varibles
	#newline
		$nl = "`r`n"
	#tab
		$tab = "`t"
	#sub-section break
		$subbreak = $nl + "+--------------+" + $nl + $nl
	#full section break
		$DIVIDE = $nl + " + -------------------------------------------------------- + " + $nl

#command alias settings
	Set-Alias wh write-host

This is a function to return a three-octet DNS scope:

#function to get DNS scope

#grab the DNS server IP
	$DNSIP = Get-DnsServerSetting | select -ExpandProperty AllIPAddress

#set up regex match for join
	$DNSIP -match "\b([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\b"

#join into a 3 octect scope
	$Scope = ($matches[1..3] -join ".")

Return to Top

staticlist.ps1

This script will create three text files, pulling info out of Active Directory:

  • statics.txt: list of FQDN and IP of each static IP machine
  • staticlist.txt: list of FQDN only of each static IP machine
  • staticlist.cvs: text file of FQDN,IP, and OS using : as the delimiter

statics.txt output examples

hpV.tpfnd.cat 10.0.0.76
4U.tpfnd.cat 10.0.0.52
4U.tpfnd.cat 10.0.0.55
WSUS.tpfnd.cat 10.0.0.80
hpv2.tpfnd.cat 10.0.0.77
DC-02.tpfnd.cat 10.0.0.58
APP-01.tpfnd.cat 10.0.0.61

Return to Top

staticlist.txt output examples

REALM.tpfnd.cat
hpV.tpfnd.cat
4U.tpfnd.cat
4U.tpfnd.cat
WSUS.tpfnd.cat
hpv2.tpfnd.cat
DC-02.tpfnd.cat
APP-01.tpfnd.cat

Return to Top

staticlist.cvs output examples

REALM.tpfnd.cat:10.0.0.59:Microsoft Windows Server 2012 R2 Standard
hpV.tpfnd.cat:10.0.0.76:Microsoft Windows Server 2012 R2 Standard
4U.tpfnd.cat:10.0.0.52:Microsoft Windows Server 2012 R2 Standard
4U.tpfnd.cat:10.0.0.55:Microsoft Windows Server 2012 R2 Standard
WSUS.tpfnd.cat:10.0.0.80:Microsoft Windows Server 2012 R2 Standard
hpv2.tpfnd.cat:10.0.0.77:Microsoft Windows Server 2012 R2 Standard
DC-02.tpfnd.cat:10.0.0.58:Microsoft Windows Server 2012 R2 Standard
APP-01.tpfnd.cat:10.0.0.61:Microsoft Windows Server 2016 Standard

Return to Top

The code

#define root varibles
#NOTE: change the path below (and in the included ps1 file) if you install this someplace else
. "C:\PS\includes\rootvaribles.ps1"
. "C:\PS\includes\scope.ps1"

#define output files
#output file for FQDN and IP
	$FROS = $FRO + "statics.txt"
#output file for FQDN only list
	$FROSL = $FRO + "staticlist.txt"
#output file for FQDN:IP:OS
	$FROCVS =  $FRO + "staticlist.cvs"

#Clean up old files if they exist
$FileExists = Test-Path $FROS
	If ($FileExists -eq $True) {Remove-Item –path $FROS}
$FileExists = Test-Path $FROSL
	If ($FileExists -eq $True) {Remove-Item –path $FROSL}
$FileExists = Test-Path $FROCVS
	If ($FileExists -eq $True) {Remove-Item –path $FROCVS}

param ( 
[string]$LDAPFilter = '(name=*)'
)
$wmiQuery = "select IPAddress, DefaultIPGateway from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE and DHCPEnabled=FALSE"

$computers = (Get-ADComputer -LDAPFilter $LDAPFilter)
foreach ($computer in $computers) 
	{ 
    $networkAdapters = (gwmi -ErrorAction SilentlyContinue -ComputerName $computer.DNSHostName -Query $wmiQuery) 
    foreach ($networkAdapter in $networkAdapters) 
		{ 
        foreach ($ip in $networkAdapter.IPAddress) 
			{ 
            if ($ip -match $Scope) 
				{  
				$computerOS = Get-CimInstance CIM_OperatingSystem -computer $computer.DNSHostName
				$os = $computerOS.caption
				$staticlist = $($computer.DNSHostName)
				$a = $($computer.DNSHostName) + " " + $ip
				$cv = $($computer.DNSHostName) + ":" + $ip + ":" + $os
				out-file $FROS -inputobject $a -encoding ASCII -Append
				out-file $FROSL -inputobject $staticlist -encoding ASCII -Append
				out-file $FROCVS -inputobject $cv -encoding ASCII -Append
				} 
			}
		} 
	}

Return to Top

ITIL.ps1

This script will make an inventory list per server, using the previous (staticlist.ps1) text files as it's source of machines.

ITIL.ps1 output


 + -------------------------------------------------------- + 
Operating System:

	Operating Systyem: Microsoft Windows Server 2012 R2 Standard
	Architecture: 64-bit
	Version: 6.3.9600
	Build Number: 9600
	Install Date: 07/13/2014 11:37:39

 + -------------------------------------------------------- + 
Motherboard:

	Vendor: Gigabyte Technology Co., Ltd.
	Product number: Z77-D3H
	Serial Number: To be filled by O.E.M.
	Primary Bus Type: PCI
	Secondary Bus Type: ISA

 + -------------------------------------------------------- + 
Processor:

	Type: Intel64 Family 6 Model 42 Stepping 7
	Manufacturer: GenuineIntel
	MaxClockSpeed: 3000
	Retail Name: Intel(R) Pentium(R) CPU G860 @ 3.00GHz
	SocketDesignation: Intel(R) Pentium(R) CPU G860 @ 3.00GHz


 + -------------------------------------------------------- + 
RAM:

	Usable Physical Memory: 9.89 GB
	Total memory modules: 4

 + -------------------------------------------------------- + 
Memory Modules:


+--------------+

	Bank Label: 
	Capacity: 4294967296
	Device Locator: XMM1
	Part Number:  
	Speed: 1333
	Data Width: 64
	Form Factor: 8


+--------------+

	Bank Label: 
	Capacity: 4294967296
	Device Locator: XMM2
	Part Number:  
	Speed: 1333
	Data Width: 64
	Form Factor: 8


+--------------+

	Bank Label: 
	Capacity: 4294967296
	Device Locator: XMM3
	Part Number: KP382H-HYC
	Speed: 1333
	Data Width: 64
	Form Factor: 8


+--------------+

	Bank Label: 
	Capacity: 4294967296
	Device Locator: XMM4
	Part Number: KP382H-HYC
	Speed: 1333
	Data Width: 64
	Form Factor: 8


+--------------+

	Bank Label: 
	Capacity: 1048576
	Device Locator: SYSTEM ROM
	Part Number: 
	Speed: 
	Data Width: 2
	Form Factor: 0


+--------------+

	Bank Label: 
	Capacity: 2147483648
	Device Locator: XMM3
	Part Number: 16JTF25664AZ-1G4G
	Speed: 1333
	Data Width: 64
	Form Factor: 8


+--------------+

	Bank Label: 
	Capacity: 2147483648
	Device Locator: XMM4
	Part Number: 16JTF25664AZ-1G4G
	Speed: 1333
	Data Width: 64
	Form Factor: 8


+--------------+

	Bank Label: 
	Capacity: 1048576
	Device Locator: SYSTEM ROM
	Part Number: 
	Speed: 
	Data Width: 2
	Form Factor: 0


+--------------+

	Bank Label: 
	Capacity: 4294967296
	Device Locator: XMM3
	Part Number: Team-Elite-1333
	Speed: 1333
	Data Width: 64
	Form Factor: 8


+--------------+

	Bank Label: 
	Capacity: 4294967296
	Device Locator: XMM4
	Part Number: Team-Elite-1333
	Speed: 1333
	Data Width: 64
	Form Factor: 8


+--------------+

	Bank Label: 
	Capacity: 1048576
	Device Locator: SYSTEM ROM
	Part Number: 
	Speed: 
	Data Width: 2
	Form Factor: 0


+--------------+

	Bank Label: BANK 0
	Capacity: 1073741824
	Device Locator: ChannelA-DIMM0
	Part Number: SUPERTALENT
	Speed: 1333
	Data Width: 64
	Form Factor: 8


+--------------+

	Bank Label: BANK 1
	Capacity: 1073741824
	Device Locator: ChannelA-DIMM1
	Part Number: SUPERTALENT
	Speed: 1333
	Data Width: 64
	Form Factor: 8


+--------------+

	Bank Label: BANK 2
	Capacity: 4294967296
	Device Locator: ChannelB-DIMM0
	Part Number: F3-10666CL7-4GBRH
	Speed: 1333
	Data Width: 64
	Form Factor: 8


+--------------+

	Bank Label: BANK 3
	Capacity: 4294967296
	Device Locator: ChannelB-DIMM1
	Part Number: F3-10666CL7-4GBRH
	Speed: 1333
	Data Width: 64
	Form Factor: 8



 + -------------------------------------------------------- + 
BIOS:

	Manufacturer: American Megatrends Inc.
	Verioning Number: F18
	Version: ALASKA - 1072009
	Name:BIOS Date: 08/21/12 10:41:14 Ver: 04.06.05
	Serial: To be filled by O.E.M.


 + -------------------------------------------------------- + 
Network Adaptors:


+--------------+

	Name: Intel(R) PRO/1000 PT Server Adapter
	DHCP? (ip4/ip6) False False False
	IP Address: (ip4/ip6)  10.0.0.55
	Gateway: (ip4/ip6)  10.0.0.1
	MACAddress: 00:15:17:94:7F:59
	Domain:   
	ServiceName: e1express
	DeviceID: 12

+--------------+

	Name: Intel(R) PRO/1000 PT Server Adapter
	DHCP? (ip4/ip6) False False False
	IP Address: (ip4/ip6)  10.0.0.55
	Gateway: (ip4/ip6)  10.0.0.1
	MACAddress: 00:15:17:94:7F:59
	Domain:   
	ServiceName: e1express
	DeviceID: 10

+--------------+

	Name: Qualcomm Atheros AR8151 PCI-E Gigabit Ethernet Controller (NDIS 6.30)
	DHCP? (ip4/ip6) False
	IP Address: (ip4/ip6)10.0.0.52
	Gateway: (ip4/ip6)10.0.0.1
	MACAddress: 90:2B:34:55:80:12
	Domain: 
	ServiceName: L1C
	DeviceID: 11

+--------------+

	Name: TEAM : Team #1
	DHCP? (ip4/ip6) False False False
	IP Address: (ip4/ip6)  10.0.0.55
	Gateway: (ip4/ip6)  10.0.0.1
	MACAddress: 00:15:17:94:7F:59
	Domain:   
	ServiceName: iANSMiniport
	DeviceID: 18


 + -------------------------------------------------------- + 
Timezone:

	Timezone: (UTC-06:00) Central Time (US & Canada)

 + -------------------------------------------------------- + 
Disk Drives:


+--------------+

	Model: Maxtor 6L300S0
	Serial Number: L60V425G            
	DeviceID: \\.\PHYSICALDRIVE0
	Partitions: 2
	Size: 0.2729 TB

+--------------+

	Model: ST2000DM001-9YN164
	Serial Number:             Z1E1HP79
	DeviceID: \\.\PHYSICALDRIVE1
	Partitions: 1
	Size: 1.8193 TB

+--------------+

	Model: Intel Raid 5 Volume
	Serial Number: 4u
	DeviceID: \\.\PHYSICALDRIVE2
	Partitions: 2
	Size: 5.458 TB

+--------------+

	Model: WD My Book 1230 USB Device
	Serial Number: WCC4N1268355    
	DeviceID: \\.\PHYSICALDRIVE3
	Partitions: 1
	Size: 2.729 TB

+--------------+

	Model: Samsung D3 Station USB Device
	Serial Number:     00000000011E0A49
	DeviceID: \\.\PHYSICALDRIVE4
	Partitions: 1
	Size: 3.6387 TB


 + -------------------------------------------------------- + 
Local Drives:


+--------------+

	Letter: \\?\Volume{029ad4cb-fb74-11e3-80b1-806e6f6e6963}\
	Label: System Reserved
	File System: NTFS
	Capacity: 0.0003 TB
	FreeSpace: 0.0001 TB

+--------------+

	Letter: C:\
	Label: 
	File System: NTFS
	Capacity: 0.2726 TB
	FreeSpace: 0.213 TB

+--------------+

	Letter: D:\
	Label: 2TB
	File System: NTFS
	Capacity: 1.8193 TB
	FreeSpace: 1.6558 TB

+--------------+

	Letter: E:\
	Label: SAMSUNG
	File System: NTFS
	Capacity: 3.6387 TB
	FreeSpace: 0.7338 TB

+--------------+

	Letter: F:\
	Label: 4uRAID
	File System: NTFS
	Capacity: 5.4579 TB
	FreeSpace: 1.2017 TB

+--------------+

	Letter: G:\
	Label: WD
	File System: NTFS
	Capacity: 2.729 TB
	FreeSpace: 2.0714 TB


 + -------------------------------------------------------- + 
Users:


+--------------+

	Caption: NT AUTHORITY\SYSTEM
	Name: NT AUTHORITY\SYSTEM
	Last Logon: 
	Description: Network login profile settings for SYSTEM on NT AUTHORITY
	User Type: 



+--------------+

	Caption: NT AUTHORITY\LOCAL SERVICE
	Name: NT AUTHORITY\LOCAL SERVICE
	Last Logon: 
	Description: Network login profile settings for LOCAL SERVICE on NT AUTHORITY
	User Type: 



+--------------+

	Caption: NT AUTHORITY\NETWORK SERVICE
	Name: NT AUTHORITY\NETWORK SERVICE
	Last Logon: 
	Description: Network login profile settings for NETWORK SERVICE on NT AUTHORITY
	User Type: 



+--------------+

	Caption: Administrator
	Name: 4U\Administrator
	Last Logon: 20171005152701.000000-300
	Description: Network login profile settings for  on 4U
	User Type: Normal Account



+--------------+

	Caption: TPFND\twist
	Name: TPFND\twist
	Last Logon: 
	Description: Network login profile settings for twist on TPFND
	User Type: 



+--------------+

	Caption: TPFND\ServerAdmin$
	Name: TPFND\ServerAdmin$
	Last Logon: 
	Description: Network login profile settings for ServerAdmin$ on TPFND
	User Type: 



+--------------+

	Caption: TPFND\MediaAdmin$
	Name: TPFND\MediaAdmin$
	Last Logon: 
	Description: Network login profile settings for MediaAdmin$ on TPFND
	User Type: 



+--------------+

	Caption: TPFND\Administrator
	Name: TPFND\Administrator
	Last Logon: 
	Description: Network login profile settings for Administrator on TPFND
	User Type: 



+--------------+

	Caption: 
	Name: 
	Last Logon: 
	Description: Network login profile settings for  on 
	User Type: 




 + -------------------------------------------------------- + 
Local Users:


+--------------+

	Caption: 4U\Administrator
	Name: Administrator
	Full Name: 
	SID: S-1-5-21-1949864851-2443593950-1573834108-500



+--------------+

	Caption: 4U\Guest
	Name: Guest
	Full Name: 
	SID: S-1-5-21-1949864851-2443593950-1573834108-501




 + -------------------------------------------------------- + 
Network Printers:


printername                                                 hostaddress                                                
-----------                                                 -----------                                                
Color Laser                                                 10.0.0.203                                                 



 + -------------------------------------------------------- + 
Startup Applications:


+--------------+

	Name: IAStorIcon
	Command: "C:\Program Files\Intel\Intel(R) Rapid Storage Technology\IAStorIconLaunch.exe" "C:\Program Files\Intel\Intel(R) Rapid Storage Technology\IAStorIcon.exe" 60
	User: Public




 + -------------------------------------------------------- + 
Installed Programs:


+--------------+

	Name: Microsoft Visual C++ 2012 Redistributable (x86) - 11.0.51106
	Vendor: Microsoft Corporation
	Version: 11.0.51106.1



+--------------+

	Name: Adobe Flash Player 14 Plugin
	Vendor: Adobe Systems Incorporated
	Version: 14.0.0.125



+--------------+

	Name: Unknown Device Identifier 8.00
	Vendor: Huntersoft
	Version: 



+--------------+

	Name: SeaTools for Windows
	Vendor: Seagate Technology
	Version: 



+--------------+

	Name: Microsoft SQL Server VSS Writer
	Vendor: Microsoft Corporation
	Version: 10.3.5500.0



+--------------+

	Name: Microsoft SQL Server 2008 Native Client
	Vendor: Microsoft Corporation
	Version: 10.3.5500.0



+--------------+

	Name: Microsoft SQL Server 2008 Setup Support Files
	Vendor: Microsoft Corporation
	Version: 10.3.5500.0



+--------------+

	Name: System Requirements Lab for Intel
	Vendor: Husdawg, LLC
	Version: 4.5.24.0



+--------------+

	Name: Intel(R) Network Connections 19.1.51.0
	Vendor: Intel
	Version: 19.1.51.0



+--------------+

	Name: Microsoft Assessment and Planning Toolkit
	Vendor: Microsoft Corporation
	Version: 9.1.265.0



+--------------+

	Name: Microsoft Web Platform Installer 5.0
	Vendor: Microsoft Corporation
	Version: 5.0.50430.0



+--------------+

	Name: Mozilla Maintenance Service
	Vendor: Mozilla
	Version: 42.0.0.5780



+--------------+

	Name: Java 8 Update 40
	Vendor: Oracle Corporation
	Version: 8.0.400



+--------------+

	Name: Microsoft SQL Server 2008 Browser
	Vendor: Microsoft Corporation
	Version: 10.3.5500.0



+--------------+

	Name: Microsoft Visual C++ 2010  x64 Redistributable - 10.0.40219
	Vendor: Microsoft Corporation
	Version: 10.0.40219



+--------------+

	Name: Etron USB3.0 Host Controller
	Vendor: Etron Technology
	Version: 0.118



+--------------+

	Name: TeraCopy 2.27
	Vendor: Code Sector
	Version: 



+--------------+

	Name: Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729
	Vendor: Microsoft Corporation
	Version: 9.0.30729



+--------------+

	Name: Mozilla Firefox 47.0.2 (x86 en-US)
	Vendor: Mozilla
	Version: 47.0.2



+--------------+

	Name: Intel(R) Rapid Storage Technology
	Vendor: Intel Corporation
	Version: 12.9.0.1001



+--------------+

	Name: Microsoft System Center Virtual Machine Manager Agent (x64)
	Vendor: Microsoft Corporation
	Version: 3.1.6011.0



+--------------+

	Name: Microsoft SQL Server 2008 (64-bit)
	Vendor: Microsoft Corporation
	Version: 



+--------------+

	Name: Renesas Electronics USB 3.0 Host Controller Driver
	Vendor: Renesas Electronics Corporation
	Version: 3.0.23.0



+--------------+

	Name: Microsoft Visual C++ 2010  x86 Redistributable - 10.0.40219
	Vendor: Microsoft Corporation
	Version: 10.0.40219



+--------------+

	Name: Windows Installer Clean Up
	Vendor: Microsoft Corporation
	Version: 3.00.00.0000



+--------------+

	Name: Microsoft Visual C++ 2005 Redistributable (x64)
	Vendor: Microsoft Corporation
	Version: 8.0.61000



+--------------+

	Name: Intel? Power Gadget 3.0
	Vendor: Intel
	Version: 3.01.5



+--------------+

	Name: Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.6161
	Vendor: Microsoft Corporation
	Version: 9.0.30729.6161



+--------------+

	Name: Notepad++
	Vendor: Notepad++ Team
	Version: 6.6.9



+--------------+

	Name: NovaBench 3.0.4
	Vendor: Novawave Inc.
	Version: 



+--------------+

	Name: Microsoft Silverlight
	Vendor: Microsoft Corporation
	Version: 5.1.41105.0




 + -------------------------------------------------------- + 
DOTnet:


+--------------+

	Framework Name: Microsoft .Net Framework
	Framework Version: v1.1.4322



+--------------+

	Framework Name: Microsoft .Net Framework
	Framework Version: v2.0.50727



+--------------+

	Framework Name: Microsoft .Net Framework
	Framework Version: v2.0.50727



+--------------+

	Framework Name: Microsoft .Net Framework
	Framework Version: v2.0.50727



+--------------+

	Framework Name: Microsoft .Net Framework
	Framework Version: v2.0.50727



+--------------+

	Framework Name: Microsoft .Net Framework
	Framework Version: v2.0.50727



+--------------+

	Framework Name: Microsoft .Net Framework
	Framework Version: v2.0.50727



+--------------+

	Framework Name: Microsoft .Net Framework
	Framework Version: v4.0.30319



+--------------+

	Framework Name: Microsoft .Net Framework
	Framework Version: v4.0.30319



+--------------+

	Framework Name: Microsoft .Net Framework
	Framework Version: v4.0.30319



+--------------+

	Framework Name: Microsoft .Net Framework
	Framework Version: v4.0.30319



+--------------+

	Framework Name: Microsoft .Net Framework
	Framework Version: v4.0.30319



+--------------+

	Framework Name: Microsoft .Net Framework
	Framework Version: v4.0.30319



+--------------+

	Framework Name: Microsoft .Net Framework
	Framework Version: v4.0.30319



+--------------+

	Framework Name: Microsoft .Net Framework
	Framework Version: v4.0.30319



+--------------+

	Framework Name: Microsoft .Net Framework
	Framework Version: v4.0.CORE




 + -------------------------------------------------------- + 
Roles and Features:


Display Name                                            Name                       Install State
------------                                            ----                       -------------
[X] Active Directory Domain Services                    AD-Domain-Services             Installed
[X] DHCP Server                                         DHCP                           Installed
[X] DNS Server                                          DNS                            Installed
[X] File and Storage Services                           FileAndStorage-Services        Installed
    [X] File and iSCSI Services                         File-Services                  Installed
        [X] File Server                                 FS-FileServer                  Installed
    [X] Storage Services                                Storage-Services               Installed
[X] .NET Framework 3.5 Features                         NET-Framework-Features         Installed
    [X] .NET Framework 3.5 (includes .NET 2.0 and 3.0)  NET-Framework-Core             Installed
[X] .NET Framework 4.5 Features                         NET-Framework-45-Fea...        Installed
    [X] .NET Framework 4.5                              NET-Framework-45-Core          Installed
    [X] WCF Services                                    NET-WCF-Services45             Installed
        [X] TCP Port Sharing                            NET-WCF-TCP-PortShar...        Installed
[X] Group Policy Management                             GPMC                           Installed
[X] Remote Differential Compression                     RDC                            Installed
[X] Remote Server Administration Tools                  RSAT                           Installed
    [X] Feature Administration Tools                    RSAT-Feature-Tools             Installed
        [X] WINS Server Tools                           RSAT-WINS                      Installed
    [X] Role Administration Tools                       RSAT-Role-Tools                Installed
        [X] AD DS and AD LDS Tools                      RSAT-AD-Tools                  Installed
            [X] Active Directory module for Windows ... RSAT-AD-PowerShell             Installed
            [X] AD DS Tools                             RSAT-ADDS                      Installed
                [X] Active Directory Administrative ... RSAT-AD-AdminCenter            Installed
                [X] AD DS Snap-Ins and Command-Line ... RSAT-ADDS-Tools                Installed
        [X] DHCP Server Tools                           RSAT-DHCP                      Installed
        [X] DNS Server Tools                            RSAT-DNS-Server                Installed
[X] SMB 1.0/CIFS File Sharing Support                   FS-SMB1                        Installed
[X] User Interfaces and Infrastructure                  User-Interfaces-Infra          Installed
    [X] Graphical Management Tools and Infrastructure   Server-Gui-Mgmt-Infra          Installed
    [X] Server Graphical Shell                          Server-Gui-Shell               Installed
[X] Windows Internal Database                           Windows-Internal-Dat...        Installed
[X] Windows PowerShell                                  PowerShellRoot                 Installed
    [X] Windows PowerShell 4.0                          PowerShell                     Installed
    [X] Windows PowerShell 2.0 Engine                   PowerShell-V2                  Installed
    [X] Windows PowerShell ISE                          PowerShell-ISE                 Installed
[X] Windows Search Service                              Search-Service                 Installed
[X] Windows Server Backup                               Windows-Server-Backup          Installed
[X] WINS Server                                         WINS                           Installed
[X] WoW64 Support                                       WoW64-Support                  Installed



 + -------------------------------------------------------- + 
Roles:

LM_Workstation
LM_Server
SQLServer
Timesource
Print
NT
Server_NT
DFS

Return to Top

ITIL.ps1 code

#NOTE: change the path below (and in the included ps1 file) if you install this someplace else
. "C:\PS\includes\rootvaribles.ps1"

$content = $FRO + "staticlist.cvs"
$computers = import-csv $content –header Name, IP, OS –delimiter :
ForEach ($c in $computers)
{
$comp = $c.Name

#Set filepath per PC
$PCFP = $FRO + $comp

#OS
$os = gwmi win32_OperatingSystem -Computer $comp | Select Caption, OSArchitecture, Version, BuildNumber

$wmi = gwmi Win32_OperatingSystem
$InstallDate = $wmi.ConvertToDateTime($wmi.InstallDate)

$OPERATINGSYSTEM=
$tab + "Operating Systyem: " + $os.Caption + $nl + 
$tab + "Architecture: " + $os.OSArchitecture + $nl + 
$tab + "Version: " + $os.Version + $nl + 
$tab + "Build Number: " + $os.BuildNumber + $nl + 
$tab + "Install Date: " + $InstallDate

#MOTHERBOARD
$mb1 = gwmi Win32_ComputerSystem -Computer $comp | Select Manufacturer, TotalPhysicalMemory

$mb2 = gwmi Win32_MotherboardDevice -Computer $comp | Select PrimaryBusType, SecondaryBusType

$mb3 = gwmi Win32_BaseBoard -Computer $comp | select Caption, Manufacturer, Product, SerialNumber, Status

$MOTHERBOARD =
$tab + "Vendor: " + $mb1.Manufacturer + $nl + 
$tab + "Product number: " + $mb3.Product + $nl + 
$tab + "Serial Number: " + $mb3.SerialNumber + $nl + 
$tab + "Primary Bus Type: " + $mb2.PrimaryBusType + $nl + 
$tab + "Secondary Bus Type: " + $mb2.SecondaryBusType

#MEMORY
$mem1 = gwmi Win32_PhysicalMemoryArray -Computer $comp | Select Name, MaxCapacity, MemoryDevices

$mem2 = gwmi Win32_PhysicalMemory -Computer $comp  | Select BankLabel, Capacity, DeviceLocator, PartNumber, Speed, DataWidth, FormFactor

$MEMORY =
$tab + "Usable Physical Memory: " + [math]::Round(($mb1.TotalPhysicalMemory/1GB),2) + " GB" + $nl + 
$tab + "Total memory modules: " + $mem1.MemoryDevices

$x=0

Foreach ($x in $mem2)
	{
		$memorymodules = $memorymodules + $subbreak
		$memorymodules = $memorymodules + $tab + "Bank Label: " + $x.BankLabel + $nl
		$memorymodules = $memorymodules + $tab + "Capacity: " + $x.Capacity + $nl
		$memorymodules = $memorymodules + $tab + "Device Locator: " + $x.DeviceLocator + $nl
		$memorymodules = $memorymodules + $tab + "Part Number: " + $x.PartNumber + $nl
		$memorymodules = $memorymodules + $tab + "Speed: " + $x.Speed + $nl
		$memorymodules = $memorymodules + $tab + "Data Width: " + $x.DataWidth + $nl
		$memorymodules = $memorymodules + $tab + "Form Factor: " + $x.FormFactor + $nl + $nl
	}

#PROCESSOR
$pr = gwmi Win32_Processor -Computer $comp 

$PROCESSOR=
$tab + "Type: " + $pr.Caption + $nl + 
$tab + "Manufacturer: " + $pr.Manufacturer + $nl + 
$tab + "MaxClockSpeed: " + $pr.MaxClockSpeed + $nl + 
$tab + "Retail Name: " + $pr.Name + $nl + 
$tab + "SocketDesignation: " + $pr.SocketDesignation + $nl
$tab + "ID: " + $pr.DeviceID + $nl

#BIOS
$bs = gwmi Win32_BIOS -Computer $comp | Select Manufacturer, SMBIOSBIOSVersion, Name, Version, SerialNumber

$bios=
$tab + "Manufacturer: " + $bs.Manufacturer + $nl + 
$tab + "Verioning Number: " + $bs.SMBIOSBIOSVersion + $nl + 
$tab + "Version: " + $bs.Version + $nl +
$tab + "Name:" + $bs.Name + $nl + 
$tab + "Serial: " + $bs.SerialNumber + $nl

#NETWORK ADAPTORS
$net1 = gwmi Win32_NetworkAdapter -Computer $comp | Where {($_.AdapterType -eq "Ethernet 802.3") -and ($_.MACAddress -ne $null)} | Select Name, MACAddress, ServiceName, DeviceID | Sort-Object -property Name

$x = 0
$NETWORKADAPTORS = ""
Foreach ($x in $net1)
	{
		$net2 = gwmi Win32_NetworkAdapterConfiguration -Computer $comp | Where {$_.MACAddress -eq $x.MACAddress} | Select IPAddress, DefaultIPGateway, DHCPEnabled, DNSDomain
		$NETWORKADAPTORS = $NETWORKADAPTORS + $subbreak
		$NETWORKADAPTORS = $NETWORKADAPTORS + $tab + "Name: "  +  $x.Name + $nl
		$NETWORKADAPTORS = $NETWORKADAPTORS + $tab + "DHCP? (ip4/ip6) "  +  $net2.DHCPEnabled + $nl
		$NETWORKADAPTORS = $NETWORKADAPTORS + $tab + "IP Address: (ip4/ip6)" + $net2.IPAddress + $nl
		$NETWORKADAPTORS = $NETWORKADAPTORS + $tab + "Gateway: (ip4/ip6)" + $net2.DefaultIPGateway + $nl
		$NETWORKADAPTORS = $NETWORKADAPTORS + $tab + "MACAddress: "  +  $x.MACAddress + $nl
		$NETWORKADAPTORS = $NETWORKADAPTORS + $tab + "Domain: " + $net2.DNSDomain + $nl
		$NETWORKADAPTORS = $NETWORKADAPTORS + $tab + "ServiceName: "  +  $x.ServiceName + $nl
		$NETWORKADAPTORS = $NETWORKADAPTORS + $tab + "DeviceID: "  + $x.DeviceID + $nl
	}
	
	
#TIMEZONE
$TIMEZONE = gwmi Win32_TimeZone -Computer $comp | Select Caption 
$TIMEZONE = $tab + "Timezone: " + $timezone.Caption


#MAPPEDDRIVES
$md = gwmi Win32_MappedLogicalDisk -Computer $comp| select Name, ProviderName

$x = 0
$MAPPEDDRIVES = ""
Foreach ($x in $md)
	{
		$MAPPEDDRIVES = $MAPPEDDRIVES + $subbreak
		$MAPPEDDRIVES = $MAPPEDDRIVES + $tab + "Name: " + $x.Name + $nl
		$MAPPEDDRIVES = $MAPPEDDRIVES + $tab + "Path: " + $x.ProviderName + $nl
	}

#DISKDRIVES
$dd = gwmi Win32_DiskDrive -Computer $comp | Select Model, DeviceID, Size, Partitions | Sort-Object -property DeviceID

$x=0
$DISKDRIVES=""
Foreach ($x in $dd)
	{
		$snumber = gwmi Win32_PhysicalMedia -Computer $comp | Where {$_.Tag -like $x.DeviceID} | Select SerialNumber
		$DISKDRIVES = $DISKDRIVES + $subbreak
		$DISKDRIVES = $DISKDRIVES + $tab + "Model: " + $x.Model + $nl
		$DISKDRIVES = $DISKDRIVES + $tab + "Serial Number: " + $snumber.serialnumber + $nl
		$DISKDRIVES = $DISKDRIVES + $tab + "DeviceID: " + $x.DeviceID + $nl
		$DISKDRIVES = $DISKDRIVES + $tab + "Partitions: " + $x.Partitions + $nl
		$DISKDRIVES = $DISKDRIVES + $tab + "Size: "  + [math]::Round(($x.Size/1TB),4) + " TB" + $nl
	}

#LOCALDRIVES
$ld = gwmi Win32_Volume -Computer $comp | Select Caption, Label, FileSystem, Capacity, FreeSpace | Sort-Object -property Caption

$x=0
$LOCALDRIVES=""
Foreach ($x in $ld)
	{
		$LOCALDRIVES = $LOCALDRIVES + $subbreak
		$LOCALDRIVES = $LOCALDRIVES + $tab + "Letter: " + $x.Caption + $nl
		$LOCALDRIVES = $LOCALDRIVES + $tab + "Label: " + $x.Label + $nl
		$LOCALDRIVES = $LOCALDRIVES + $tab + "File System: " + $x.FileSystem + $nl
		$LOCALDRIVES = $LOCALDRIVES + $tab + "Capacity: "  + [math]::Round(($x.Capacity/1TB),4) + " TB" + $nl
		$LOCALDRIVES = $LOCALDRIVES + $tab + "FreeSpace: "  + [math]::Round(($x.FreeSpace/1TB),4) + " TB" + $nl
	}

#SHARES
gwmi Win32_NetworkConnection -Computer $comp | Select LocalName, RemoteName | Format-List

gwmi Win32_share -computer $comp | Where {($_.name -NotLike "*$") -and ($_.path -NotLike "*ServerFolders*")} | Sort-Object -property path | FT path, name, Description -autosize 

#INSTALLEDPROGRAMS
$InsProg = gwmi Win32_InstalledWin32Program -Computer $comp | Select Name, Vendor, Version

$x=0
$INSTALLEDPROGRAMS=""
Foreach ($x in $InsProg)
	{
		$INSTALLEDPROGRAMS = $INSTALLEDPROGRAMS + $subbreak
		$INSTALLEDPROGRAMS = $INSTALLEDPROGRAMS + $tab + "Name: " + $x.Name + $nl
		$INSTALLEDPROGRAMS = $INSTALLEDPROGRAMS + $tab + "Vendor: " + $x.Vendor + $nl
		$INSTALLEDPROGRAMS = $INSTALLEDPROGRAMS + $tab + "Version: " + $x.Version + $nl
		$INSTALLEDPROGRAMS = $INSTALLEDPROGRAMS + $nl + $nl
	}

#DOTNET
$dnet = gwmi Win32_InstalledProgramFramework -Computer $comp | Select FrameworkName, FrameworkVersion  | Sort-Object -property FrameworkVersion

$x=0
$DOTNET=""
Foreach ($x in $dnet)
	{
		$DOTNET = $DOTNET + $subbreak
		$DOTNET = $DOTNET + $tab + "Framework Name: " + $x.FrameworkName + $nl
		$DOTNET = $DOTNET + $tab + "Framework Version: " + $x.FrameworkVersion + $nl
		$DOTNET = $DOTNET + $nl + $nl
	}

#USERS
$usrs=gwmi Win32_NetworkLoginProfile -Computer $comp | Select Caption, LastLogon, Description, Name, UserType
$x=0
$USERS=""
Foreach ($x in $usrs)
	{
		$USERS = $USERS + $subbreak
		$USERS = $USERS + $tab + "Caption: " + $x.Caption + $nl
		$USERS = $USERS + $tab + "Name: " + $x.Name + $nl
		$USERS = $USERS + $tab + "Last Logon: " + $x.LastLogon + $nl
		$USERS = $USERS + $tab + "Description: " + $x.Description + $nl
		$USERS = $USERS + $tab + "User Type: " + $x.UserType + $nl
		$USERS = $USERS + $nl + $nl
	}

#LOCALUSERS
$lusers=gwmi Win32_UserAccount -Computer $comp | Select Caption, SID, Name, FullName
$x=0
$LOCALUSERS=""
Foreach ($x in $lusers)
	{
		$LOCALUSERS = $LOCALUSERS + $subbreak
		$LOCALUSERS = $LOCALUSERS + $tab + "Caption: " + $x.Caption + $nl
		$LOCALUSERS = $LOCALUSERS + $tab + "Name: " + $x.Name + $nl
		$LOCALUSERS = $LOCALUSERS + $tab + "Full Name: " + $x.FullName + $nl
		$LOCALUSERS = $LOCALUSERS + $tab + "SID: " + $x.SID + $nl
		$LOCALUSERS = $LOCALUSERS + $nl + $nl
	}

#STARTUP
$strt = gwmi Win32_StartupCommand -Computer $comp | Select Command, Caption, User | Sort-Object -property User

$x=0
$STRTUP=""
Foreach ($x in $strt)
	{
		$STRTUP = $STRTUP + $subbreak
		$STRTUP = $STRTUP + $tab + "Name: " + $x.Caption + $nl
		$STRTUP = $STRTUP + $tab + "Command: " + $x.Command + $nl
		$STRTUP = $STRTUP + $tab + "User: " + $x.User + $nl
		$STRTUP = $STRTUP + $nl + $nl
	}
	
#PRINTERS
$prnt = gwmi win32_printer -ComputerName $comp | %{ $printer = $_.Name; $port = $_.portname; gwmi win32_tcpipprinterport -computername $comp | where { $_.Name -eq $port } | select @{name="printername";expression={$printer}}, hostaddress }

#SERVERFEATURES
$SERVERFEATURES=Get-WindowsFeature | where-object {$_.Installed -eq $True}

#ROLES
$rls = gwmi Win32_ComputerSystem -Computer $comp | Select -expand Roles

#WRITE TO FILE

#Clean up old files if they exist
$FileExists = Test-Path $PCFP
	If ($FileExists -eq $True) {Remove-Item –path $PCFP}

$OPERATINGSYSTEMtext = $DIVIDE + "Operating System:" + $nl
out-file -filepath $PCFP -inputobject $OPERATINGSYSTEMtext -encoding ASCII -Append
out-file -filepath $PCFP -inputobject $OPERATINGSYSTEM -encoding ASCII -Append

$MOTHERBOARDtext = $DIVIDE + "Motherboard:" + $nl
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $MOTHERBOARDtext -encoding ASCII -Append
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $MOTHERBOARD -encoding ASCII -Append

$PROCESSORtext = $DIVIDE + "Processor:" + $nl
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $PROCESSORtext -encoding ASCII -Append
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $PROCESSOR -encoding ASCII -Append

$MEMORYtext = $DIVIDE + "RAM:" + $nl
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $MEMORYtext -encoding ASCII -Append
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $MEMORY -encoding ASCII -Append

$memorymodulestext = $DIVIDE + "Memory Modules:" + $nl
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $memorymodulestext -encoding ASCII -Append
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $memorymodules -encoding ASCII -Append

$biostext = $DIVIDE + "BIOS:" + $nl
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $biostext -encoding ASCII -Append
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $bios -encoding ASCII -Append

$NETWORKADAPTORStext = $DIVIDE + "Network Adaptors:" + $nl
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $NETWORKADAPTORStext -encoding ASCII -Append
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $NETWORKADAPTORS -encoding ASCII -Append

$TIMEZONEtext = $DIVIDE + "Timezone:" + $nl
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $TIMEZONEtext -encoding ASCII -Append
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $TIMEZONE -encoding ASCII -Append

$DISKDRIVEStext = $DIVIDE + "Disk Drives:" + $nl
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $DISKDRIVEStext -encoding ASCII -Append
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $DISKDRIVES -encoding ASCII -Append

$LOCALDRIVEStext = $DIVIDE + "Local Drives:" + $nl
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $LOCALDRIVEStext -encoding ASCII -Append
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $LOCALDRIVES -encoding ASCII -Append

$USERStext = $DIVIDE + "Users:" + $nl
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $USERStext -encoding ASCII -Append
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $USERS -encoding ASCII -Append

$LOCALUSERStext = $DIVIDE + "Local Users:" + $nl
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $LOCALUSERStext -encoding ASCII -Append
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $LOCALUSERS -encoding ASCII -Append

$prnttext = $DIVIDE + "Network Printers:" + $nl
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $prnttext -encoding ASCII -Append
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $prnt -encoding ASCII -Append

$STRTUPtext = $DIVIDE + "Startup Applications:" + $nl
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $STRTUPtext -encoding ASCII -Append
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $STRTUP -encoding ASCII -Append

$INSTALLEDPROGRAMStext = $DIVIDE + "Installed Programs:" + $nl
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $INSTALLEDPROGRAMStext -encoding ASCII -Append
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $INSTALLEDPROGRAMS -encoding ASCII -Append

$DOTNETtext = $DIVIDE + "DOTnet:" + $nl
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $DOTNETtext -encoding ASCII -Append
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $DOTNET -encoding ASCII -Append

$SERVERFEATUREStext = $DIVIDE + "Roles and Features:" + $nl
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $SERVERFEATUREStext -encoding ASCII -Append
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $SERVERFEATURES -encoding ASCII -Append

$rolestext = $DIVIDE + "Roles:" + $nl
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $rolestext -encoding ASCII -Append
out-file -filepath "C:\PS\OUTPUT\$comp.txt" -inputobject $rls -encoding ASCII -Append
}

Return to Top

DHCP.ps1

This script pulls information about your DHCP server settings. It makes three text files:

  • dynamic.txt: formated output file for each dynamic device
  • dynamiclist.txt: output file for FQDN for each dynamic IP
  • dynamiclist.cvs: output file for FQDN:IP

dynamic.txt output example

+--------------+

	Host Name: TV.tpfnd.cat
	IP Address: 10.0.0.201
	Scope Id: 10.0.0.0
	Lease Expiry Time: 10/28/2017 09:35:43

+--------------+

	Host Name: Galaxy-J3-Prime.tpfnd.cat
	IP Address: 10.0.0.203
	Scope Id: 10.0.0.0
	Lease Expiry Time: 10/26/2017 13:24:00

+--------------+

	Host Name: tower.tpfnd.cat
	IP Address: 10.0.0.204
	Scope Id: 10.0.0.0
	Lease Expiry Time: 10/28/2017 17:50:26

+--------------+

	Host Name: bedroom.tpfnd.cat
	IP Address: 10.0.0.205
	Scope Id: 10.0.0.0
	Lease Expiry Time: 10/29/2017 15:56:26

+--------------+

	Host Name: Win7Test.tpfnd.cat
	IP Address: 10.0.0.206
	Scope Id: 10.0.0.0
	Lease Expiry Time: 10/25/2017 20:19:01

Return to Top

dynamiclist.txt output example

TV.tpfnd.cat
Galaxy-J3-Prime.tpfnd.cat
tower.tpfnd.cat
bedroom.tpfnd.cat
Win7Test.tpfnd.cat

Return to Top

dynamiclist.txt output example

TV.tpfnd.cat:10.0.0.201
Galaxy-J3-Prime.tpfnd.cat:10.0.0.203
tower.tpfnd.cat:10.0.0.204
bedroom.tpfnd.cat:10.0.0.205
Win7Test.tpfnd.cat:10.0.0.206

Return to Top

The code

#define root varibles
#NOTE: change the path below (and in the included ps1 file) if you install this someplace else
. "C:\PS\includes\rootvaribles.ps1"
. "C:\PS\includes\scope.ps1"

#Set filepaths. ODF=
$OFD = $FRO + "dynamic.txt"
$OFDL = $FRO + "dynamiclist.txt"
$OFCVS = $FRO + "dynamiclist.cvs"

#Clean up old files if they exist
$FileExists = Test-Path $OFD
	If ($FileExists -eq $True) {Remove-Item –path $OFD}
$FileExists = Test-Path $OFDL
	If ($FileExists -eq $True) {Remove-Item –path $OFDL}
$FileExists = Test-Path $OFCVS
	If ($FileExists -eq $True) {Remove-Item –path $OFCVS}

#Clear varibles
$DNSDYNAMIC = ""
$dynamiclist = ""
$dynamic = ""
$cv = ""

#Fix scope
$SmallScope = $Scope
$Scope = $Scope + ".0"

#START OF CODE

$dns = Get-DnsServerSetting | Select-Object ComputerName, AllIPAddress

$DNSServerName = $dns.ComputerName
$DNSServerIP = $dns.AllIPAddress

$DNSLeases = Get-DhcpServerv4Lease -ScopeId $Scope |  Where {($_.HostName -ne $null) -and ($_.LeaseExpiryTime -ne $null)} | Select IPAddress, ScopeID, HostName, LeaseExpiryTime

$x = 0

Foreach ($x in $DNSLeases)
	{
		$DNSDYNAMIC = $DNSDYNAMIC + $subbreak
		$DNSDYNAMIC = $DNSDYNAMIC + $tab + "Host Name: "  +  $x.HostName + $nl
		$DNSDYNAMIC = $DNSDYNAMIC + $tab + "IP Address: "  +  $x.IPAddress + $nl
		$DNSDYNAMIC = $DNSDYNAMIC + $tab + "Scope Id: " + $x.ScopeId + $nl
		$DNSDYNAMIC = $DNSDYNAMIC + $tab + "Lease Expiry Time: " + $x.LeaseExpiryTime + $nl
		$dynamiclist = $dynamiclist + $x.HostName + $nl
		$dynamic = $dynamic + $x.HostName + $x.IPAddress + $nl
		$cv = $cv + $x.HostName + ":"  + $x.IPAddress + $nl
	}

$DHCPO1 = Get-DhcpServerv4OptionValue -Scope $Scope | Sort-Object -property OptionID

$x = 0

Foreach ($x in $DNSLeases)
	{
		$DHCPOptions = $DHCPOptions + $subbreak
		$DHCPOptions = $DHCPOptions + $tab + "Option Id: "  +  $x.OptionId + $nl
		$DHCPOptions = $DHCPOptions + $tab + "Name: "  +  $x.Name + $nl
		$DHCPOptions = $DHCPOptions + $tab + "Type: " + $x.Type + $nl
		$DHCPV =  Get-DhcpServerv4OptionValue -Scope $Scope | Where ($_.OptionID -eq $x.OptionId) | Select -expand Value
		$DHCPOptions = $DHCPOptions + $tab + "Values: " + $x.DHCPV + $nl
	}

#Write to files

out-file $OFD -inputobject $DNSDYNAMIC -encoding ASCII -Append
out-file $OFDL -inputobject $dynamiclist -encoding ASCII -Append
out-file $OFCVS -inputobject $cv -encoding ASCII -Append

 Get-DhcpServerSetting -ComputerName REALM.tpfnd.cat | FT *
 Get-DhcpServerv4DnsSetting -ComputerName REALM.tpfnd.cat 

Return to Top

References

Return to Top