0% found this document useful (0 votes)
47 views5 pages

Skrypt

The document contains PowerShell functions to generate reports on various Active Directory and DNS configuration details. It includes functions to generate reports on the domain, A records in DNS, PTR records in DNS, running services, installed roles/features, shared folders, and event logs. The functions retrieve information using commands like Get-ADDomain, Get-DnsServerResourceRecord, Get-Service, and Get-EventLog then output the results to text files. A menu function allows selecting which report to generate.

Uploaded by

Damian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views5 pages

Skrypt

The document contains PowerShell functions to generate reports on various Active Directory and DNS configuration details. It includes functions to generate reports on the domain, A records in DNS, PTR records in DNS, running services, installed roles/features, shared folders, and event logs. The functions retrieve information using commands like Get-ADDomain, Get-DnsServerResourceRecord, Get-Service, and Get-EventLog then output the results to text files. A menu function allows selecting which report to generate.

Uploaded by

Damian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

function raport-domena{

#wywietlnie OU dla komputerow i user


$domain = Get-ADDomain
$forest = Get-ADForest
$DC=Get-ADDomainController

[string]$data = Get-Date
$data
$autor = " `n Autor:Damian Woszczak"
$info = $data + $autor | Out-File $path\${name}.txt

$name = $domain.DNSRoot
$Output = "SID domeny:"+$domain.DomainSID | Out-File $path\${name}.txt -Append
$Output = "DNS ROOT:" + $domain.DNSRoot | Out-File ${path}\${name}.txt -Append
$Output = "Jednostka organizacyjna dla komputerow:" + $domain.ComputersContainer |
Out-File ${path}\${name}.txt -Append
$Output = "Jednostka organizcyjna dla uzytkownikow:" + $domain.UsersContainer |
Out-File ${path}\${name}.txt -Append
$Output = "Poziom domeny:" + $domain.DomainMode | Out-File ${path}\${name}.txt
-Append
$Output = "Poziom lasu:" + $forest.ForestMode | Out-File ${path}\${name}.txt
-Append
$domaincontrollers = Get-ADDomainController -filter * | foreach {$_.Name}
foreach($domaincontroller in $domaincontrollers){
"Lista konrolerow domeny:" |Out-File ${path}\${name}.txt -Append
Get-ADDomainController -Filter * | Select-Object name |Out-File ${path}\$
{name}.txt -Append
}

Write-Host "SID domeny:" $domain.DomainSID


Write-Host "DNS ROOT:" $domain.DNSRoot
Write-Host "Jednostka organizacyjna dla komputerow:" $domain.ComputersContainer
Write-Host "Jednostka organizcyjna dla uzytkownikow:" $domain.UsersContainer
Write-Host "Poziom domeny:" $domain.DomainMode
Write-Host "Poziom lasu:" $forest.ForestMode
Write-Host "Lista konrolerow domeny:" | Get-ADDomainController -filter * | ft name

function raport-dns{
$domain = Get-ADDomain
$zones = Get-DnsServerZone | Where {($_.Zonetype -eq "primary" )-and
($_.isreverselookupzone -eq $false)} | foreach { $_.ZoneName }

foreach($zone in $zones){
$zone
Get-DnsServerResourceRecord -ZoneName $zone -RRType A |ft Hostname,@{n ="Adres
IP"; e={$_.RecordData.IPv4Address.IPAddressToString} }
Get-DnsServerResourceRecord -ZoneName $zone -RRType A |Select-Object
Hostname,{n ="Adres IP"; e={$_.RecordData.IPv4Address.IPAddressToString} } |
Export-Csv ${path}\${zone}_strefaDNS.csv -NoTypeInformation
Add-Content ${path}\${zone}_strefaDNS.csv $info
}
}

function raport-ptr{
$ptrzones = Get-DnsServerZone | Where {($_.Zonetype -eq "primary" )-and
($_.isreverselookupzone -eq $true)} | foreach { $_.ZoneName }

foreach($ptrzone in $ptrzones){
$ptrzone
Get-DnsServerResourceRecord -ZoneName $ptrzone -RRType Ptr |ft @{n="IP";
e={$_.Hostname}},@{n ="Host"; e={$_.recorddata.ptrdomainname} }
Get-DnsServerResourceRecord -ZoneName $ptrzone -RRType Ptr | Select-Object
Hostname,@{n ="Host"; e={$_.recorddata.ptrdomainname} }| Export-Csv ${path}\$
{ptrzone}_strefy.csv -NoTypeInformation
Add-Content ${path}\${ptrzone}_strefy.csv $info
}

function raport-uslugi{

$domaincontrollers = Get-ADDomainController -filter * | foreach {$_.Name}


foreach($domaincontroller in $domaincontrollers){
Invoke-Command -ComputerName $domaincontroller -ArgumentList
$domaincontroller,$path,$info -ScriptBlock{
param($domaincontroller,$path,$info)
Write-Host "Uruchomione uslugi na:" $domaincontroller
Get-Service |where status -Like "Running" |ft Name,DisplayName,Status
Get-Service |where status -Like "Running" |Select-Object
Name,DisplayName,Status | Export-Csv ${path}\${domaincontroller}-serwer_uslugi.csv
-NoTypeInformation

Add-Content ${path}\${domaincontroller}-serwer_uslugi.csv $info


}
}
}

function raport-role{
$domaincontrollers = Get-ADDomainController -filter * | foreach {$_.Name}
foreach($domaincontroller in $domaincontrollers){
Invoke-Command -ComputerName $domaincontroller -ArgumentList
$domaincontroller,$path,$info -ScriptBlock{
param($domaincontroller,$path,$info)
Write-Host "FRole i funckje zainstalowane na:" $domaincontroller
Get-WindowsFeature | Where-Object {$_.installstate -eq "installed"} | ft
Name,DisplayName
Get-WindowsFeature | Where-Object {$_.installstate -eq "installed"} |
Select-Object Name,DisplayName |Export-Csv ${path}\${domaincontroller}-
serwer_role.csv -NoTypeInformation
Add-Content ${path}\${domaincontroller}-serwer_role.csv $info
}
}
}

function raport-smb{
$domaincontrollers = Get-ADDomainController -filter * | foreach {$_.Name}

foreach($domaincontroller in $domaincontrollers){
Invoke-Command -ComputerName $domaincontroller -ArgumentList
$domaincontroller,$path,$info -ScriptBlock{
param($domaincontroller,$path,$info)
Write-Host "Udzialy sieciowe dostepne na:" $domaincontroller
Get-SmbShare |Where-Object {$_.name -notLike "*$"} |ft
Name,Path,Description
Get-SmbShare |Where-Object {$_.name -notLike "*$"} |Select-Object
Name,Path,Description |Export-Csv ${path}\${domaincontroller}-serwer_udzialy.csv
-NoTypeInformation
Add-Content ${path}\${domaincontroller}-serwer_udzialy.csv $info
}
}
}

function event-logs{

Write-Host "Logi System"


Get-EventLog -LogName System -Newest 5 -ErrorAction SilentlyContinue
Write-Host "Logi security"
Get-EventLog -LogName Security -Newest 5 -ErrorAction SilentlyContinue
Write-Host "Logi Autoruns"
Get-EventLog -LogName Autoruns -Newest 5 -ErrorAction SilentlyContinue
Write-Host "Logi Directory Service"
Get-EventLog -LogName 'Directory Service' -Newest 5 -ErrorAction SilentlyContinue

Write-Host "Logi Application"


Get-EventLog -LogName Application -Newest 5 -ErrorAction SilentlyContinue
Write-Host "Logi Windows PowerShell"
Get-EventLog -LogName 'Windows PowerShell' -Newest 5 -ErrorAction SilentlyContinue
"Logi System " | Out-File ${path}\events.txt
Get-EventLog -LogName System -Newest 5 -ErrorAction SilentlyContinue| Out-File $
{path}\events.txt -Append
"Logi Security " | Out-File ${path}\events.txt -Append
Get-EventLog -LogName Security -Newest 5 -ErrorAction SilentlyContinue| Out-File $
{path}\events.txt -Append
"Logi Autoruns " | Out-File ${path}\events.txt -Append
Get-EventLog -LogName Autoruns -Newest 5 -ErrorAction SilentlyContinue | Out-File $
{path}\events.txt -Append
"Logi Directory Service " | Out-File ${path}\events.txt -Append
Get-EventLog -LogName 'Directory Service' -Newest 5 -ErrorAction SilentlyContinue|
Out-File ${path}\events.txt -Append

"Logi Application " | Out-File ${path}\events.txt -Append


Get-EventLog -LogName Application -Newest 5 -ErrorAction SilentlyContinue | Out-
File ${path}\events.txt -Append
"Logi Windows PowerShell " | Out-File ${path}\events.txt -Append
Get-EventLog -LogName 'Windows PowerShell' -Newest 5 -ErrorAction SilentlyContinue
| Out-File ${path}\events.txt -Append
}

function Menu
{
param (
[string]$Title = 'Menu'
)
cls
Write-Host "================ $Title ================"

Write-Host "1: Wcisnij '1' do stworzenia raportu o domenie."


Write-Host "2: Wcisnij '2' do stworzenia raportu o rekordach typu A w DNS."
Write-Host "3: Wcisnij '3' do stworzenia raportu o rekordach PTR w DNS."
Write-Host "4: Wcisnij '4' do stworzenia raportu o uruchomionych uslugach."
Write-Host "5: Wcisnij '5' do stworzenia raportu o zainstlowanych rolach i
funkcjach."
Write-Host "6: Wcisnij '6' do stworzenia raportu o udostepnionych zasobach
sieciowych."
Write-Host "7: Wcisnij '7' do stworzenia raportu o 5 Event Logach z grup
System, Security,Autoruns,Directory Service,Application,Windows PowerShell ."
Write-Host "Q: Wcisnij 'Q' to quit."
}

do
{
Menu
if (-not (Test-Path 'C:\WAT\damian_woszczak') ){
New-Item -Path 'C:\WAT\damian_woszczak' -ItemType Directory
}
$path = 'C:\WAT\damian_woszczak'
[string]$data = Get-Date
$data
$autor = " `n Autor:Damian Woszczak"
$info = $data + $autor

$input = Read-Host "Wybierz raport do utworzenia"


switch ($input)
{
'1' {
cls
'Wybrales #1'
raport-domena
} '2' {
cls
'Wybrales #2'
raport-dns
} '3' {
cls
'Wybrales #3'
raport-ptr
} '4' {
cls
'Wybrales #4'
raport-uslugi
} '5' {
cls
'Wybrales #5'
raport-role
} '6' {
cls
'Wybrales #6'
raport-smb
} '7' {
cls
'Wybrales #7'
event-logs
} 'q' {
return
}
}
pause
}
until ($input -eq 'q')

You might also like