Skip to content

Commit 5df807e

Browse files
authored
Merge pull request #18 from exactmike/DirectConnect
Direct connect merge
2 parents 1cab536 + d461cf5 commit 5df807e

148 files changed

Lines changed: 8433 additions & 7702 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Functions/Add-RequiredMember.ps1

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Function Add-RequiredMember
2+
{
3+
4+
<#
5+
.PARAMETER RequiredMember
6+
An Array of strings which designate the names of the required members for the input object
7+
.PARAMETER InputObject
8+
An Array of strings which designate the names of the required members for the input object
9+
#>
10+
[CmdletBinding()]
11+
param(
12+
[Parameter(Mandatory, Position = 1)]
13+
[AllowNull()]
14+
[AllowEmptyCollection()]
15+
[string[]]$RequiredMember
16+
,
17+
[Parameter(Mandatory, ValueFromPipeline, Position = 2)]
18+
[psobject[]]$InputObject
19+
)
20+
Process
21+
{
22+
foreach ($io in $InputObject)
23+
{
24+
foreach ($rm in $RequiredMember)
25+
{
26+
if ($null -ne $rm -and -not [string]::IsNullOrEmpty($rm))
27+
{
28+
if (-not (Test-Member -InputObject $io -Name $rm))
29+
{
30+
Add-Member -InputObject $io -MemberType NoteProperty -Name $rm -Value $null
31+
}
32+
}
33+
}
34+
}
35+
}
36+
37+
}
38+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Function AddServiceTypeAttributesToGenericOrgSystemObject
2+
{
3+
4+
[CmdletBinding()]
5+
param
6+
(
7+
[parameter(Mandatory)]
8+
$OrgSystemObject
9+
,
10+
[parameter(Mandatory)]
11+
$ServiceType
12+
,
13+
[parameter()]
14+
$dictionary
15+
)#end param
16+
#Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState
17+
if ($null -ne $dictionary)
18+
{
19+
Set-DynamicParameterVariable -dictionary $dictionary
20+
}
21+
$ServiceTypeDefinition = Get-OneShellServiceTypeDefinition -ServiceType $ServiceType
22+
Write-Verbose -Message "Using ServiceTypeDefinition $($ServiceTypeDefinition.name)"
23+
if ($null -ne $ServiceTypeDefinition.ServiceTypeAttributes.System -and $ServiceTypeDefinition.ServiceTypeAttributes.System.count -ge 1)
24+
{
25+
foreach ($a in $ServiceTypeDefinition.ServiceTypeAttributes.System.name)
26+
{
27+
$Value = $(Get-Variable -Name $a -Scope Local).Value
28+
Write-Verbose -Message "Value for $a is $($value -join ',')"
29+
$OrgSystemObject.ServiceTypeAttributes | Add-Member -MemberType NoteProperty -Name $a -Value $Value
30+
}
31+
}
32+
$OrgSystemObject
33+
34+
}
35+

Functions/AddUserProfileFolder.ps1

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Function AddUserProfileFolder
2+
{
3+
4+
[cmdletbinding()]
5+
param
6+
(
7+
$UserProfile
8+
)
9+
$profileFolder = $UserProfile.ProfileFolder
10+
if ($null -eq $profileFolder -or [string]::IsNullOrEmpty($profileFolder))
11+
{throw("User Profile $($UserProfile.Identity) Profile Folder is invalid.")}
12+
if (-not (Test-Path -Path $profileFolder))
13+
{
14+
[void](New-Item -Path $profileFolder -ItemType Directory -ErrorAction Stop)
15+
}
16+
$profileSubfolders = $(join-path $profilefolder 'Logs'), $(join-path $profilefolder 'Export'), $(join-path $profileFolder 'InputFiles')
17+
foreach ($folder in $profileSubfolders)
18+
{
19+
if (-not (Test-Path -Path $folder))
20+
{
21+
[void](New-Item -Path $folder -ItemType Directory -ErrorAction Stop)
22+
}
23+
}
24+
25+
}
26+

Functions/Connect-OneShellSystem.ps1

