-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from LarryWisherMan/feature/ModuleUpdates
Feature/module updates
- Loading branch information
Showing
88 changed files
with
6,895 additions
and
2,751 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
param( | ||
[string]$FolderPath, # Accept a folder path | ||
[string]$ExportTo # Export to a single destination file | ||
) | ||
|
||
# Ensure the export folder exists if exporting to a directory | ||
$exportFolderPath = Split-Path $ExportTo | ||
if (-not (Test-Path -Path $exportFolderPath)) | ||
{ | ||
New-Item -Path $exportFolderPath -ItemType Directory | ||
} | ||
|
||
# If the export file doesn't exist, create an empty file | ||
if (-not (Test-Path -Path $ExportTo)) | ||
{ | ||
New-Item -Path $ExportTo -ItemType File | ||
} | ||
|
||
$combinedContent = "" | ||
|
||
# Get all .ps1 files in the folder | ||
$FunctionFiles = Get-ChildItem -Path $FolderPath -Filter *.ps1 | ||
|
||
foreach ($FunctionFile in $FunctionFiles) | ||
{ | ||
# Read the contents of the function file | ||
$functionsContent = Get-Content -Path $FunctionFile.FullName -Raw | ||
|
||
# Use a regular expression to match each function in the file | ||
$functionPattern = 'function\s+([^\s]+)\s*{[^{}]*((?>[^{}]+|(?<open>{)|(?<-open>}))*(?(open)(?!)))\s*}' | ||
$matches = [regex]::Matches($functionsContent, $functionPattern) | ||
|
||
foreach ($match in $matches) | ||
{ | ||
# Capture the function name and its entire content | ||
$functionName = $match.Groups[1].Value | ||
$functionBody = $match.Value | ||
|
||
# Append each function to the combined content | ||
$combinedContent += "`n`n# Function: $functionName from file $($FunctionFile.FullName)`n" | ||
$combinedContent += $functionBody | ||
} | ||
} | ||
|
||
# Export all functions to the single export file | ||
Set-Content -Path $ExportTo -Value $combinedContent -Force # Force overwrites existing file | ||
|
||
Write-Host "Exported all functions from provided folder to $ExportTo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
param( | ||
[string]$FunctionFile, | ||
[string]$ExportTo | ||
) | ||
|
||
# Ensure the export folder exists if exporting to a directory | ||
if (-not (Test-Path -Path $ExportTo)) | ||
{ | ||
$exportFolderPath = Split-Path $ExportTo | ||
if (-not (Test-Path -Path $exportFolderPath)) | ||
{ | ||
New-Item -Path $exportFolderPath -ItemType Directory | ||
} | ||
} | ||
|
||
# Read the contents of the function file | ||
$functionsContent = Get-Content -Path $FunctionFile -Raw | ||
|
||
# Use a regular expression to match each function in the file | ||
$functionPattern = 'function\s+([^\s]+)\s*{[^{}]*((?>[^{}]+|(?<open>{)|(?<-open>}))*(?(open)(?!)))\s*}' | ||
$matches = [regex]::Matches($functionsContent, $functionPattern) | ||
|
||
$combinedContent = "" | ||
|
||
foreach ($match in $matches) | ||
{ | ||
# Capture the function name and its entire content | ||
$functionName = $match.Groups[1].Value | ||
$functionBody = $match.Value | ||
|
||
# Append each function to the combined content | ||
$combinedContent += "`n`n# Function: $functionName`n" | ||
$combinedContent += $functionBody | ||
} | ||
|
||
# Export all functions to the single export file | ||
Set-Content -Path $ExportTo -Value $combinedContent | ||
|
||
Write-Host "Exported all functions to $ExportTo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
param( | ||
[string]$FunctionFile, # The input file containing multiple functions | ||
[string]$ExportTo # The export folder for individual function files | ||
) | ||
|
||
# Ensure the export folder exists | ||
if (-not (Test-Path -Path $ExportTo)) | ||
{ | ||
New-Item -Path $ExportTo -ItemType Directory -Force | ||
} | ||
|
||
# Read the contents of the function file | ||
$functionsContent = Get-Content -Path $FunctionFile -Raw | ||
|
||
# Use a regular expression to match each function in the file | ||
$functionPattern = 'function\s+([^\s]+)\s*{[^{}]*((?>[^{}]+|(?<open>{)|(?<-open>}))*(?(open)(?!)))\s*}' | ||
$matches = [regex]::Matches($functionsContent, $functionPattern) | ||
|
||
foreach ($match in $matches) | ||
{ | ||
# Capture the function name and its entire content | ||
$functionName = $match.Groups[1].Value | ||
$functionBody = $match.Value | ||
|
||
# Define the export file path for each function | ||
$exportFilePath = Join-Path -Path $ExportTo -ChildPath "$functionName.ps1" | ||
|
||
# Ensure the directory exists for the file path (especially if nested directories are involved) | ||
$exportFolder = Split-Path -Path $exportFilePath -Parent | ||
if (-not (Test-Path -Path $exportFolder)) | ||
{ | ||
New-Item -Path $exportFolder -ItemType Directory -Force | ||
} | ||
|
||
# Export the function to its own file | ||
Set-Content -Path $exportFilePath -Value $functionBody | ||
|
||
Write-Host "Exported $functionName to $exportFilePath" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
class RegUserProfile { | ||
[string]$SID | ||
[string]$ProfilePath | ||
[bool]$IsOrphaned | ||
[string]$OrphanReason | ||
[string]$ComputerName | ||
[bool]$IsSpecial | ||
[bool]$IsLoaded | ||
[string]$UserName | ||
[string]$Domain | ||
[datetime]$LastLogonDate | ||
[long]$ProfileSize | ||
[string]$ProfileType | ||
[datetime]$CreatedDate | ||
[string]$ProfileStatus | ||
[bool]$IsTemporary | ||
[bool]$IsCorrupted | ||
[string[]]$SecurityGroups | ||
[string]$HomeDirectory | ||
[bool]$IsEncrypted | ||
[string]$ProfileState | ||
[string]$LastUsedApp | ||
[bool]$HasBackup | ||
[bool]$IsRoaming | ||
[datetime]$LastModifiedDate | ||
[bool]$IsAdminProfile | ||
|
||
# New properties | ||
[bool]$HasUserFolder # Indicates if the user's folder exists | ||
[datetime]$Created # The DateTime when the object was instantiated | ||
|
||
# Constructor | ||
RegUserProfile( | ||
[string]$SID, | ||
[string]$ProfilePath, | ||
[bool]$IsOrphaned, | ||
[string]$OrphanReason = $null, | ||
[string]$ComputerName, | ||
[bool]$IsSpecial, | ||
[bool]$IsLoaded, | ||
[string]$UserName, | ||
[string]$Domain, | ||
[datetime]$LastLogonDate, | ||
[long]$ProfileSize, | ||
[string]$ProfileType, | ||
[datetime]$CreatedDate, | ||
[string]$ProfileStatus, | ||
[bool]$IsTemporary, | ||
[bool]$IsCorrupted, | ||
[string[]]$SecurityGroups, | ||
[string]$HomeDirectory, | ||
[bool]$IsEncrypted, | ||
[string]$ProfileState, | ||
[string]$LastUsedApp, | ||
[bool]$HasBackup, | ||
[bool]$IsRoaming, | ||
[datetime]$LastModifiedDate, | ||
[bool]$IsAdminProfile, | ||
[bool]$HasUserFolder # New property | ||
) { | ||
# Initialize all properties | ||
$this.SID = $SID | ||
$this.ProfilePath = $ProfilePath | ||
$this.IsOrphaned = $IsOrphaned | ||
$this.OrphanReason = $OrphanReason | ||
$this.ComputerName = $ComputerName | ||
$this.IsSpecial = $IsSpecial | ||
$this.IsLoaded = $IsLoaded | ||
$this.UserName = $UserName | ||
$this.Domain = $Domain | ||
$this.LastLogonDate = $LastLogonDate | ||
$this.ProfileSize = $ProfileSize | ||
$this.ProfileType = $ProfileType | ||
$this.CreatedDate = $CreatedDate | ||
$this.ProfileStatus = $ProfileStatus | ||
$this.IsTemporary = $IsTemporary | ||
$this.IsCorrupted = $IsCorrupted | ||
$this.SecurityGroups = $SecurityGroups | ||
$this.HomeDirectory = $HomeDirectory | ||
$this.IsEncrypted = $IsEncrypted | ||
$this.ProfileState = $ProfileState | ||
$this.LastUsedApp = $LastUsedApp | ||
$this.HasBackup = $HasBackup | ||
$this.IsRoaming = $IsRoaming | ||
$this.LastModifiedDate = $LastModifiedDate | ||
$this.IsAdminProfile = $IsAdminProfile | ||
$this.HasUserFolder = $HasUserFolder | ||
$this.Created = [DateTime]::Now # Automatically set when object is created | ||
} | ||
|
||
# JSON Serialization Example | ||
[string] ToJson() { | ||
$properties = @{ | ||
SID = $this.SID | ||
ProfilePath = $this.ProfilePath | ||
IsOrphaned = $this.IsOrphaned | ||
OrphanReason = $this.OrphanReason | ||
ComputerName = $this.ComputerName | ||
IsSpecial = $this.IsSpecial | ||
IsLoaded = $this.IsLoaded | ||
UserName = $this.UserName | ||
Domain = $this.Domain | ||
LastLogonDate = $this.LastLogonDate | ||
ProfileSize = $this.ProfileSize | ||
ProfileType = $this.ProfileType | ||
CreatedDate = $this.CreatedDate | ||
ProfileStatus = $this.ProfileStatus | ||
IsTemporary = $this.IsTemporary | ||
IsCorrupted = $this.IsCorrupted | ||
SecurityGroups = $this.SecurityGroups | ||
HomeDirectory = $this.HomeDirectory | ||
IsEncrypted = $this.IsEncrypted | ||
ProfileState = $this.ProfileState | ||
LastUsedApp = $this.LastUsedApp | ||
HasBackup = $this.HasBackup | ||
IsRoaming = $this.IsRoaming | ||
LastModifiedDate = $this.LastModifiedDate | ||
IsAdminProfile = $this.IsAdminProfile | ||
HasUserFolder = $this.HasUserFolder | ||
Created = $this.Created # Include the new Created DateTime property | ||
} | ||
return $properties | ConvertTo-Json | ||
} | ||
} |
Oops, something went wrong.