From 600e33e871302bd55e6a76e431ebd09617596714 Mon Sep 17 00:00:00 2001 From: vrguibar Date: Tue, 4 Jun 2024 12:22:25 +0200 Subject: [PATCH] Remove parameter var type. This is handled by Get-AdObjectType. Add misssing params. Fix typos. --- Private/Get-ADCSTemplate.ps1 | 14 +- Private/Get-FunctionDisplay.ps1 | 5 +- Private/New-Template.ps1 | 13 +- Private/New-TemplateOID.ps1 | 12 +- Private/Test-IsUniqueOID.ps1 | 20 +- Private/Test-IsValidDN.ps1 | 1 + Private/Test-IsValidGUID.ps1 | 8 +- Private/Test-IsValidSID.ps1 | 7 +- Public/ConvertTo-IPv4Integer.ps1 | 13 +- Public/ConvertTo-IPv4MaskBit.ps1 | 7 +- Public/ConvertTo-IPv4MaskString.ps1 | 9 +- Public/ConvertTo-IPv4NetworkAddress.ps1 | 34 +-- Public/ConvertTo-IntegerIPv4.ps1 | 3 +- Public/New-AGPMobject.ps1 | 5 +- Public/New-AdDelegatedGroup.ps1 | 1 + Public/New-DelegateAdGpo.ps1 | 1 - Public/New-DelegateAdOU.ps1 | 1 - Public/New-DhcpObject.ps1 | 5 +- Public/New-EitAdSite.ps1 | 6 +- Public/New-ExchangeObject.ps1 | 7 +- Public/New-LocalLogonTask.ps1 | 229 ++++++++++---------- Public/New-TimePolicyGPO.ps1 | 50 ++--- Public/Revoke-Inheritance.ps1 | 12 +- Public/Set-AdAclDelegateGalAdmin.ps1 | 5 +- Public/Set-AdAclDelegateUserAdmin.ps1 | 7 +- Public/Set-AdAclLaps.ps1 | 11 +- Public/Start-AdAclDelegateComputerAdmin.ps1 | 16 +- Public/Start-AdDelegatedSite.ps1 | 22 +- Public/Test-IPv4MaskString.ps1 | 10 +- Public/Test-RegistryValue.ps1 | 14 +- 30 files changed, 310 insertions(+), 238 deletions(-) diff --git a/Private/Get-ADCSTemplate.ps1 b/Private/Get-ADCSTemplate.ps1 index 16b4406..e8bd50d 100644 --- a/Private/Get-ADCSTemplate.ps1 +++ b/Private/Get-ADCSTemplate.ps1 @@ -31,15 +31,17 @@ Function Get-ADCSTemplate { ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, - Position = 0)] - [string]$DisplayName, + Position = 0)] + [string] + $DisplayName, [Parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, - Position = 1)] - [string]$Server + Position = 1)] + [string] + $Server ) Begin { Write-Verbose -Message '|=> ************************************************************************ <=|' @@ -50,7 +52,7 @@ Function Get-ADCSTemplate { ############################## # Variables Definition - if(-not $Server) { + if (-not $Server) { $Server = (Get-ADDomainController -Discover -ForceDiscover -Writable).HostName[0] } @@ -61,7 +63,7 @@ Function Get-ADCSTemplate { } #end If } #end Begin Process { - $ConfigNC = $((Get-ADRootDSE -Server $Server).configurationNamingContext) + $ConfigNC = $((Get-ADRootDSE -Server $Server).configurationNamingContext) $TemplatePath = ('CN=Certificate Templates,CN=Public Key Services,CN=Services,{0}' -f $ConfigNC) diff --git a/Private/Get-FunctionDisplay.ps1 b/Private/Get-FunctionDisplay.ps1 index f3dbe48..67abf79 100644 --- a/Private/Get-FunctionDisplay.ps1 +++ b/Private/Get-FunctionDisplay.ps1 @@ -34,9 +34,10 @@ [Parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, HelpMessage = 'Amount of Tabs to be used on the formatting.', Position = 1)] - [ValidateNotNullOrEmpty()][PSDefaultValue(Help = 'Default Value is "4"')] + [ValidateNotNullOrEmpty()] + [PSDefaultValue(Help = 'Default Value is "4"')] [int] - $TabCount = 4 + $TabCount = 2 ) Begin { diff --git a/Private/New-Template.ps1 b/Private/New-Template.ps1 index 1cda1d4..3ce796b 100644 --- a/Private/New-Template.ps1 +++ b/Private/New-Template.ps1 @@ -37,14 +37,20 @@ Function New-Template { #> [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Low')] Param( - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $False, + [Parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $False, HelpMessage = 'Display Name of the new template.', Position = 0)] [ValidateNotNullOrEmpty()] [System.String] $DisplayName, - [Parameter(Mandatory = $True, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $False, + [Parameter(Mandatory = $True, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $False, HelpMessage = 'Other attributes in form of HashTable of the new template.', Position = 1)] [System.Collections.Hashtable] @@ -108,8 +114,7 @@ Function New-Template { New-ADObject @Splat } - } - catch { + } catch { # Handle errors here ###Get-CurrentErrorToDisplay -CurrentError $error[0] throw diff --git a/Private/New-TemplateOID.ps1 b/Private/New-TemplateOID.ps1 index 7029cca..353f928 100644 --- a/Private/New-TemplateOID.ps1 +++ b/Private/New-TemplateOID.ps1 @@ -39,15 +39,21 @@ Function New-TemplateOID { [OutputType([System.Collections.Hashtable])] Param( - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $False, + [Parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $False, HelpMessage = 'FQDN of a Domain Controller.', Position = 0)] [ValidateNotNullOrEmpty()] [System.String] $Server, - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $False, - HelpMessage = 'Configuration Namin Context of the domain.', + [Parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $False, + HelpMessage = 'Configuration Naming Context of the domain.', Position = 1)] [ValidateNotNullOrEmpty()] [System.String] diff --git a/Private/Test-IsUniqueOID.ps1 b/Private/Test-IsUniqueOID.ps1 index f2a1ea0..d6c68cf 100644 --- a/Private/Test-IsUniqueOID.ps1 +++ b/Private/Test-IsUniqueOID.ps1 @@ -25,25 +25,37 @@ Function Test-IsUniqueOID { [OutputType([System.Boolean])] param ( - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $False, + [Parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $False, HelpMessage = 'Specifies the Common Name (CN) of the Certificate Template', Position = 0)] [string] $cn, - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $False, + [Parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $False, HelpMessage = 'Specifies the OID (Object Identifier) of the Certificate Template', Position = 1)] [string] $TemplateOID, - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $False, + [Parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $False, HelpMessage = 'Specifies the Active Directory server to query', Position = 2)] [string] $Server, - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $False, + [Parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $False, HelpMessage = 'Specifies the Configuration Naming Context (ConfigNC) to search for the Certificate Template.', Position = 3)] [string] diff --git a/Private/Test-IsValidDN.ps1 b/Private/Test-IsValidDN.ps1 index ca72b77..9fdc94d 100644 --- a/Private/Test-IsValidDN.ps1 +++ b/Private/Test-IsValidDN.ps1 @@ -34,6 +34,7 @@ function Test-IsValidDN { HelpMessage = 'String to ve validated as DistinguishedName', Position = 0)] [ValidateNotNullOrEmpty()] + [ValidateScript({ Test-IsValidDN -ObjectDN $_ })] [Alias('DN', 'DistinguishedName', 'LDAPpath')] [string] $ObjectDN diff --git a/Private/Test-IsValidGUID.ps1 b/Private/Test-IsValidGUID.ps1 index eba94a4..486e0f5 100644 --- a/Private/Test-IsValidGUID.ps1 +++ b/Private/Test-IsValidGUID.ps1 @@ -31,9 +31,11 @@ [CmdletBinding(ConfirmImpact = 'Low', SupportsShouldProcess = $false)] [OutputType([bool])] - param - ( - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, + param ( + [Parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $false, HelpMessage = 'String to be validated as Global Unique Identifier (GUID)', Position = 0)] [ValidateNotNullOrEmpty()] diff --git a/Private/Test-IsValidSID.ps1 b/Private/Test-IsValidSID.ps1 index 5ab3112..09ba4cc 100644 --- a/Private/Test-IsValidSID.ps1 +++ b/Private/Test-IsValidSID.ps1 @@ -27,7 +27,10 @@ function Test-IsValidSID { [OutputType([bool])] param ( - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, + [Parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $false, HelpMessage = 'String to be validated as SID', Position = 0)] [ValidateNotNullOrEmpty()] @@ -37,7 +40,7 @@ function Test-IsValidSID { ) Begin { # Define DN Regex - $SidRegex = [RegEx]::new("^S-1-[0-59]-\d{2}-\d{8,10}-\d{8,10}-\d{8,10}-[1-9]\d{3}") + $SidRegex = [RegEx]::new('^S-1-[0-59]-\d{2}-\d{8,10}-\d{8,10}-\d{8,10}-[1-9]\d{3}') } #end Begin Process { Try { diff --git a/Public/ConvertTo-IPv4Integer.ps1 b/Public/ConvertTo-IPv4Integer.ps1 index a77bc38..6bbc225 100644 --- a/Public/ConvertTo-IPv4Integer.ps1 +++ b/Public/ConvertTo-IPv4Integer.ps1 @@ -26,8 +26,9 @@ function ConvertTo-IPv4Integer { ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, - Position = 0)] - [String] $Ipv4Address + Position = 0)] + [String] + $Ipv4Address ) Begin { @@ -41,18 +42,18 @@ function ConvertTo-IPv4Integer { } Process { - Try{ + Try { $ipAddress = [IPAddress]::Parse($IPv4Address) $bytes = $ipAddress.GetAddressBytes() [Array]::Reverse($bytes) - [System.BitConverter]::ToUInt32($bytes,0) + [System.BitConverter]::ToUInt32($bytes, 0) - }Catch{ + } Catch { Write-Error -Exception $_.Exception -Category $_.CategoryInfo.Category - } + } } End { diff --git a/Public/ConvertTo-IPv4MaskBit.ps1 b/Public/ConvertTo-IPv4MaskBit.ps1 index 6c43e7d..3c78d67 100644 --- a/Public/ConvertTo-IPv4MaskBit.ps1 +++ b/Public/ConvertTo-IPv4MaskBit.ps1 @@ -26,9 +26,10 @@ function ConvertTo-IPv4MaskBit { ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, - Position = 0)] - [ValidateScript({Test-IPv4MaskString $_})] - [String] $MaskString + Position = 0)] + [ValidateScript({ Test-IPv4MaskString $_ })] + [String] + $MaskString ) Begin { Write-Verbose -Message '|=> ************************************************************************ <=|' diff --git a/Public/ConvertTo-IPv4MaskString.ps1 b/Public/ConvertTo-IPv4MaskString.ps1 index 9e6bad1..cd6a165 100644 --- a/Public/ConvertTo-IPv4MaskString.ps1 +++ b/Public/ConvertTo-IPv4MaskString.ps1 @@ -25,9 +25,10 @@ function ConvertTo-IPv4MaskString { ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, - Position =0)] - [ValidateRange(0,32)] - [System.Int32] $MaskBits + Position = 0)] + [ValidateRange(0, 32)] + [System.Int32] + $MaskBits ) Begin { Write-Verbose -Message '|=> ************************************************************************ <=|' @@ -42,7 +43,7 @@ function ConvertTo-IPv4MaskString { Process { $mask = ([Math]::Pow(2, $MaskBits) - 1) * [Math]::Pow(2, (32 - $MaskBits)) $bytes = [BitConverter]::GetBytes([UInt32] $mask) - (($bytes.Count - 1)..0 | ForEach-Object { [String] $bytes[$_] }) -join "." + (($bytes.Count - 1)..0 | ForEach-Object { [String] $bytes[$_] }) -join '.' } End { Write-Verbose -Message "Function $($MyInvocation.InvocationName) finished." diff --git a/Public/ConvertTo-IPv4NetworkAddress.ps1 b/Public/ConvertTo-IPv4NetworkAddress.ps1 index dc99043..c4ff120 100644 --- a/Public/ConvertTo-IPv4NetworkAddress.ps1 +++ b/Public/ConvertTo-IPv4NetworkAddress.ps1 @@ -36,34 +36,38 @@ Function ConvertTo-IPv4NetworkAddress { #> [CmdletBinding(ConfirmImpact = 'Low')] [OutputType([System.Net.IpAddress])] - Param - ( + + Param ( [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, - HelpMessage = "Specifies the IPv4 Address as string (e.g., 192.168.1.200)", - Position = 0)] - [String] $IPv4Address, + HelpMessage = 'Specifies the IPv4 Address as string (e.g., 192.168.1.200)', + Position = 0)] + [String] + $IPv4Address, [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, - HelpMessage = "Specifies the IPv4 network mask as string (e.g., 255.255.255.0)", - ParameterSetName='SubnetMask', - Position = 1)] - [String] $SubnetMask, + HelpMessage = 'Specifies the IPv4 network mask as string (e.g., 255.255.255.0)', + ParameterSetName = 'SubnetMask', + Position = 1)] + [String] + $SubnetMask, [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, - HelpMessage = "Specifies the network prefix length, also known as CIDR (e.g., 24)", - ParameterSetName='PrefixLength', - Position = 1)] - [String] $PrefixLength + HelpMessage = 'Specifies the network prefix length, also known as CIDR (e.g., 24)', + ParameterSetName = 'PrefixLength', + Position = 1)] + [String] + $PrefixLength ) + Begin { Write-Verbose -Message '|=> ************************************************************************ <=|' Write-Verbose -Message (Get-Date).ToShortDateString() @@ -75,7 +79,7 @@ Function ConvertTo-IPv4NetworkAddress { ##### # Variables - $IntegerIPv4Address = 0 + $IntegerIPv4Address = 0 $IntegerIPv4SubnetMask = 0 $IntegerNetworkAddress = 0 [IpAddress]$NetworkAddress @@ -86,7 +90,7 @@ Function ConvertTo-IPv4NetworkAddress { Write-Verbose -Message ('IP Address {0} to Integer: {1}' -f $IPv4Address, $IntegerIPv4Address) # Get IPv4 subnet mask as an Integer - If($PSCmdlet.ParameterSetName -eq 'PrefixLength') { + If ($PSCmdlet.ParameterSetName -eq 'PrefixLength') { $SubnetMask = (ConvertTo-IPv4MaskString -MaskBits $PrefixLength).ToString() Write-Verbose -Message ('PrefixLength of {0} to Integer: {1}' -f $SubnetMask, $IntegerIPv4SubnetMask) } diff --git a/Public/ConvertTo-IntegerIPv4.ps1 b/Public/ConvertTo-IntegerIPv4.ps1 index 36aed82..37ff5e2 100644 --- a/Public/ConvertTo-IntegerIPv4.ps1 +++ b/Public/ConvertTo-IntegerIPv4.ps1 @@ -26,7 +26,8 @@ function ConvertTo-IntegerIPv4 { ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, Position = 0)] - [uint32] $Integer + [uint32] + $Integer ) Begin { diff --git a/Public/New-AGPMobject.ps1 b/Public/New-AGPMobject.ps1 index 84dc282..8a8aa7f 100644 --- a/Public/New-AGPMobject.ps1 +++ b/Public/New-AGPMobject.ps1 @@ -27,7 +27,10 @@ [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')] Param( # PARAM1 full path to the configuration.xml file - [Parameter(Mandatory = $true, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True, ValueFromRemainingArguments = $false, + [Parameter(Mandatory = $true, + ValueFromPipeline = $True, + ValueFromPipelineByPropertyName = $True, + ValueFromRemainingArguments = $false, HelpMessage = 'Full path to the configuration.xml file', Position = 0)] [string] diff --git a/Public/New-AdDelegatedGroup.ps1 b/Public/New-AdDelegatedGroup.ps1 index f952f8d..9013552 100644 --- a/Public/New-AdDelegatedGroup.ps1 +++ b/Public/New-AdDelegatedGroup.ps1 @@ -66,6 +66,7 @@ #> [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')] [OutputType([Microsoft.ActiveDirectory.Management.AdGroup])] + Param ( # Param1 Group which membership is to be changed [Parameter(Mandatory = $true, diff --git a/Public/New-DelegateAdGpo.ps1 b/Public/New-DelegateAdGpo.ps1 index e2350ff..a3f2659 100644 --- a/Public/New-DelegateAdGpo.ps1 +++ b/Public/New-DelegateAdGpo.ps1 @@ -102,7 +102,6 @@ function New-DelegateAdGpo { HelpMessage = 'Domain Local Group with GPO Rights to be assigned', Position = 3)] [ValidateNotNullOrEmpty()] - [string] $GpoAdmin, # Param5 Restore GPO settings from backup using the BackupID GUID diff --git a/Public/New-DelegateAdOU.ps1 b/Public/New-DelegateAdOU.ps1 index 0459a41..741f86d 100644 --- a/Public/New-DelegateAdOU.ps1 +++ b/Public/New-DelegateAdOU.ps1 @@ -60,7 +60,6 @@ function New-DelegateAdOU { ValueFromRemainingArguments = $false, HelpMessage = 'Name of the OU', Position = 0)] - [ValidateNotNull()] [ValidateNotNullOrEmpty()] [ValidateLength(2, 50)] [string] diff --git a/Public/New-DhcpObject.ps1 b/Public/New-DhcpObject.ps1 index a2cba43..f1dbf7e 100644 --- a/Public/New-DhcpObject.ps1 +++ b/Public/New-DhcpObject.ps1 @@ -32,7 +32,10 @@ Param ( # PARAM1 full path to the configuration.xml file - [Parameter(Mandatory = $true, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True, ValueFromRemainingArguments = $false, + [Parameter(Mandatory = $true, + ValueFromPipeline = $True, + ValueFromPipelineByPropertyName = $True, + ValueFromRemainingArguments = $false, HelpMessage = 'Full path to the configuration.xml file', Position = 0)] [string] diff --git a/Public/New-EitAdSite.ps1 b/Public/New-EitAdSite.ps1 index 4599264..f032c6d 100644 --- a/Public/New-EitAdSite.ps1 +++ b/Public/New-EitAdSite.ps1 @@ -21,10 +21,12 @@ function New-EitAdSite { Param ( # Param1 New Site name - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, + [Parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $false, HelpMessage = 'Add help message for user', Position = 0)] - [ValidateNotNull()] [ValidateNotNullOrEmpty()] [string] $NewSiteName diff --git a/Public/New-ExchangeObject.ps1 b/Public/New-ExchangeObject.ps1 index d4e0a4f..0fceb68 100644 --- a/Public/New-ExchangeObject.ps1 +++ b/Public/New-ExchangeObject.ps1 @@ -18,9 +18,13 @@ Function New-ExchangeObject { http://www.eguibarit.com #> [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')] + Param( # PARAM1 full path to the configuration.xml file - [Parameter(Mandatory = $true, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True, ValueFromRemainingArguments = $false, + [Parameter(Mandatory = $true, + ValueFromPipeline = $True, + ValueFromPipelineByPropertyName = $True, + ValueFromRemainingArguments = $false, HelpMessage = 'Full path to the configuration.xml file', Position = 0)] [string] @@ -33,6 +37,7 @@ Function New-ExchangeObject { ValueFromRemainingArguments = $false, HelpMessage = 'Path to all the scripts and files needed by this function', Position = 1)] + [PSDefaultValue(Help = 'Default Value is "C:\PsScripts\"')] [string] $DMscripts = 'C:\PsScripts\' ) diff --git a/Public/New-LocalLogonTask.ps1 b/Public/New-LocalLogonTask.ps1 index 22e3dc3..7ecd918 100644 --- a/Public/New-LocalLogonTask.ps1 +++ b/Public/New-LocalLogonTask.ps1 @@ -1,6 +1,5 @@ -function New-LocalLogonTask -{ -<# +function New-LocalLogonTask { + <# .SYNOPSIS Generates a New Local Logon task .DESCRIPTION @@ -15,70 +14,69 @@ function New-LocalLogonTask Eguibar Information Technology S.L. http://www.eguibarit.com #> - [CmdletBinding(ConfirmImpact = 'Medium')] - Param - ( - # Param1 help description - [Parameter(Mandatory = $true,HelpMessage = 'Add help message for user', - ValueFromPipeline = $true, - ValueFromPipelineByPropertyName = $true, - ValueFromRemainingArguments = $false, - Position = 0)] - [ValidateNotNullOrEmpty()] - [string] - $name, - - # Param2 help description - [Parameter(Mandatory = $true,HelpMessage = 'Add help message for user', - ValueFromPipeline = $true, - ValueFromPipelineByPropertyName = $true, - ValueFromRemainingArguments = $false, - Position = 1)] - [ValidateNotNullOrEmpty()] - [string] - $Description, - - # Param3 help description - [Parameter(Mandatory = $true,HelpMessage = 'Add help message for user', - ValueFromPipeline = $true, - ValueFromPipelineByPropertyName = $true, - ValueFromRemainingArguments = $false, - Position = 2)] - [ValidateNotNullOrEmpty()] - [string] - $Author, - - # Param4 help description - [Parameter(Mandatory = $true,HelpMessage = 'Add help message for user', - ValueFromPipeline = $true, - ValueFromPipelineByPropertyName = $true, - ValueFromRemainingArguments = $false, - Position = 3)] - [ValidateNotNullOrEmpty()] - [string] - $Command, - - # Param5 help description - [Parameter(Mandatory = $false, - ValueFromPipeline = $true, - ValueFromPipelineByPropertyName = $true, - ValueFromRemainingArguments = $false, - Position = 4)] - [string] - $CommandArguments, - - # Param6 help description - [Parameter(Mandatory = $false, - ValueFromPipeline = $true, - ValueFromPipelineByPropertyName = $true, - ValueFromRemainingArguments = $false, - Position = 5)] - [switch] - $Hidden - ) - - Begin - { + [CmdletBinding(ConfirmImpact = 'Medium')] + Param + ( + # Param1 help description + [Parameter(Mandatory = $true, HelpMessage = 'Add help message for user', + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $false, + Position = 0)] + [ValidateNotNullOrEmpty()] + [string] + $name, + + # Param2 help description + [Parameter(Mandatory = $true, HelpMessage = 'Add help message for user', + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $false, + Position = 1)] + [ValidateNotNullOrEmpty()] + [string] + $Description, + + # Param3 help description + [Parameter(Mandatory = $true, HelpMessage = 'Add help message for user', + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $false, + Position = 2)] + [ValidateNotNullOrEmpty()] + [string] + $Author, + + # Param4 help description + [Parameter(Mandatory = $true, HelpMessage = 'Add help message for user', + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $false, + Position = 3)] + [ValidateNotNullOrEmpty()] + [string] + $Command, + + # Param5 help description + [Parameter(Mandatory = $false, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $false, + Position = 4)] + [string] + $CommandArguments, + + # Param6 help description + [Parameter(Mandatory = $false, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $false, + Position = 5)] + [switch] + $Hidden + ) + + Begin { Write-Verbose -Message '|=> ************************************************************************ <=|' Write-Verbose -Message (Get-Date).ToShortDateString() Write-Verbose -Message (' Starting: {0}' -f $MyInvocation.Mycommand) @@ -87,59 +85,54 @@ function New-LocalLogonTask ############################## # Variables Definition - } - Process - { - # https://msdn.microsoft.com/en-us/library/windows/desktop/aa383607(v=vs.85).aspx - try - { - # Create the TaskService object - $service = New-Object -ComObject('Schedule.Service') - # Connect to the server's Task Service Scheduler - $service.Connect($Env:computername) - - $rootFolder = $service.GetFolder('\') - - $taskDefinition = $service.NewTask(0) - - # Define information about the task. - # Set the registration info for the task by creating the RegistrationInfo object. - $regInfo = $taskDefinition.RegistrationInfo - $regInfo.Description = $Description - $regInfo.Author = $Author - - # Set the task setting info for the Task Scheduler by creating a TaskSettings object. - $settings = $taskDefinition.Settings - $settings.Enabled = $true - $settings.StartWhenAvailable = $true - $settings.Hidden = $Hidden - - # Create a logon trigger - $triggers = $taskDefinition.Triggers - # TriggerTypeLogon is 9 - $trigger = $triggers.Create(9) - - # Trigger variables that define when the trigger is active - $trigger.StartBoundary = '2014-10-0T22:00:00' - #$trigger.DaysInterval = 1 - $trigger.Id = 'LogonTriggerId' - $trigger.Enabled = $true - - # Create the action for the task to execute. Add an action to the task - $Action = $taskDefinition.Actions.Create(0) - $Action.Path = $Command - $Action.Arguments = $CommandArguments - - # Register (create -> 6 ) the task - $rootFolder.RegisterTaskDefinition( $name, $taskDefinition, 6, $null , $null , 0) } - catch - { - throw $error + Process { + # https://msdn.microsoft.com/en-us/library/windows/desktop/aa383607(v=vs.85).aspx + try { + # Create the TaskService object + $service = New-Object -ComObject('Schedule.Service') + # Connect to the server's Task Service Scheduler + $service.Connect($Env:computername) + + $rootFolder = $service.GetFolder('\') + + $taskDefinition = $service.NewTask(0) + + # Define information about the task. + # Set the registration info for the task by creating the RegistrationInfo object. + $regInfo = $taskDefinition.RegistrationInfo + $regInfo.Description = $Description + $regInfo.Author = $Author + + # Set the task setting info for the Task Scheduler by creating a TaskSettings object. + $settings = $taskDefinition.Settings + $settings.Enabled = $true + $settings.StartWhenAvailable = $true + $settings.Hidden = $Hidden + + # Create a logon trigger + $triggers = $taskDefinition.Triggers + # TriggerTypeLogon is 9 + $trigger = $triggers.Create(9) + + # Trigger variables that define when the trigger is active + $trigger.StartBoundary = '2014-10-0T22:00:00' + #$trigger.DaysInterval = 1 + $trigger.Id = 'LogonTriggerId' + $trigger.Enabled = $true + + # Create the action for the task to execute. Add an action to the task + $Action = $taskDefinition.Actions.Create(0) + $Action.Path = $Command + $Action.Arguments = $CommandArguments + + # Register (create -> 6 ) the task + $rootFolder.RegisterTaskDefinition( $name, $taskDefinition, 6, $null , $null , 0) + } catch { + throw $error + } } - } - End - { + End { Write-Verbose -Message "Function $($MyInvocation.InvocationName) finished creating new task." Write-Verbose -Message '' Write-Verbose -Message '-------------------------------------------------------------------------------' diff --git a/Public/New-TimePolicyGPO.ps1 b/Public/New-TimePolicyGPO.ps1 index 2fdc6a7..b62352b 100644 --- a/Public/New-TimePolicyGPO.ps1 +++ b/Public/New-TimePolicyGPO.ps1 @@ -1,5 +1,4 @@ -Function New-TimePolicyGPO -{ +Function New-TimePolicyGPO { <# .Synopsis @@ -26,7 +25,7 @@ Function New-TimePolicyGPO ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, HelpMessage = 'Name of the GPO to be created', - Position = 0)] + Position = 0)] [ValidateNotNull()] [ValidateNotNullOrEmpty()] [string] @@ -38,7 +37,7 @@ Function New-TimePolicyGPO ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, HelpMessage = 'NTP Servers to be used for time sync', - Position = 1)] + Position = 1)] [string] $NtpServer, @@ -48,7 +47,7 @@ Function New-TimePolicyGPO ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, HelpMessage = 'AnnounceFlags for reliable time server', - Position = 2)] + Position = 2)] [ValidateNotNullOrEmpty()] [int] $AnnounceFlags, @@ -59,7 +58,7 @@ Function New-TimePolicyGPO ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, HelpMessage = 'Type of sync to be used', - Position = 3)] + Position = 3)] [ValidateNotNullOrEmpty()] [ValidateSet('NoSync', 'NTP', 'NT5DS', 'AllSync', ignorecase = $false)] [string] @@ -71,7 +70,7 @@ Function New-TimePolicyGPO ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, HelpMessage = 'WMIFilter to be created and used', - Position = 3)] + Position = 3)] [ValidateNotNullOrEmpty()] $WMIFilter, @@ -81,7 +80,7 @@ Function New-TimePolicyGPO ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, HelpMessage = 'Disable Virtual Machine time sync clock', - Position = 4)] + Position = 4)] [switch] $DisableVMTimeSync ) @@ -100,8 +99,8 @@ Function New-TimePolicyGPO $msWMIAuthor = (Get-ADUser -Identity $env:USERNAME).Name # Create WMI Filter - $WMIGUID = [string]'{'+([Guid]::NewGuid())+'}' - $WMIDN = 'CN='+$WMIGUID+',CN=SOM,CN=WMIPolicy,CN=System,{0}' -f ([ADSI]'LDAP://RootDSE').DefaultNamingContext.ToString() + $WMIGUID = [string]'{' + ([Guid]::NewGuid()) + '}' + $WMIDN = 'CN=' + $WMIGUID + ',CN=SOM,CN=WMIPolicy,CN=System,{0}' -f ([ADSI]'LDAP://RootDSE').DefaultNamingContext.ToString() $WMICN = $WMIGUID $WMIdistinguishedname = $WMIDN $WMIID = $WMIGUID @@ -116,16 +115,16 @@ Function New-TimePolicyGPO # msWMI-Parm1: The description of the WMI filter # msWMI-Parm2: The query and other related data of the WMI filter $Attr = @{ - 'msWMI-Name' = $msWMIName - 'msWMI-Parm1' = $msWMIParm1 - 'msWMI-Parm2' = $msWMIParm2 - 'msWMI-Author' = $msWMIAuthor - 'msWMI-ID' = $WMIID - 'instanceType' = 4 + 'msWMI-Name' = $msWMIName + 'msWMI-Parm1' = $msWMIParm1 + 'msWMI-Parm2' = $msWMIParm2 + 'msWMI-Author' = $msWMIAuthor + 'msWMI-ID' = $WMIID + 'instanceType' = 4 'showInAdvancedViewOnly' = 'TRUE' - 'distinguishedname' = $WMIdistinguishedname - 'msWMI-ChangeDate' = $msWMICreationDate - 'msWMI-CreationDate' = $msWMICreationDate + 'distinguishedname' = $WMIdistinguishedname + 'msWMI-ChangeDate' = $msWMICreationDate + 'msWMI-CreationDate' = $msWMICreationDate } $WMIPath = ('CN=SOM,CN=WMIPolicy,CN=System,{0}' -f ([ADSI]'LDAP://RootDSE').DefaultNamingContext.ToString()) @@ -136,8 +135,7 @@ Function New-TimePolicyGPO Process { If ($null -ne $ExistingWMIFilters) { - foreach ($ExistingWMIFilter in $ExistingWMIFilters) - { + foreach ($ExistingWMIFilter in $ExistingWMIFilters) { $array += $ExistingWMIFilter.'msWMI-Name' } } Else { @@ -155,9 +153,9 @@ Function New-TimePolicyGPO # Get WMI filter $WMIFilterADObject = Get-ADObject -Filter 'objectClass -eq "msWMI-Som"' -Properties 'msWMI-Name', 'msWMI-Parm1', 'msWMI-Parm2' | - Where-Object { - $_.'msWMI-Name' -eq "$msWMIName" - } + Where-Object { + $_.'msWMI-Name' -eq "$msWMIName" + } $ExistingGPO = get-gpo -Name $PSBoundParameters['gpoName'] -ErrorAction 'SilentlyContinue' @@ -190,7 +188,7 @@ Function New-TimePolicyGPO # Disable the Hyper-V time synchronization integration service. $null = Set-GPPrefRegistryValue -Name $PSBoundParameters['gpoName'] -Action Update -Context Computer ` -Key 'HKLM\SYSTEM\CurrentControlSet\Services\W32Time\Parameters' ` - -Type DWord -ValueName 'Enabled' -Value 0 + -Type DWord -ValueName 'Enabled' -Value 0 # Used to control how often the time service synchronizes to 15 minutes $null = Set-GPPrefRegistryValue -Name $PSBoundParameters['gpoName'] -Action Update -Context Computer ` @@ -203,7 +201,7 @@ Function New-TimePolicyGPO -Type DWord -ValueName 'MaxPosPhaseCorrection' -Value 3600 # Set the three registry keys in the Preferences section of the new GPO - $null = Set-GPPrefRegistryValue -Name $PSBoundParameters['gpoName'] -Action Update -Context Computer ` + $null = Set-GPPrefRegistryValue -Name $PSBoundParameters['gpoName'] -Action Update -Context Computer ` -Key 'HKLM\SYSTEM\CurrentControlSet\Services\W32Time\Config' ` -Type DWord -ValueName 'MaxNegPhaseCorrection' -Value 3600 }#end if diff --git a/Public/Revoke-Inheritance.ps1 b/Public/Revoke-Inheritance.ps1 index f9f20ec..ef9deb6 100644 --- a/Public/Revoke-Inheritance.ps1 +++ b/Public/Revoke-Inheritance.ps1 @@ -36,7 +36,9 @@ Param ( # PARAM1 STRING for the Object Name - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, + [Parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, HelpMessage = 'Distinguished Name of the object (or container).', Position = 0)] [ValidateNotNullOrEmpty()] @@ -45,13 +47,17 @@ [String] $LDAPpath, - [Parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, + [Parameter(Mandatory = $false, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, HelpMessage = 'Remove inheritance from parent. If present Inheritance will be removed.', Position = 1)] [switch] $RemoveInheritance, - [Parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, + [Parameter(Mandatory = $false, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, HelpMessage = 'Previous inherited access rules will be kept. If present means rules will be copied and maintained, otherwise rules will be removed.', Position = 1)] diff --git a/Public/Set-AdAclDelegateGalAdmin.ps1 b/Public/Set-AdAclDelegateGalAdmin.ps1 index 08714df..aac8af0 100644 --- a/Public/Set-AdAclDelegateGalAdmin.ps1 +++ b/Public/Set-AdAclDelegateGalAdmin.ps1 @@ -43,7 +43,6 @@ function Set-AdAclDelegateGalAdmin { HelpMessage = 'Identity of the group getting the delegation, usually a DomainLocal group.', Position = 0)] [ValidateNotNullOrEmpty()] - [String] $Group, # PARAM2 Distinguished Name of the OU where given group will manage a User GAL. @@ -76,8 +75,10 @@ function Set-AdAclDelegateGalAdmin { $Splat = [hashtable]::New([StringComparer]::OrdinalIgnoreCase) + $CurrentGroup = Get-AdObjectType -Identity $PSBoundParameters['Group'] + $Splat = @{ - Group = $PSBoundParameters['Group'] + Group = $CurrentGroup LDAPPath = $PSBoundParameters['LDAPpath'] } diff --git a/Public/Set-AdAclDelegateUserAdmin.ps1 b/Public/Set-AdAclDelegateUserAdmin.ps1 index c38b148..d76b0bc 100644 --- a/Public/Set-AdAclDelegateUserAdmin.ps1 +++ b/Public/Set-AdAclDelegateUserAdmin.ps1 @@ -36,7 +36,7 @@ function Set-AdAclDelegateUserAdmin { Eguibar Information Technology S.L. http://www.eguibarit.com #> - [CmdletBinding(ConfirmImpact = 'Medium')] + [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')] Param ( # PARAM1 STRING for the Delegated Group Name @@ -44,7 +44,6 @@ function Set-AdAclDelegateUserAdmin { HelpMessage = 'Identity of the group getting the delegation, usually a DomainLocal group.', Position = 0)] [ValidateNotNullOrEmpty()] - [String] $Group, # PARAM2 Distinguished Name of the OU where given group can read the User password @@ -77,8 +76,10 @@ function Set-AdAclDelegateUserAdmin { $Splat = [hashtable]::New([StringComparer]::OrdinalIgnoreCase) + $CurrentGroup = Get-AdObjectType -Identity $PSBoundParameters['Group'] + $Splat = @{ - Group = $PSBoundParameters['Group'] + Group = $CurrentGroup LDAPPath = $PSBoundParameters['LDAPpath'] } } #end Begin diff --git a/Public/Set-AdAclLaps.ps1 b/Public/Set-AdAclLaps.ps1 index 016815f..e22537a 100644 --- a/Public/Set-AdAclLaps.ps1 +++ b/Public/Set-AdAclLaps.ps1 @@ -45,7 +45,6 @@ function Set-AdAclLaps { HelpMessage = 'Identity of the group getting being able to READ the password.', Position = 0)] [ValidateNotNullOrEmpty()] - [String] $ReadGroup, # PARAM2 STRING for the Delegated Group Name @@ -53,7 +52,6 @@ function Set-AdAclLaps { HelpMessage = 'Identity of the group getting being able to RESET the password.', Position = 1)] [ValidateNotNullOrEmpty()] - [String] $ResetGroup, # PARAM3 Distinguished Name of the OU where given group can read the computer password @@ -62,6 +60,7 @@ function Set-AdAclLaps { Position = 2)] [ValidateNotNullOrEmpty()] [validateScript({ Test-IsValidDN -ObjectDN $_ })] + [Alias('DN', 'DistinguishedName')] [String] $LDAPpath, @@ -101,13 +100,13 @@ function Set-AdAclLaps { # AdmPwd.PS CMDlets Set-AdmPwdComputerSelfPermission -Identity $LDAPpath - Set-AdmPwdReadPasswordPermission -AllowedPrincipals $ReadGroup -Identity $LDAPpath - Set-AdmPwdResetPasswordPermission -AllowedPrincipals $ResetGroup -Identity $LDAPpath + Set-AdmPwdReadPasswordPermission -AllowedPrincipals $currentReadGroup -Identity $PSBoundParameters['LDAPpath'] + Set-AdmPwdResetPasswordPermission -AllowedPrincipals $currentResetGroup -Identity $PSBoundParameters['LDAPpath'] # LAPS CMDlets Set-LapsADComputerSelfPermission -Identity $LDAPpath - Set-LapsADReadPasswordPermission -AllowedPrincipals $currentReadGroup.SID -Identity $LDAPpath - Set-LapsADResetPasswordPermission -AllowedPrincipals $currentResetGroup.SID -Identity $LDAPpath + Set-LapsADReadPasswordPermission -AllowedPrincipals $currentReadGroup.SID -Identity $PSBoundParameters['LDAPpath'] + Set-LapsADResetPasswordPermission -AllowedPrincipals $currentResetGroup.SID -Identity $PSBoundParameters['LDAPpath'] } else { Write-Error -Message 'Not Implemented. Schema does not contains the required attributes.' diff --git a/Public/Start-AdAclDelegateComputerAdmin.ps1 b/Public/Start-AdAclDelegateComputerAdmin.ps1 index 5ba72df..62c151b 100644 --- a/Public/Start-AdAclDelegateComputerAdmin.ps1 +++ b/Public/Start-AdAclDelegateComputerAdmin.ps1 @@ -48,7 +48,6 @@ function Set-AdAclDelegateComputerAdmin { HelpMessage = 'Identity of the group getting the delegation, usually a DomainLocal group.', Position = 0)] [ValidateNotNullOrEmpty()] - [String] $Group, # PARAM2 Distinguished Name of the OU where given group can read the computer password @@ -57,6 +56,7 @@ function Set-AdAclDelegateComputerAdmin { Position = 1)] [ValidateNotNullOrEmpty()] [validateScript({ Test-IsValidDN -ObjectDN $_ })] + [Alias('DN', 'DistinguishedName')] [String] $LDAPpath, @@ -91,8 +91,10 @@ function Set-AdAclDelegateComputerAdmin { $Splat = [hashtable]::New([StringComparer]::OrdinalIgnoreCase) + $currentGroup = Get-AdObjectType -Identity $PSBoundParameters['Group'] + $Splat = @{ - Group = $PSBoundParameters['Group'] + Group = $currentGroup LDAPPath = $PSBoundParameters['LDAPpath'] } @@ -100,13 +102,13 @@ function Set-AdAclDelegateComputerAdmin { Process { try { # Check if RemoveRule switch is present. - If($PSBoundParameters['RemoveRule']) { + If ($PSBoundParameters['RemoveRule']) { # Add the parameter to remove the rule $Splat.Add('RemoveRule', $true) } - if ($Force -or $PSCmdlet.ShouldProcess("Proceed with delegations?")) { - # Create/Delete Computers + if ($Force -or $PSCmdlet.ShouldProcess('Proceed with delegations?')) { + # Create/Delete Computers Set-AdAclCreateDeleteComputer @Splat # Reset Computer Password @@ -134,10 +136,10 @@ function Set-AdAclDelegateComputerAdmin { Set-AdAclBitLockerTPM @Splat # Grant the right to delete computers from default container. Move Computers - Set-DeleteOnlyComputer -Group $PSBoundParameters['Group'] -LDAPPath $PSBoundParameters['QuarantineDN'] + Set-DeleteOnlyComputer -Group $currentGroup -LDAPPath $PSBoundParameters['QuarantineDN'] # Set LAPS - Set-AdAclLaps -ResetGroup $PSBoundParameters['Group'] -ReadGroup $PSBoundParameters['Group'] -LDAPPath $PSBoundParameters['LDAPpath'] + Set-AdAclLaps -ResetGroup $currentGroup -ReadGroup $currentGroup -LDAPPath $PSBoundParameters['LDAPpath'] } #end If } catch { diff --git a/Public/Start-AdDelegatedSite.ps1 b/Public/Start-AdDelegatedSite.ps1 index 1356efa..304f40c 100644 --- a/Public/Start-AdDelegatedSite.ps1 +++ b/Public/Start-AdDelegatedSite.ps1 @@ -66,14 +66,20 @@ function Start-AdDelegateSite { [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium', DefaultParameterSetName = 'ParamOptions')] param ( # PARAM1 full path to the configuration.xml file - [Parameter(Mandatory = $true, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True, ValueFromRemainingArguments = $false, + [Parameter(Mandatory = $true, + ValueFromPipeline = $True, + ValueFromPipelineByPropertyName = $True, + ValueFromRemainingArguments = $false, HelpMessage = 'Full path to the configuration.xml file', Position = 0)] [string] $ConfigXMLFile, #PARAM2 - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $False, + [Parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $False, ParameterSetName = 'ParamOptions', HelpMessage = 'Enter the Name of the Site OU', Position = 1)] @@ -82,16 +88,24 @@ function Start-AdDelegateSite { $ouName, #PARAM3 - [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $False, + [Parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $False, ParameterSetName = 'ParamOptions', HelpMessage = 'Enter the Name new redirected OU for computers', Position = 2)] [ValidateNotNullOrEmpty()] + [validateScript({ Test-IsValidDN -ObjectDN $_ })] + [Alias('DN', 'DistinguishedName', 'LDAPpath')] [String] $QuarantineDN, # Param4 Create Exchange Objects - [Parameter(Mandatory = $false, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, + [Parameter(Mandatory = $false, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $false, HelpMessage = 'If present It will create all needed Exchange objects and containers.', Position = 3)] [switch] diff --git a/Public/Test-IPv4MaskString.ps1 b/Public/Test-IPv4MaskString.ps1 index f41c76c..76b86ce 100644 --- a/Public/Test-IPv4MaskString.ps1 +++ b/Public/Test-IPv4MaskString.ps1 @@ -15,8 +15,8 @@ function Test-IPv4MaskString { ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, - HelpMessage = "Specifies the IPv4 network mask string (e.g., 255.255.255.0)", - Position = 1)] + HelpMessage = 'Specifies the IPv4 network mask string (e.g., 255.255.255.0)', + Position = 1)] [String] $MaskString ) @@ -29,9 +29,9 @@ function Test-IPv4MaskString { Process { $validBytes = '0|128|192|224|240|248|252|254|255' - $maskPattern = ('^((({0})\.0\.0\.0)|' -f $validBytes) + - ('(255\.({0})\.0\.0)|' -f $validBytes) + - ('(255\.255\.({0})\.0)|' -f $validBytes) + + $maskPattern = ('^((({0})\.0\.0\.0)|' -f $validBytes) + + ('(255\.({0})\.0\.0)|' -f $validBytes) + + ('(255\.255\.({0})\.0)|' -f $validBytes) + ('(255\.255\.255\.({0})))$' -f $validBytes) $MaskString -match $maskPattern } #end Process diff --git a/Public/Test-RegistryValue.ps1 b/Public/Test-RegistryValue.ps1 index 1f60aea..84297de 100644 --- a/Public/Test-RegistryValue.ps1 +++ b/Public/Test-RegistryValue.ps1 @@ -29,15 +29,22 @@ function Test-RegistryValue { #> [CmdletBinding(ConfirmImpact = 'Low')] [OutputType([Bool])] + Param ( - [parameter(Mandatory=$true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, + [parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $false, HelpMessage = 'Registry path to be tested', Position = 0)] [ValidateNotNullOrEmpty()] [string] $Path, - [parameter(Mandatory=$true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ValueFromRemainingArguments = $false, + [parameter(Mandatory = $true, + ValueFromPipeline = $true, + ValueFromPipelineByPropertyName = $true, + ValueFromRemainingArguments = $false, HelpMessage = 'Registry value to be tested', Position = 1)] [ValidateNotNullOrEmpty()] @@ -59,8 +66,7 @@ function Test-RegistryValue { try { Get-ItemProperty -Path $Path | Select-Object -ExpandProperty $Value -ErrorAction Stop | Out-Null return $true - } - catch { + } catch { return $false } } #end Process