Skip to content

Commit

Permalink
feat: add synopsis and script desctiption
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivica Agatunovic committed Jul 26, 2024
1 parent 8c52118 commit 5ba07f1
Show file tree
Hide file tree
Showing 9 changed files with 365 additions and 106 deletions.
36 changes: 34 additions & 2 deletions copy-with-progress-to-remote-vms.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
#Usage:
# Copy-WithProgress -Source "C:\projects" -Destination "U:\Backup\test"
<#
.SYNOPSIS
Copies files from a specified source directory to a destination directory on remote computers with progress reporting.
.DESCRIPTION
This script defines a function `Copy-WithProgress` that:
1. Takes a source directory, a destination directory, and a list of remote hosts.
2. Connects to each remote host using a PowerShell session.
3. Copies files from the source directory to the destination directory on each remote host.
4. Displays progress information for each file being copied.
.PARAMETER Source
The path to the source directory on the local machine from which files will be copied.
.PARAMETER Destination
The path to the destination directory on the remote computers where files will be copied to.
.PARAMETER RemoteHost
An array of remote computer names or IP addresses to which files will be copied.
.EXAMPLE
Copy-WithProgress -Source "C:\projects" -Destination "U:\Backup\test" -RemoteHost "vm1", "vm2"
This example copies files from "C:\projects" on the local machine to "U:\Backup\test" on the remote computers "vm1" and "vm2".
Progress is displayed for each file being copied.
.NOTES
- The function uses PowerShell remoting (New-PSSession) to connect to remote computers.
- Ensure that PowerShell remoting is enabled and properly configured on the remote computers.
- The `-UseSSL` parameter in `New-PSSession` requires that the remote session be secured with SSL.
Author : Ivica Agatunovic
WebSite: https://github.com/ivicaagatunovic
Linkedin: www.linkedin.com/in/ivica-agatunovic-96090024
#>
Function Copy-WithProgress
{
[CmdletBinding()]
Expand Down
92 changes: 92 additions & 0 deletions enable-disable-secure-boot-vmware.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
<#
.SYNOPSIS
This script manages VM secure boot settings in a VMware environment.
It includes functions to sort servers by data center, check and update secure boot settings, and manage VM power states as necessary.
.DESCRIPTION
The script contains functions to:
1. Categorize servers into different data centers based on naming conventions.
2. Retrieve and update the secure boot setting of virtual machines (VMs).
3. Disable or enable secure boot on VMs, handling VM power state transitions as needed.
4. Connect to specified vCenter servers to apply configuration changes.
.EXAMPLE
$cred = Get-Credential
$unsortedArray = 'ivica01.domain.local', 'ivica02.domain.local'
$sortedServerHash = triage-dc -serverArray $unsortedArray
enable-vmsecureboot -serverArray $sortedServerHash.dc2 -vcenter 'vcenter02.domain.local' -cred $cred
This example sorts the provided server array by data center and enables secure boot on VMs located in data center 'dc2' using the specified vCenter server.
.NOTES
Ensure that VMware PowerCLI is installed and properly configured.
Update the `$unsortedArray` and vCenter server addresses according to your environment's requirements.
Author : Ivica Agatunovic
WebSite: https://github.com/ivicaagatunovic
Linkedin: www.linkedin.com/in/ivica-agatunovic-96090024
#>

function triage-dc(){
<#
.SYNOPSIS
Sorts an array of server names into different data centers based on naming patterns.
.DESCRIPTION
This function takes an array of server names and sorts them into a hashtable where the keys are data center names and the values are arrays of server names belonging to each data center. The sorting is done based on regex patterns matching the server names.
.PARAMETER serverArray
An array of server names to be sorted.
.OUTPUTS
A hashtable where keys are data center names (e.g., 'dc1', 'dc2', 'dc3') and values are arrays of server names that match the respective data center pattern.
#>
param(
[String[]]$serverArray
)
Expand All @@ -18,6 +59,19 @@ function triage-dc(){
}

Function get-vmsecureboot {
<#
.SYNOPSIS
Retrieves the secure boot status of a virtual machine.
.DESCRIPTION
This function checks whether secure boot is enabled or disabled on a VM by inspecting its boot options.
.PARAMETER vm
The virtual machine object for which the secure boot status is to be retrieved.
.OUTPUTS
Returns a string indicating the secure boot status: 'enabled' or 'disabled'.
#>
param(
[Parameter(
Mandatory = $true,
Expand All @@ -33,6 +87,25 @@ Function get-vmsecureboot {
}

function disable-vmsecureboot() {
<#
.SYNOPSIS
Disables secure boot on specified VMs by connecting to a vCenter server.
.DESCRIPTION
This function connects to the specified vCenter server, retrieves VMs from the provided server array, and disables secure boot on them. It handles VM power state transitions, ensuring VMs are powered off before making configuration changes, and then restarts them if necessary.
.PARAMETER serverArray
An array of server names whose secure boot settings are to be disabled.
.PARAMETER vcenter
The vCenter server to connect to for applying the secure boot settings.
.PARAMETER cred
The credentials used to authenticate with the vCenter server.
.OUTPUTS
Writes status messages indicating the progress and outcome of the secure boot configuration changes.
#>
param(
[Parameter(Mandatory)]
[String[]]$serverArray,
Expand Down Expand Up @@ -75,6 +148,25 @@ function disable-vmsecureboot() {
}

function enable-vmsecureboot() {
<#
.SYNOPSIS
Enables secure boot on specified VMs by connecting to a vCenter server.
.DESCRIPTION
This function connects to the specified vCenter server, retrieves VMs from the provided server array, and enables secure boot on them. It handles VM power state transitions, ensuring VMs are powered off before making configuration changes, and then restarts them if necessary.
.PARAMETER serverArray
An array of server names whose secure boot settings are to be enabled.
.PARAMETER vcenter
The vCenter server to connect to for applying the secure boot settings.
.PARAMETER cred
The credentials used to authenticate with the vCenter server.
.OUTPUTS
Writes status messages indicating the progress and outcome of the secure boot configuration changes.
#>
param(
[Parameter(Mandatory)]
[String[]]$serverArray,
Expand Down
9 changes: 7 additions & 2 deletions install-subca.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Function Install-SubCA {
<#
.SYNOPSIS
This function will install PKI SubCA.
Expand All @@ -16,7 +15,13 @@ Function Install-SubCA {
The CRL File path where CRL are published (Default is C:\Windows\System32\CertSrv\CertEnroll)
.PARAMETER CRLURLPath
The CRL URL Path registered as CRL/AIA extensions in client certificates generated Ex: "pki.domain.local")
#>
.NOTES
Author : Ivica Agatunovic
WebSite: https://github.com/ivicaagatunovic
Linkedin: www.linkedin.com/in/ivica-agatunovic-96090024
#>
Function Install-SubCA {

[CmdletBinding()]
param (
Expand Down
85 changes: 41 additions & 44 deletions installed-apps-report.ps1
Original file line number Diff line number Diff line change
@@ -1,47 +1,44 @@
# This script generates a report of installed applications on a Windows system and uploads it to an S3 bucket.
#
# Summary:
# The script performs the following tasks:
# 1. Retrieves system details such as FQDN, computer name, and OS version.
# 2. Creates an event log source if it doesn't already exist.
# 3. Defines a function to get installed applications from the registry.
# 4. Determines the OS architecture and fetches applications accordingly.
# 5. Formats the application data and outputs it to the console, a CSV file, or a GridView.
# 6. Imports required PowerShell modules for AWS S3 operations.
# 7. Generates the installed applications report and logs the event.
# 8. Uploads the generated report to an S3 bucket.
# 9. Logs the success or failure of the upload operation.
#
# Variables:
# - $fqdn: Fully Qualified Domain Name of the computer.
# - $computername: Name of the computer.
# - $osversion: Operating system version.
# - $EndpointUrl: S3 bucket endpoint URL.
# - $reportKey: Access key for the S3 bucket.
# - $reportSecret: Secret key for the S3 bucket.
# - $reportpath: Path to save the generated report.
# - $eventidreport: Event ID for report generation.
# - $eventidupload: Event ID for a successful upload.
# - $eventiduploaderror: Event ID for upload error.
# - $modules: List of PowerShell modules required for the script.
#
# Functions:
# - Get-InstalledApplication: Retrieves installed applications from the registry.
# - Import-PSModule: Imports the required PowerShell modules if not already imported.
#
# Example Usage:
# - To generate and upload a report of installed applications:
# Run the script without any parameters.
#
# - To view the installed applications in a GridView:
# Modify the 'Get-InstalledApplication' call to use '-OutputType 'GridView''.
#
# - To output the installed applications to the console:
# Modify the 'Get-InstalledApplication' call to use '-OutputType 'Console''.
#
# Notes:
# - Ensure the required AWS Tools PowerShell modules are installed and available.
# - Ensure the appropriate permissions are set for the S3 bucket access.
<#
.SYNOPSIS
Generates a report of installed applications on a Windows system and uploads it to an S3 bucket.
.DESCRIPTION
This script performs the following tasks:
1. Retrieves system details such as FQDN, computer name, and OS version.
2. Creates an event log source if it doesn't already exist.
3. Defines a function to get installed applications from the registry.
4. Determines the OS architecture and fetches applications accordingly.
5. Formats the application data and outputs it to the console, a CSV file, or a GridView.
6. Imports required PowerShell modules for AWS S3 operations.
7. Generates the installed applications report and logs the event.
8. Uploads the generated report to an S3 bucket.
9. Logs the success or failure of the upload operation.
.FUNCTION Get-InstalledApplication
Retrieves installed applications from the registry.
.FUNCTION Import-PSModule
Imports the required PowerShell modules if not already imported.
.EXAMPLE
To generate and upload a report of installed applications:
Run the script without any parameters.
.EXAMPLE
To view the installed applications in a GridView:
Modify the 'Get-InstalledApplication' call to use '-OutputType 'GridView''.
.EXAMPLE
To output the installed applications to the console:
Modify the 'Get-InstalledApplication' call to use '-OutputType 'Console''.
.NOTES
- Ensure the required AWS Tools PowerShell modules are installed and available.
- Ensure the appropriate permissions are set for the S3 bucket access.
Author : Ivica Agatunovic
WebSite: https://github.com/ivicaagatunovic
Linkedin: www.linkedin.com/in/ivica-agatunovic-96090024
#>

$fqdn = ([System.Net.Dns]::GetHostByName(($env:computerName))).hostname
$computername = $env:computerName
Expand Down
77 changes: 62 additions & 15 deletions mof-cleanup.ps1
Original file line number Diff line number Diff line change
@@ -1,21 +1,68 @@
#Cleanup .json and .mof files present in the C:\Windows\System32\Configuration\ConfigurationStatus
$cleanuppath = "C:\Windows\System32\Configuration\ConfigurationStatus"
$historyindays = 10
$date = ([System.DateTime]::Now).AddDays(-$historyindays)
$eventidstart = 777
$eventidend = 888
$eventiderror = 999
<#
.SYNOPSIS
Cleans up .json and .mof files in the specified directory older than a specified number of days.
New-EventLog -LogName 'Application' -Source 'DSC_CLEANUP' -ErrorAction SilentlyContinue
Write-EventLog -LogName 'Application' -Source 'DSC_CLEANUP' -EntryType Information -EventID $eventidstart -Message "DSC Files Cleanup Started"
.DESCRIPTION
This function performs the following tasks:
1. Initializes event logging.
2. Logs the start of the cleanup process.
3. Deletes .json and .mof files older than the specified number of days in the given directory.
4. Logs the completion of the cleanup process.
5. Handles exceptions and logs any errors encountered during the process.
.PARAMETER CleanupPath
The path to the directory where the cleanup will be performed. Default is "C:\Windows\System32\Configuration\ConfigurationStatus".
.PARAMETER HistoryInDays
The number of days to retain files. Files older than this will be deleted. Default is 10 days.
.PARAMETER EventIDStart
The event ID used to log the start of the cleanup process. Default is 777.
.PARAMETER EventIDEnd
The event ID used to log the successful completion of the cleanup process. Default is 888.
.PARAMETER EventIDError
The event ID used to log any errors encountered during the cleanup process. Default is 999.
.EXAMPLE
Cleanup-DSCFiles -CleanupPath "C:\Windows\System32\Configuration\ConfigurationStatus" -HistoryInDays 10
.NOTES
Author : Ivica Agatunovic
WebSite: https://github.com/ivicaagatunovic
Linkedin: www.linkedin.com/in/ivica-agatunovic-96090024
- Ensure the script is run with appropriate permissions to delete files in the specified directory.
- The script logs events in the Application log with the source 'DSC_CLEANUP'.
#>

function Cleanup-DSCFiles {
[CmdletBinding()]
param (
[string]$CleanupPath = "C:\Windows\System32\Configuration\ConfigurationStatus",
[int]$HistoryInDays = 10,
[int]$EventIDStart = 777,
[int]$EventIDEnd = 888,
[int]$EventIDError = 999
)

$date = ([System.DateTime]::Now).AddDays(-$HistoryInDays)

New-EventLog -LogName 'Application' -Source 'DSC_CLEANUP' -ErrorAction SilentlyContinue
Write-EventLog -LogName 'Application' -Source 'DSC_CLEANUP' -EntryType Information -EventID $EventIDStart -Message "DSC Files Cleanup Started"

try {
foreach ($mof in ([System.IO.Directory]::EnumerateFiles("C:\Windows\System32\Configuration\ConfigurationStatus", "*.*", "AllDirectories").Where({[System.IO.File]::GetLastWriteTime($_) -le $date})))
{ [System.IO.File]::Delete($mof) }
Write-EventLog -LogName 'Application' -Source 'DSC_CLEANUP' -EntryType Information -EventID $eventidend -Message "DSC Files Cleanup Finished"
foreach ($file in ([System.IO.Directory]::EnumerateFiles($CleanupPath, "*.*", "AllDirectories").Where({[System.IO.File]::GetLastWriteTime($_) -le $date}))) {
[System.IO.File]::Delete($file)
}
Write-EventLog -LogName 'Application' -Source 'DSC_CLEANUP' -EntryType Information -EventID $EventIDEnd -Message "DSC Files Cleanup Finished"
}

catch {
Throw "-=== Something went wrong [$($Error[0])] ===-"
Write-EventLog -LogName 'Application' -Source 'DSC_CLEANUP' -EntryType Information -EventID $eventiderror -Message "DSC Files Cleanup Failed due to: [$($Error[0])]!!!"
Write-EventLog -LogName 'Application' -Source 'DSC_CLEANUP' -EntryType Error -EventID $EventIDError -Message "DSC Files Cleanup Failed due to: [$($_.Exception.Message)]"
Throw "-=== Something went wrong [$($_.Exception.Message)] ===-"
}
}

# Example usage of the function
# Cleanup-DSCFiles -CleanupPath "C:\Windows\System32\Configuration\ConfigurationStatus" -HistoryInDays 10
Loading

0 comments on commit 5ba07f1

Please sign in to comment.