These are just random notes and programs that may have incomplete descriptions. Any scripts or programs use at your risk
Friday, March 17, 2023
Powershell: Get all DNS records from AD DNS
Import-Module DnsServer
# Set the output folder
$outputFolder = "C:\temp\Final"
$DNSServer = DNSServer.com
# Get all DNS zones
$zones = Get-DnsServerZone -ComputerName $DNSServer
# Loop through each zone and export its records to a separate CSV file
foreach ($zone in $zones) {
$records = Get-DnsServerResourceRecord -ZoneName $zone.ZoneName -ComputerName $DNSServer| `
select hostname,`
recordtype,`
type,timestamp,`
timetolive,`
@{n='Data';e={$rr = $_;`
switch ($rr.RecordType) {
'A' {$rr.RecordData.IPv4Address}
'CNAME' {$rr.RecordData.HostnameAlias}
'NS' {$rr.RecordData.NameServer}
'SOA' {$rr.RecordData.PrimaryServer}
'SRV' {$rr.RecordData.DomainName}
'PTR' {$rr.RecordData.PtrDomainName}
'MX' {$rr.RecordData.MailExchange}
'AAAA' {$rr.RecordData.IPv6Address}
'TXT' {$rr.RecordData.DescriptiveText}
}}}
$outputFile = "$outputFolder\$($zone.ZoneName).csv"
$records | Export-Csv -NoTypeInformation -path $outputFile
}
# Output confirmation message
Write-Host "DNS records exported to $outputFolder."
Thursday, February 2, 2023
Powershell: AD DHCP scope information
Needed a script to export dhcp scope and scope id for a domain.
$report = @()
$DHCPServer = DHCPServerHostname
$scopes =Get-DhcpServerv4Scope -ComputerName $DHCPServer
foreach ($scope in $Scopes){
$scopeID = $scope.ScopeId
$report += Get-DhcpServerv4OptionValue -ScopeId $scopeID -ComputerName $DHCPServer |`
select @{name="ScopeID";e={$scopeID}},OptionID,Name,Type,@{Name="Value";e={$_.value -join ";"}
}
$report | export-csv -NoTypeInformation -path "c:\temp\DHCPScopeIDwithOption.csv"
$scopes | export-csv -NoTypeInformation -path "c:\temp\DHCPScopeIDwithMask.csv"
Monday, August 9, 2021
Powershell - Extract ADFS certificates from ADFS server
Wrote script so people specify the adfs server and the signature and encryption certificate will extract the certs to two files stored in c:\temp
# just put in the ADFS server name
$AdfsServer = 'adfs.microsoft.com'
[xml]$XmlDocument = (New-Object System.Net.WebClient).DownloadString("https://$AdfsServer/FederationMetadata/2007-06/FederationMetadata.xml")
#ADFS Signing Certificate
$Cert = $xmldocument.entitydescriptor.roledescriptor.keydescriptor | select Use,@{Name="x509"; Expression={(($_.keyinfo).X509data).x509certificate}}
#Sign Cert
$cert | ? {$_.use -eq "signing"} | select -ExpandProperty x509 | out-file c:\temp\Signcert.cer
#Encryption Cert
$cert | ? {$_.use -eq "encryption"} | select -ExpandProperty x509 | out-file c:\temp\Encryptioncert.cer
$Cert
Wednesday, July 29, 2020
Powershell - Get certificate information
List Certificate Templates
function get-CertificateTemplates {
[CmdletBinding()] Param (
[Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)]
[string]$forest
)
$DefaultPartition = Get-ADDomainController -Server $forest | select -expand DefaultPartition
$configcontext = "CN=Configuration,$($DefaultPartition)"
$ADSI = [ADSI]"LDAP://CN=Certificate Templates,CN=Public Key Services,CN=Services,$ConfigContext"
$ADSI.Children | Sort-Object Name | Select-Object DisplayName, Name, msPKI-Cert-Template-OID
}
List Certificate CDP info
function get-CertificateCDP {
[CmdletBinding()] Param (
[Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)]
[string]$forest
)
$DefaultPartition = Get-ADDomainController -Server $forest | select -expand DefaultPartition
$configcontext = "CN=Configuration,$($DefaultPartition)"
$ADSI = [ADSI]"LDAP://CN=cdp,CN=Public Key Services,CN=Services,$ConfigContext"
$ADSI.Children | select cn,Children,path
}
List Certificate Auhtorities in forest - requires activedirectory module
function get-CertificationAuthorities {
[CmdletBinding()] Param (
[Parameter(Mandatory = $True, ValueFromPipelineByPropertyName = $True)]
[string]$forest
)
$DefaultPartition = Get-ADDomainController -Server $forest | select -expand DefaultPartition
$configcontext = "CN=Configuration,$($DefaultPartition)"
$ADSI = [ADSI]"LDAP://CN=Certification Authorities,CN=Public Key Services,CN=Services,$ConfigContext"
$ADSI.Children | select name,whenCreated
}
Monday, June 29, 2020
Powershell : get-ADReplicationReport - Function to get replication status from specified domain controller
.Synopsis
Get Active Directory replication report
DESCRIPTION
reports on replication issues
EXAMPLE
get-ADReplicationReport -domains "Domain1","Domain2"
function get-QrgADReplicationReport
{
[CmdletBinding()]
[Alias()]
[OutputType([int])]
Param
(
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[string]$Server
)
Begin
{
}
Process
{
Get-ADReplicationPartnerMetadata -Target $server -Partition * | select `
Server,`
@{Name = 'Partner';Expression = {$_.Partner.split(",")[1].split("=")[1]}},`
Partition,`
LastReplicationSuccess,`
ConsecutiveReplicationFailures,`
PartnerType,`
PartnerAddress,`
PartnerGuid
}
End
{
}
}
Wednesday, June 5, 2019
Powershell : Function to get FSMO Info for a domain
function Get-DomainFSMO
{
[CmdletBinding()]
[OutputType([System.Management.ManagementObject])]
param
(
[parameter( Mandatory=$false,
ValueFromPipeline=$True,
Position = 0,
HelpMessage="An array of domains.",
ValueFromPipelineByPropertyName=$True)]
[String[]] $domain
)
begin{Write-Verbose "Getting Forest info for: $CurrentDomain"}
process{
foreach ($CurrentDomain in $domain){
$dom = @{
label="Domain"
expression = {$CurrentDomain}
}
Write-Verbose "Getting Forest info for: $CurrentDomain"
Get-ADDomain -Server $CurrentDomain | Select-Object $dom,InfrastructureMaster, RIDMaster, PDCEmulator,DomainMode,DomainSid
}
}
end{}
}
Friday, July 27, 2018
vmware - Powershell get hardware inventory
PowerState : PoweredOn Version : 6.0.0 NumCpu : 12 Cluster : Clustername MaxEVCMode : intel-haswell vCenter : vcentername Name : esxi host name Build : buildnumber CpuCoreCountTotal : 12 Model : Hardware model number MemoryTotalGB : Total memory of esxi host CpuModel : cpu model MemoryUsageGB : memory usage at time of report SerialNumber : esxi host serial number ConnectionState : ConnectedPrior to running this make sure you are up to date on your vmware powercli via
Install-Module -Name VMware.PowerCLI Import-Module VMware.VimAutomation.Core Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false Set-PowerCLIConfiguration -InvalidCertificateAction ignore -confirm:$false Update-Module -Name VMware.PowerCLI
$vcenter = "vcenterhostname"
#Tony Unger
#Requires -Version 5
<#If script fails try to run the following commands
Install-Module -Name VMware.PowerCLI
Import-Module VMware.VimAutomation.Core
Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false
Set-PowerCLIConfiguration -InvalidCertificateAction ignore -confirm:$false
Update-Module -Name VMware.PowerCLI
#>
& 'C:\Program Files (x86)\VMware\Infrastructure\PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1'
$report =@()
Connect-VIServer -Server $vcenter
$vmHosts = get-vmhost | select Name,`
ConnectionState,`
PowerState,`
NumCpu,`
MemoryUsageGB,`
MemoryTotalGB,`
Version,`
Build,`
MaxEVCMode,`
@{N="Cluster";E={ $_.Parent}},`
@{N="vCenter";E={ ($_.uid).split("@")[1].split(":")[0]}}
foreach ($vmHost in $vmHosts) {
$VMHardwareInfo = get-vmhosthardware -vmhost $vmHost.name |select Manufacturer,`
Model,`
SerialNumber,`
CpuModel,`
CpuCoreCountTotal
$ESXiInfo = New-Object -TypeName PSObject -Property @{
Name = $vmHost.name
ConnectionState = $vmHost.ConnectionState
PowerState = $vmHost.PowerState
NumCpu = $vmHost.NumCpu
MemoryUsageGB = $vmHost.MemoryUsageGB
MemoryTotalGB = $vmHost.MemoryTotalGB
Version = $vmHost.Version
Build = $vmHost.Build
MaxEVCMode = $vmHost.MaxEVCMode
Cluster = $vmHost.Cluster
vCenter = $vmHost.vCenter
Model = $VMHardwareInfo.Model
SerialNumber = $VMHardwareInfo.SerialNumber
CpuModel = $VMHardwareInfo.CpuModel
CpuCoreCountTotal = $VMHardwareInfo.CpuCoreCountTotal
}
$report += $ESXiInfo
}
$report | export-csv -path c:\temp\ESXiHardwareInfo.csv -notype
Powershell: Microsoft Graph to add new roles to application registration
PowerShell Script Bulk add new roles to application registration in azure. Update $roles with ,Us...
-
Here is an excel document I created that will ping a list of nodes in column A and give results in column B. There are much better tools th...
-
#reads event logs for filter and exports to $Date = ( Get-Date ).AddMinutes(-30) $LogName = 'Security' $ProviderName = ...
-
This is a KQL written for Azure Sentinel. Purpose is to search for eventid from Active Directory Domain Services related to Group objects....