Modules/WisherTools.Helpers/0.1.0/WisherTools.Helpers.psm1
#Region './Classes/1.class1.ps1' -1 class Class1 { [string]$Name = 'Class1' Class1() { #default Constructor } [String] ToString() { # Typo "calss" is intentional return ( 'This calss is {0}' -f $this.Name) } } #EndRegion './Classes/1.class1.ps1' 16 #Region './Classes/2.class2.ps1' -1 class Class2 { [string]$Name = 'Class2' Class2() { #default constructor } [String] ToString() { return ( 'This calss is {0}' -f $this.Name) } } #EndRegion './Classes/2.class2.ps1' 15 #Region './Classes/3.class11.ps1' -1 class Class11 : Class1 { [string]$Name = 'Class11' Class11 () { } [String] ToString() { return ( 'This calss is {0}:{1}' -f $this.Name,'class1') } } #EndRegion './Classes/3.class11.ps1' 14 #Region './Classes/4.class12.ps1' -1 class Class12 : Class1 { [string]$Name = 'Class12' Class12 () { } [String] ToString() { return ( 'This calss is {0}:{1}' -f $this.Name,'class1') } } #EndRegion './Classes/4.class12.ps1' 14 #Region './Public/Get-BackupFilePath.ps1' -1 function Get-BackupFilePath { param ( [string]$BackupDirectory = "C:\LHStuff\UserProfileTools\RegProfBackup", [string]$Prefix = "ProfileListBackup" ) # Generate a unique backup file name with timestamp $dateTimeStamp = (Get-Date -Format "yyyyMMdd_HHmmss") $backupFileName = "$Prefix`_$dateTimeStamp.reg" $backupPath = Join-Path -Path $BackupDirectory -ChildPath $backupFileName return $backupPath } #EndRegion './Public/Get-BackupFilePath.ps1' 14 #Region './Public/Get-DirectoryPath.ps1' -1 function Get-DirectoryPath { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [string]$BasePath, [Parameter(Mandatory = $true)] [string]$ComputerName, [Parameter(Mandatory = $true)] [bool]$IsLocal # Determines whether to return local or UNC format ) if ($IsLocal) { # Convert UNC to local format $localPath = $BasePath -replace '(?:.+)\\([a-zA-Z])\$\\', '$1:\' return $localPath } else { # Convert local path to UNC format $uncPath = $BasePath -replace '^([a-zA-Z]):\\', "\\$ComputerName\`$1`$\" return $uncPath } } #EndRegion './Public/Get-DirectoryPath.ps1' 25 #Region './Public/Get-FunctionScriptBlock.ps1' -1 function Get-FunctionScriptBlock { param ( [string]$FunctionName ) try { # Get the current definition (body) of the specified function dynamically $functionBody = (Get-Command -Name $FunctionName).Definition if (-not $functionBody) { throw "Function '$FunctionName' does not exist." } # Create the full function definition as a script block $fullFunctionScript = @" function $FunctionName { $functionBody } "@ return $fullFunctionScript } catch { Write-Error "Failed to retrieve the function '$FunctionName'. Error: $_" return $null } } #EndRegion './Public/Get-FunctionScriptBlock.ps1' 27 #Region './Public/Test-ComputerPing.ps1' -1 function Test-ComputerPing { [CmdletBinding()] param ( [Parameter(Mandatory = $true)] [string]$ComputerName, [Parameter(Mandatory = $false)] [int]$Timeout = 2000 # Default timeout is 4000 ms (4 seconds) ) try { # Build the filter query to include the address and timeout $query = "Address='$ComputerName' AND Timeout=$Timeout" # Use Get-CimInstance to ping the computer with a timeout $pingResult = Get-CimInstance -ClassName Win32_PingStatus ` -Filter $query -ErrorAction Stop # Check if the ping status is 0 (successful ping) if ($pingResult.StatusCode -eq 0) { Write-Verbose "Computer '$ComputerName' is online." return $true } else { Write-Verbose "Computer '$ComputerName' is offline or unreachable (StatusCode: $($pingResult.StatusCode))." return $false } } catch { Write-Verbose "Failed to ping computer '$ComputerName'. Error: $_" return $false } } #EndRegion './Public/Test-ComputerPing.ps1' 32 #Region './Public/Test-DirectoryExists.ps1' -1 function Test-DirectoryExists { param ( [string]$Directory ) if (-not (Test-Path $Directory)) { New-Item -Path $Directory -ItemType Directory -Force | Out-Null } } #EndRegion './Public/Test-DirectoryExists.ps1' 10 |