Skip to content

Commit

Permalink
Merge pull request #7 from scott1138/1.1.0
Browse files Browse the repository at this point in the history
1.1.0
  • Loading branch information
scott1138 authored Jul 13, 2020
2 parents 1da2983 + e3671a4 commit 9d43dbe
Show file tree
Hide file tree
Showing 11 changed files with 558 additions and 314 deletions.
9 changes: 6 additions & 3 deletions PS-Tools/PS-Tools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PS-Tools.psm1'

# Version number of this module.
ModuleVersion = '1.0.1'
ModuleVersion = '1.1.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -92,14 +92,17 @@ FunctionsToExport = @(
'Copy-SnapshotToVHD',
'Get-TimeStamp',
'Set-ResourceGroupTags',
'Write-InformationPlus'
'Write-InformationPlus',
'Set-PSToolsConfig'
)

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()

# Variables to export from this module
VariablesToExport = @()
VariablesToExport = @(
'PSToolsConfig'
)

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @()
Expand Down
11 changes: 9 additions & 2 deletions PS-Tools/PS-Tools.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ foreach ($Function in $Functions) {
}
}

try {
$PSToolsConfig = Get-Content -Path 'C:\ProgramData\PS-Tools\config.json' -ErrorAction 'Stop' | ConvertFrom-Json
Write-Verbose "Configuration loaded from C:\ProgramDate\PS-Tools\config.json"
}
catch {
Write-Warning "PS-Tools configuration file not found."
Write-Warning "Run Set-PSToolsConfig to create one."
}

# Export only the functions using PowerShell standard verb-noun naming.
# Be sure to list each exported functions in the FunctionsToExport field of the module manifest file.
# This improves performance of command discovery in PowerShell.
Export-ModuleMember -Function *-*

Export-ModuleMember -Function $Functions.BaseName -Variable 'PSToolsConfig'
20 changes: 20 additions & 0 deletions PS-Tools/PSToolsConfigReqs.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
$ReferenceSettings = @{
'New-SA' = @(
'SandboxServiceAccountOU',
'SandboxServiceAccountGroup',
'DevServiceAccountOU',
'DevServiceAccountGroup',
'TestServiceAccountOU',
'TestServiceAccountGroup',
'TrainingServiceAccountOU',
'TrainingServiceAccountGroup',
'UATServiceAccountOU',
'UATServiceAccountGroup',
'ProdServiceAccountOU',
'ProdServiceAccountGroup',
'NoMFAGroup'
)
'New-User' = @(
'UserOU'
)
}
44 changes: 44 additions & 0 deletions PS-Tools/Private/Test-PSToolsConfig.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
function Test-PSToolsConfig {
[CmdletBinding()]

param (
[Parameter(Mandatory)]
[string]
$Domain

)

# Get the name of the calling function
# [0] is the current function
# [1] is the calling function
$FunctionName = (Get-PSCallStack)[1].Command
Write-Verbose "Testing for function $FunctionName"

# Check to see if the PSToolsConfig variable exists
if ($null -eq $PSToolsConfig) {
Write-Error 'PSToolsConfig has not been set, run Set-PSToolsConfig'
break
}

# use the function name to check for required values.
if ($FunctionName -eq 'New-SA') {
# Load Reference Settings
$PSToolsConfigReqsPath = "$((Get-Item $PSScriptRoot).Parent)\PSToolsConfigReqs.ps1"
Write-Verbose "Loading config from $PSToolsConfigReqsPath"
. $PSToolsConfigReqsPath

$MissingSetting = $false
foreach ($Setting in $ReferenceSettings."$FunctionName") {
Write-Verbose "Checking for $Setting"
if ($null -eq $PSToolsConfig."$Domain".$Setting) {
Write-Warning "Missing setting $Setting for $Domain"
$MissingSetting = $true
}
}
if ($MissingSetting) {
Write-Error "Missing settings required for New-SA, run Set-PSToolsConfig -Domain $Domain -Function $FunctionName"
}

}

}
Loading

0 comments on commit 9d43dbe

Please sign in to comment.