Lines changed: 414 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Function Convert-CredentialToUserProfileCredential
2+
{
3+
4+
[cmdletbinding()]
5+
param
6+
(
7+
[pscredential]$credential
8+
,
9+
[string]$Identity
10+
)
11+
if ($null -eq $Identity -or [string]::IsNullOrWhiteSpace($Identity))
12+
{$Identity = $(New-OneShellGuid).guid}
13+
$credential | Add-Member -MemberType NoteProperty -Name 'Identity' -Value $Identity
14+
$credential | Select-Object -Property @{n = 'Identity'; e = {$_.Identity}}, @{n = 'UserName'; e = {$_.UserName}}, @{n = 'Password'; e = {$_.Password | ConvertFrom-SecureString}}
15+
16+
}
17+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Function Convert-HashtableToObject
2+
{
3+
4+
[CmdletBinding()]
5+
PARAM
6+
(
7+
[Parameter(ValueFromPipeline, Mandatory)]
8+
[HashTable]$hashtable
9+
,
10+
[switch]$Combine
11+
,
12+
[switch]$Recurse
13+
)
14+
BEGIN
15+
{
16+
$output = @()
17+
}
18+
PROCESS
19+
{
20+
if ($recurse)
21+
{
22+
$keys = $hashtable.Keys | ForEach-Object { $_ }
23+
Write-Verbose -Message "Recursing $($Keys.Count) keys"
24+
foreach ($key in $keys)
25+
{
26+
if ($hashtable.$key -is [HashTable])
27+
{
28+
$hashtable.$key = Convert-HashtableToObject -hashtable $hashtable.$key -Recurse # -Combine:$combine
29+
}
30+
}
31+
}
32+
if ($combine)
33+
{
34+
$output += @(New-Object -TypeName PSObject -Property $hashtable)
35+
Write-Verbose -Message "Combining Output = $($Output.Count) so far"
36+
}
37+
else
38+
{
39+
New-Object -TypeName PSObject -Property $hashtable
40+
}
41+
}
42+
END
43+
{
44+
if ($combine -and $output.Count -gt 1)
45+
{
46+
Write-Verbose -Message "Combining $($Output.Count) cached outputs"
47+
$output | Join-Object
48+
}
49+
else
50+
{
51+
$output
52+
}
53+
}
54+
55+
}
56+

Functions/ConvertFrom-FQDN.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Function ConvertFrom-FQDN
2+
{
3+
4+
[cmdletbinding()]
5+
param(
6+
[parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)]
7+
[string[]]$FQDN
8+
)
9+
process
10+
{
11+
foreach ($f in $FQDN)
12+
{
13+
"DC=$($f.replace(".", ",DC="))"
14+
}
15+
}
16+
17+
}

