You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am attempting to use ImportExcel's Set-ExcelRange feature and/or .AutofitColumns() to output a spreadsheet with the proper column widths formatted correctly.
Here is the script I am testing with.
#Requires -Module ActiveDirectory, ImportExcel, HelperFunctions
#Requires -Version 5
#Requires -RunAsAdministrator
<#
.SYNOPSIS
Get AD password policies
.DESCRIPTION
This script executes an AD PowerShell cmdlet to gather the default domain
password policies and exports the results to an Excel spreadsheet.
.PARAMETER ForestName
The name of the Active Directory Forest to gather default password policies for.
.PARAMETER DomainName
Enter the name of the Active Directory domain to gather the default password policy on.
.PARAMETER Credential
Enter the Credential Object.
.EXAMPLE
.\Export-ADDomainPasswordPolicies.ps1 -ForestName exampleforest.com -Credential (Get-Credential)
.EXAMPLE
.\Export-ADDomainPasswordPolicies.ps1 -DomainName exampledomain.com -Credential (Get-Credential)
.EXAMPLE
.\Export-ADDomainPasswordPolicies.ps1
.OUTPUTS
Excel spreadsheet with the default password policy information settings
.NOTES
THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE
ENTIRE RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS
WITH THE USER.
You need to come up with a simple script that reproduces the problem. I do not have the time walk thru a 400 hundred line script with all that is going on.
Plus, doesn't seem to be an ImportExcel issue, seems to be a skill issue.
I am attempting to use ImportExcel's Set-ExcelRange feature and/or .AutofitColumns() to output a spreadsheet with the proper column widths formatted correctly.
Here is the script I am testing with.
#Requires -Module ActiveDirectory, ImportExcel, HelperFunctions
#Requires -Version 5
#Requires -RunAsAdministrator
<#
.SYNOPSIS
Get AD password policies
#>
###########################################################################
AUTHOR: Heather Miller
VERSION HISTORY: 3.0 - added Error handling and credential support
############################################################################
[CmdletBinding(DefaultParameterSetName = 'ForestParamSet',
SupportsShouldProcess = $true)]
param
(
[Parameter(ParameterSetName = 'ForestParamSet',
Position = 0,
HelpMessage = 'Enter the name of AD forest.')]
[ValidateNotNullOrEmpty()]
[String]$ForestName,
[Parameter(ParameterSetName = 'DomainParamSet',
Position = 0,
HelpMessage = 'Enter the AD domain name.')]
[ValidateNotNullOrEmpty()]
[String]$DomainName,
[Parameter(ParameterSetName = 'ForestParamSet',
Position = 1,
HelpMessageBaseName = 'Add the credential object variable name.')]
[Parameter(ParameterSetName = 'DomainParamSet',
Position = 1,
HelpMessage = 'Add the credential object variable name.')]
[ValidateNotNull()]
[System.Management.Automation.PsCredential]
[System.Management.Automation.Credential()]
$Credential = [System.Management.Automation.PSCredential]::Empty
)
#Region Modules
try
{
Import-Module -Name ActiveDirectory -SkipEditionCheck -Force -ErrorAction Stop
}
catch
{
try
{
Import-Module C:\Windows\System32\WindowsPowerShell\v1.0\Modules\ActiveDirectory\ActiveDirectory.psd1 -ErrorAction Stop
}
catch
{
throw "Active Directory module could not be loaded. $($_.Exception.Message)"
}
}
try
$module = Get-Module -ListAvailable | Where-Object { $ .Name -eq $moduleName };
{
Import-Module -Name ImportExcel -Force
}
catch
{
try
{
$moduleName = 'ImportExcel'
$ErrorActionPreference = 'Stop';
$ErrorActionPreference = 'Continue';
$modulePath = Split-Path $module.Path;
$psdPath = "{0}{1}" -f $modulePath, "ImportExcel.psd1"
Import-Module $psdPath -ErrorAction Stop
}
catch
{
throw "ImportExcel PS module could not be loaded. $($.Exception.Message)"
}
}
#EndRegion
#Region Variables
$dtPPHeadersCsv =
@"
ColumnName,DataType
"Domain Name",string
"Complexity Enabled",string
"Lockout Duration",string
"Lockout Window",string
"Lockout Threshold",string
"Max Password Age",string
"Min Password Age",string
"Min Password Length",string
"Password History Count",string
"Reversible Encryption Enabled",string
"@
$dtmFormatString = "yyyy-MM-dd HH:mm:ss"
$dtmFileFormatString = "yyyy-MM-dd_HH-mm-ss"
#EndRegion
#Region Functions
#EndRegion
#Region Script
$Error.Clear()
try
{
try
{
#https://docs.microsoft.com/en-us/dotnet/api/system.net.securityprotocoltype?view=netcore-2.0#System_Net_SecurityProtocolType_SystemDefault
if ($PSVersionTable.PSVersion.Major -lt 6 -and [Net.ServicePointManager]::SecurityProtocol -notmatch 'Tls12')
{
Write-Verbose -Message 'Adding support for TLS 1.2'
[Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12
}
}
catch
{
Write-Warning -Message 'Adding TLS 1.2 to supported security protocols was unsuccessful.'
}
}
catch
{
$errorMessage = "{0}: {1}" -f $Error[0], $Error[0].InvocationInfo.PositionMessage
Write-Error $errorMessage -ErrorAction Continue
}
finally
{
}
#EndRegion
None of the above combinations works properly. What am I doing wrong or is this a bug in the function?
The text was updated successfully, but these errors were encountered: