Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Huge module overhaul #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CitrixImagingTools/CitrixImagingTools.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ Foreach ($import in @($Public + $Private))
Export-ModuleMember -Function $Public.Basename

Add-Type -Path "$PSScriptRoot\Private\LsaSecretsHelper.cs"
#Update-TypeData -TypeName System.Management.Automation.CmdletInfo -MemberName Tags -MemberType Scriptproperty -Value {Get-Tag2 -InputObject $this.Definition}
167 changes: 167 additions & 0 deletions CitrixImagingTools/Private/Add-ObjectDetail.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
function Add-ObjectDetail
{
<#
.SYNOPSIS
Decorate an object with
- A TypeName
- New properties
- Default parameters

.DESCRIPTION
Helper function to decorate an object with
- A TypeName
- New properties
- Default parameters

.PARAMETER InputObject
Object to decorate. Accepts pipeline input.

.PARAMETER TypeName
Typename to insert.

This will show up when you use Get-Member against the resulting object.

.PARAMETER PropertyToAdd
Add these noteproperties.

Format is a hashtable with Key (Property Name) = Value (Property Value).

Example to add a One and Date property:

-PropertyToAdd @{
One = 1
Date = (Get-Date)
}

.PARAMETER DefaultProperties
Change the default properties that show up

.PARAMETER Passthru
Whether to pass the resulting object on. Defaults to true

.EXAMPLE
#
# Create an object to work with
$Object = [PSCustomObject]@{
First = 'Cookie'
Last = 'Monster'
Account = 'CMonster'
}

#Add a type name and a random property
Add-ObjectDetail -InputObject $Object -TypeName 'ApplicationX.Account' -PropertyToAdd @{ AnotherProperty = 5 }

# First Last Account AnotherProperty
# ----- ---- ------- ---------------
# Cookie Monster CMonster 5

#Verify that get-member shows us the right type
$Object | Get-Member

# TypeName: ApplicationX.Account ...

.EXAMPLE
#
# Create an object to work with
$Object = [PSCustomObject]@{
First = 'Cookie'
Last = 'Monster'
Account = 'CMonster'
}

#Add a random property, set a default property set so we only see two props by default
Add-ObjectDetail -InputObject $Object -PropertyToAdd @{ AnotherProperty = 5 } -DefaultProperties Account, AnotherProperty

# Account AnotherProperty
# ------- ---------------
# CMonster 5

#Verify that the other properties are around
$Object | Select -Property *

# First Last Account AnotherProperty
# ----- ---- ------- ---------------
# Cookie Monster CMonster 5

.NOTES
This breaks the 'do one thing' rule from certain perspectives...
The goal is to decorate an object all in one shot

This abstraction simplifies decorating an object, with a slight trade-off in performance. For example:

10,000 objects, add a property and typename:
Add-ObjectDetail: ~4.6 seconds
Add-Member + PSObject.TypeNames.Insert: ~3 seconds

Initial code borrowed from Shay Levy:
http://blogs.microsoft.co.il/scriptfanatic/2012/04/13/custom-objects-default-display-in-powershell-30/

.FUNCTIONALITY
PowerShell Language
#>
[CmdletBinding()]
param(
[Parameter( Mandatory = $true,
Position=0,
ValueFromPipeline=$true )]
[ValidateNotNullOrEmpty()]
[psobject[]]$InputObject,

[Parameter( Mandatory = $false,
Position=1)]
[string]$TypeName,

[Parameter( Mandatory = $false,
Position=2)]
[System.Collections.Hashtable]$PropertyToAdd,

[Parameter( Mandatory = $false,
Position=3)]
[ValidateNotNullOrEmpty()]
[Alias('dp')]
[System.String[]]$DefaultProperties,

[boolean]$Passthru = $True
)

Begin
{
if($PSBoundParameters.ContainsKey('DefaultProperties'))
{
# define a subset of properties
$ddps = New-Object System.Management.Automation.PSPropertySet DefaultDisplayPropertySet,$DefaultProperties
$PSStandardMembers = [System.Management.Automation.PSMemberInfo[]]$ddps
}
}
Process
{
foreach($Object in $InputObject)
{
switch ($PSBoundParameters.Keys)
{
'PropertyToAdd'
{
foreach($Key in $PropertyToAdd.Keys)
{
#Add some noteproperties. Slightly faster than Add-Member.
$Object.PSObject.Properties.Add( ( New-Object System.Management.Automation.PSNoteProperty($Key, $PropertyToAdd[$Key]) ) )
}
}
'TypeName'
{
#Add specified type
[void]$Object.PSObject.TypeNames.Insert(0,$TypeName)
}
'DefaultProperties'
{
# Attach default display property set
Add-Member -InputObject $Object -MemberType MemberSet -Name PSStandardMembers -Value $PSStandardMembers
}
}
if($Passthru)
{
$Object
}
}
}
}
2 changes: 1 addition & 1 deletion CitrixImagingTools/Private/Get-LsaSecret.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function Get-LsaSecret
$UnsecureString = [PSCredential]::New("user",$Secret.Value).GetNetworkCredential().Password

.NOTES
ToDo: add tags, author info
Original Author: Sebastian Neumann (@megam0rf)
#>

[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingConvertToSecureStringWithPlainText", "")]
Expand Down
13 changes: 8 additions & 5 deletions CitrixImagingTools/Private/Get-OSInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ function Get-OSInfo
$NICInfo = Get-CimInstance -ClassName win32_networkadapterconfiguration -Filter "DHCPEnabled='True' and DNSHostName='$env:COMPUTERNAME'"

[pscustomobject]@{
PSVersion = $PSVersionTable.PSVersion
Domain = $ComputerSystemInfo.Domain
PartOfDomain = $ComputerSystemInfo.PartOfDomain
NICs = $NICInfo
Drives = [pscustomobject]@{
PSVersion = $PSVersionTable.PSVersion
Domain = $ComputerSystemInfo.Domain
PartOfDomain = $ComputerSystemInfo.PartOfDomain
NICs = $NICInfo
NumCPU = $ComputerSystemInfo.NumberOfProcessors
NumCPULogical = $ComputerSystemInfo.NumberOfLogicalProcessors
Drives = [pscustomobject]@{
Disks = $DriveInfo | Where-Object DriveType -eq 3
CD = $DriveInfo | Where-Object DriveType -eq 5
Floppy = $DriveInfo | Where-Object DriveType -eq 2
}

}
}
2 changes: 1 addition & 1 deletion CitrixImagingTools/Private/Get-Personality.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ function Get-Personality
{
$PersonalityIni = Get-Item -LiteralPath "$env:SystemDrive\Personality.ini" -ErrorAction Stop

Import-IniFile -FilePath $PersonalityIni.FullName
CitriImagingTools\Import-IniFile -FilePath $PersonalityIni.FullName
}
6 changes: 3 additions & 3 deletions CitrixImagingTools/Private/Get-PvsPath.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Function Get-PvsPath
#>
try
{
if (Test-Path -LiteraPath "$env:ProgramFiles\Citrix\Provisioning Services")
if (Test-Path -LiteralPath "$env:ProgramFiles\Citrix\Provisioning Services")
{
$Path = Get-Item -LiteraPath "$env:ProgramFiles\Citrix\Provisioning Services"
$Path = Get-Item -LiteralPath "$env:ProgramFiles\Citrix\Provisioning Services"
}
else
{
$Pkg = Get-Package -Name 'Citrix Provisioning Services Target Device x64'
$Path = Get-Item -LiteraPath $Pkg.FullPath
$Path = Get-Item -LiteralPath $Pkg.FullPath
}

return $Path
Expand Down
37 changes: 37 additions & 0 deletions CitrixImagingTools/Private/Get-Tag.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function Get-Tag
{
[CmdletBinding(DefaultParameterSetName='String')]
param(
[Parameter(ParameterSetName='Path',ValueFromPipeline=$true)]
$Path,

[Parameter(ParameterSetName='String',ValueFromPipeline=$true)]
$InputObject
)

Begin
{
$TagsPattern = ([regex]'(?m)^[\s]{0,15}Tags:(?<Tags>.*)$')
}

Process
{
foreach ($P in $Path)
{
$Result = Select-String -Pattern $TagsPattern -Path $P
$TagList = $Result.Matches | Foreach-Object {
$Tags = $_.Groups['Tags'].Value

if (-not [string]::IsNullOrEmpty($Tags))
{
$Tags.Trim().Split(',')
}
}

[pscustomobject]@{
Path = $P
Tags = $TagList
}
}
}
}
37 changes: 37 additions & 0 deletions CitrixImagingTools/Private/Get-Tag2.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
function Get-Tag2
{
[CmdletBinding()]
param(
$InputObject
)

Begin
{
$TagsPattern = ([regex]'(?m)^[\s]{0,15}Tags:(?<Tags>.*)$')
}

Process
{
foreach ($I in $InputObject)
{
$Result = Select-String -Pattern $TagsPattern -InputObject $I
$TagList = $Result.Matches | Foreach-Object {
try
{
$Tags = $_.Groups['Tags'].Value

if (-not [string]::IsNullOrEmpty($Tags))
{
$Tags.Trim().Split(',')
}
}
catch
{
$null
}
}

$TagList
}
}
}
24 changes: 24 additions & 0 deletions CitrixImagingTools/Private/ScheduledTasks-2016.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Tasks;Category;Description
AutoCHK\Proxy;CEIP;This task collects and uploads autochk SQM data if opted-in to the Microsoft Customer Experience Improvement Program.
Customer Experience Improvement Program \Consolidator;CEIP;If the user has consented to participate in the Windows Customer Experience Improvement Program, this job collects and sends usage data to Microsoft.
Customer Experience Improvement Program \KernelCeipTask;CEIP;The Kernel CEIP (Customer Experience Improvement Program) task collects additional information about the system and sends this data to Microsoft. If the user has not consented to participate in Windows CEIP, this task does nothing.
Customer Experience Improvement Program \Uploader;CEIP;This job sends data about windows based on user participation in the Windows Customer Experience Improvement Program
Customer Experience Improvement Program \UsbCeip;CEIP;The USB CEIP (Customer Experience Improvement Program) task collects Universal Serial Bus related statistics and information about your machine and sends to the Windows Device Connectivity engineering group at Microsoft. The information received is used to help improve the reliability, stability, and overall functionality of USB in Windows. If the user has not consented to participate in Windows CEIP, this task does not do anything.
Application Experience\Microsoft Compatibility Appraiser;Applications;Helps resolve application compatibility challenges.
Application Experience\StartupTask;Applications;Determines if there are too many startup entries and then notifies the user
Windows Defender\Windows Defender Cache Maintenance;Safety;Can be disabled in case an alternative virus and malware protection has been implemented.
Windows Defender\Windows Defender Cleanup;Safety;Can be disabled in case an alternative virus and malware protection has been implemented.
Windows Defender\Windows Defender Scheduled Scan;Safety;Can be disabled in case an alternative virus and malware protection has been implemented.
Windows Defender\Windows Defender Verification;Safety;Can be disabled in case an alternative virus and malware protection has been implemented.
Windows Filtering Platform \BfeOnServiceStartTypeChange;Safety;This task adjusts the start type for firewall-triggered services when the start type of the Base Filtering Engine (BFE) is disabled.
CHKDSK\Proactive Scan;Maintenance;NTFS Volume Health Scan
Diagnosis\Scheduled;Maintenance;The Windows Scheduled Maintenance Task performs periodic maintenance of the computer system by fixing problems automatically or reporting them through the Action Center.
DiskDiagnostic\Microsoft-Windows-DiskDiagnosticDataCollector;Maintenance;The Windows Disk Diagnostic reports general disk and system information to Microsoft for users participating in the Customer Experience Program.
Maintenance\WinSAT;Maintenance;Measures a system�s performance and capabilities
Power Efficiency Diagnostics\AnalyzeSystem;Maintenance;This task analyzes the system looking for conditions that may cause high energy use.
RecoveryEnvironment\VerifyWinRE;Maintenance;Validates the Windows Recovery Environment.
Registry\RegIdleBackup;Maintenance;Registry Idle Backup Task
Mobile Broadband Accounts / MNO Metadata Parser;General;Parses information related to mobile broadband users
RAS / MobilityManager;General;Provides support for the switching of mobility enabled VPN connections if their underlying interface goes down.
Shell / IndexerAutomaticMaintenance;General;Maintains the search index
WDI\ResolutionHost;General;The Windows Diagnostic Infrastructure Resolution host enables interactive resolutions for system problems detected by the Diagnostic Policy Service. It is triggered when necessary by the Diagnostic Policy Service in the appropriate user session. If the Diagnostic Policy Service is not running, the task will not run.
31 changes: 31 additions & 0 deletions CitrixImagingTools/Private/ScheduledTasks-Win10.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Tasks;Category;Description
Application Experience\Appraiser;CEIP;Aggregates and uploads Application Telemetry information if opted-in to the Microsoft Customer Experience Improvement Program.
Application Experience\ProgramDataUpdater;CEIP;Collects program telemetry information if opted-in to the Microsoft Customer Experience Improvement Program
AutoCHK\Proxy;CEIP;This task collects and uploads autochk SQM data if opted-in to the Microsoft Customer Experience Improvement Program.
Customer Experience Improvement Program \Consolidator;CEIP;If the user has consented to participate in the Windows Customer Experience Improvement Program, this job collects and sends usage data to Microsoft.
Customer Experience Improvement Program \KernelCeipTask;CEIP;The Kernel CEIP (Customer Experience Improvement Program) task collects additional information about the system and sends this data to Microsoft. If the user has not consented to participate in Windows CEIP, this task does nothing.
Customer Experience Improvement Program \Uploader;CEIP;This job sends data about windows based on user participation in the Windows Customer Experience Improvement Program
Customer Experience Improvement Program \UsbCeip;CEIP;The USB CEIP (Customer Experience Improvement Program) task collects Universal Serial Bus related statistics and information about your machine and sends to the Windows Device Connectivity engineering group at Microsoft. The information received is used to help improve the reliability, stability, and overall functionality of USB in Windows. If the user has not consented to participate in Windows CEIP, this task does not do anything.
Shell\FamilySafetyMonitor;Safety;Initializes Family Safety monitoring and enforcement.
Shell\FamilySafetyRefresh;Safety;Synchronizes the latest settings with the Family Safety website.
Windows Defender\Windows Defender CacheMaintenance;Safety;Can be disabled in case an alternative virus and malware protection has been implemented.
Windows Defender\Windows Defender CacheMaintenance;Safety;Can be disabled in case an alternative virus and malware protection has been implemented.
Windows Defender\Windows Defender Cleanup;Safety;Can be disabled in case an alternative virus and malware protection has been implemented.
Windows Defender\Windows DefenderScheduled Scan;Safety;Can be disabled in case an alternative virus and malware protection has been implemented.
Windows Defender\Windows DefenderVerification;Safety;Can be disabled in case an alternative virus and malware protection has been implemented.
Windows Filtering Platform \BfeOnServiceStartTypeChange;Safety;This task adjusts the start type for firewall-triggered services when the start type of the Base Filtering Engine (BFE) is disabled.
Application Experience\StartupAppTask;Optimization;Scans startup entries and raises notification to the user if there are too many startup entries.
CHKDSK\Proactive Scan;Optimization;NTFS Volume Health Scan
Diagnosis\Scheduled;Optimization;The Windows Scheduled Maintenance Task performs periodic maintenance of the computer system by fixing problems automatically or reporting them through the Action Center.
DiskDiagnostic\Microsoft-Windows-DiskDiagnosticDataCollector;Optimization;The Windows Disk Diagnostic reports general disk and system information to Microsoft for users participating in the Customer Experience Program.
DiskDiagnostic\Microsoft-Windows-DiskDiagnosticResolver;Optimization;This task warns users about faults that occur on disks that support Self-Monitoring and Reporting Technology
Defrag\ScheduledDefrag;Optimization;This task optimizes local storage drives
FileHistory\File History;Optimization;Protects user files from accidental loss by copying them to a backup location when the system is unattended
Maintenance\WinSAT;Optimization;Measures a system�s performance and capabilities
MemoryDiagnostic\ProcessMemoryDiagnosticEvents;Optimization;Schedules a memory diagnostic in response to system events.
MemoryDiagnostic\RunFullMemoryDiagnostic;Optimization;Detects and mitigates problems in physical memory (RAM).
Power Efficiency Diagnostics\AnalyzeSystem;Optimization;This task analyzes the system looking for conditions that may cause high energy use.
RecoveryEnvironment\VerifyWinRE;Optimization;Validates the Windows Recovery Environment.
Registry\RegIdleBackup;Optimization;Registry Idle Backup Task
SystemRestore\SR;Optimization;This task creates regular system protection points.
WDI\ResolutionHost;Optimization;The Windows Diagnostic Infrastructure Resolution host enables interactive resolutions for system problems detected by the Diagnostic Policy Service. It is triggered when necessary by the Diagnostic Policy Service in the appropriate user session. If the Diagnostic Policy Service is not running, the task will not run
2 changes: 1 addition & 1 deletion CitrixImagingTools/Private/Set-LsaSecret.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function Set-LsaSecret
Set-LsaSecret -Key MyKey -Value $ValueAsSecureString

.NOTES
ToDo: add tags, author info
Original Author: Sebastian Neumann (@megam0rf)
#>

[CmdletBinding(SupportsShouldProcess = $true)]
Expand Down
Loading