Functions/Export-OneShellData.ps1

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
Function Export-OneShellData
2+
{
3+
[cmdletbinding(DefaultParameterSetName = 'delimited')]
4+
param(
5+
$ExportFolderPath = $script:ExportDataPath
6+
,
7+
[string]$DataToExportTitle
8+
,
9+
$DataToExport
10+
,
11+
[parameter(ParameterSetName = 'xml/json')]
12+
[int]$Depth = 2
13+
,
14+
[parameter(ParameterSetName = 'delimited')]
15+
[parameter(ParameterSetName = 'xml/json')]
16+
[ValidateSet('xml', 'csv', 'json', 'clixml')]
17+
[string]$DataType
18+
,
19+
[parameter(ParameterSetName = 'delimited')]
20+
[switch]$Append
21+
,
22+
[parameter(ParameterSetName = 'delimited')]
23+
[string]$Delimiter = ','
24+
,
25+
[switch]$ReturnExportFilePath
26+
,
27+
[parameter()]
28+
[ValidateSet('Unicode', 'BigEndianUnicode', 'Ascii', 'Default', 'UTF8', 'UTF8NOBOM', 'UTF7', 'UTF32')]
29+
[string]$Encoding = 'Ascii'
30+
)
31+
#Determine Export File Path
32+
#validate append
33+
if ($Append -eq $true -and $DataType -ne 'csv')
34+
{
35+
throw("-Append is not supported with data type $DataType. It is only supported with data type 'csv'")
36+
}
37+
Function GetTimeStamp
38+
{
39+
[string]$Stamp = Get-Date -Format yyyyMMdd-HHmmss
40+
#$([DateTime]::Now.ToShortDateString()) $([DateTime]::Now.ToShortTimeString()) #check if this is faster to use than Get-Date
41+
$Stamp
42+
}
43+
$stamp = GetTimeStamp
44+
#Build the ExportFilePath value
45+
switch ($DataType)
46+
{
47+
'xml'
48+
{
49+
$ExportFilePath = Join-Path -Path $exportFolderPath -ChildPath $($Stamp + $DataToExportTitle + '.xml')
50+
}#xml
51+
'clixml'
52+
{
53+
$ExportFilePath = Join-Path -Path $exportFolderPath -ChildPath $($Stamp + $DataToExportTitle + '.xml')
54+
}#xml
55+
'json'
56+
{
57+
$ExportFilePath = Join-Path -Path $exportFolderPath -ChildPath $($Stamp + $DataToExportTitle + '.json')
58+
}#json
59+
'csv'
60+
{
61+
if ($Append)
62+
{
63+
$mostrecent = @(get-childitem -Path $ExportFolderPath -Filter "*$DataToExportTitle.csv" | Sort-Object -Property CreationTime -Descending | Select-Object -First 1)
64+
if ($mostrecent.count -eq 1)
65+
{
66+
$ExportFilePath = $mostrecent[0].fullname
67+
}#if
68+
else {$ExportFilePath = Join-Path -Path $exportFolderPath -ChildPath $($Stamp + $DataToExportTitle + '.csv')}#else
69+
}#if
70+
else {$ExportFilePath = Join-Path -Path $exportFolderPath -ChildPath $($Stamp + $DataToExportTitle + '.csv')}#else
71+
}#csv
72+
}#switch $dataType
73+
#Attempt Export of Data to File
74+
$message = "Export of $DataToExportTitle as Data Type $DataType to File $ExportFilePath"
75+
Write-OneShellLog -Message $message -EntryType Attempting
76+
Try
77+
{
78+
$formattedData = $(
79+
switch ($DataType)
80+
{
81+
'xml'
82+
{
83+
$DataToExport | ConvertTo-Xml -Depth $Depth -ErrorAction Stop -NoTypeInformation -As String
84+
}#xml
85+
'clixml'
86+
{
87+
#$DataToExport | ConvertTo-CliXML -Depth -errorAction Stop -Encoding $Encoding #not supported in Windows PowerShell, also need to handle Encoding if UTF8NOBOM is specified
88+
}#xml
89+
'json'
90+
{
91+
$DataToExport | ConvertTo-Json -Depth $Depth -ErrorAction Stop
92+
}#json
93+
'csv'
94+
{
95+
$DataToExport | ConvertTo-Csv -ErrorAction Stop -NoTypeInformation -Delimiter $Delimiter
96+
}#csv
97+
}
98+
)
99+
$outFileParams = @{
100+
ErrorAction = 'Stop'
101+
LiteralPath = $ExportFilePath
102+
}
103+
switch ($Encoding)
104+
{
105+
'UTF8NOBOM'
106+
{
107+
if ($Append)
108+
{
109+
$outFileParams.Append = $true
110+
$outFileParams.InputObject = $formattedData
111+
}
112+
Out-FileUtf8NoBom @outFileParams
113+
}
114+
Default
115+
{
116+
$outFileParams.Encoding = $Encoding
117+
if ($DataType -eq 'clixml')
118+
{
119+
$outFileParams.Depth = $Depth
120+
$outFileParams.InputObject = $DataToExport
121+
Export-Clixml @outFileParams
122+
}
123+
else
124+
{
125+
$outFileParams.InputObject = $formattedData
126+
if ($append)
127+
{
128+
$outFileParams.Append = $true
129+
}
130+
Out-File @outFileParams
131+
}
132+
}
133+
}
134+
if ($ReturnExportFilePath) {$ExportFilePath}
135+
Write-OneShellLog -Message $message -EntryType Succeeded
136+
}#try
137+
Catch
138+
{
139+
Write-OneShellLog -Message "FAILED: Export of $DataToExportTitle as Data Type $DataType to File $ExportFilePath" -Verbose -ErrorLog
140+
Write-OneShellLog -Message $_.tostring() -ErrorLog
141+
}#catch
142+
143+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Function Export-OneShellOrgProfile
2+
{
3+
[cmdletbinding(SupportsShouldProcess)]
4+
param
5+
(
6+
[parameter(Mandatory)]
7+
[psobject]$profile
8+
,
9+
[parameter(Mandatory)]
10+
[AllowNull()]
11+
[ValidateScript( {Test-DirectoryPath -path $_})]
12+
$Path
13+
)
14+
$name = [string]$($profile.Identity.tostring()) + '.json'
15+
if ($null -eq $Path)
16+
{
17+
Write-Verbose -Message "Using Default Profile Location"
18+
$FilePath = Join-Path $script:OneShellOrgProfilePath[0] $name
19+
}
20+
else
21+
{
22+
$FilePath = Join-Path $Path $name
23+
}
24+
Write-Verbose -Message "Profile File Export Path is $FilePath"
25+
$profile | Remove-Member -Member DirectoryPath
26+
$JSONparams = @{
27+
InputObject = $profile
28+
ErrorAction = 'Stop'
29+
Depth = 10
30+
}
31+
$OutParams = @{
32+
ErrorAction = 'Stop'
33+
FilePath = $FilePath
34+
Encoding = 'ascii'
35+
}
36+
if ($whatifPreference -eq $false)
37+
{$OutParams.Force = $true}
38+
try
39+
{
40+
ConvertTo-Json @JSONparams | Out-File @OutParams
41+
}#end try
42+
catch
43+
{
44+
$_
45+
throw "FAILED: Could not write Org Profile data to $FilePath"
46+
}#end catch
47+
}
48+
#end Function Export-OneShellOrgProfile

0 commit comments

Comments
 (0)