-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPSInfo.ps1
More file actions
99 lines (75 loc) · 2.37 KB
/
PSInfo.ps1
File metadata and controls
99 lines (75 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env pwsh
# Powershell info and helper utilities
# NOTE: This script is still in development and should not be used in production code.
# https://github.com/ajgorhoe/IGLib.modules.IGLibScriptsPS.git
# Remark: make sure you have set the execution policy correctly, e.g. (as admin.):
# Set-ExecutionPolicy RemoteSigned
# Execute definitions from other files:
. "$(Join-Path "$PSScriptRoot" "Common.ps1")"
# Check whether the current script has already been executed before:
CheckScriptExecuted $ExecutedScriptPath_PowerShellInfo $MyInvocation.MyCommand.Path;
# Store scritp path in a variable in order to enable later verifications:
$ExecutedScriptPath_PowerShellInfo = $MyInvocation.MyCommand.Path
# Auxiliary definitions:
Set-Alias print Write-Host
Set-Alias alias Set-Alias
Set-Alias aliases Get-Alias
function PowerShellInfo()
{
Write-Host 'Version information ($PSVersionTable):'
# Write-Host $PSVersionTable
# $PSVersionTable
$PSVersionTable | Format-Table -AutoSize
}
function ArrayToString($ArrayVar = $null)
{
if ("$ArrayVar" -eq "") {
Write-Host "`nError in ArrayToString(): null argument or not an array.`n"
return $null;
}
if ("$($ArrayVar.GetType().BaseType.Name)" -ne "Array")
{
Write-Host "`nError in ArrayToString(): not an array.`n"
Write-Host "$($ArrayVar.GetType().BaseType.Name) instead of 'Array'`n"
return $null;
}
$count = $ArrayVar.Count;
$sb = New-Object -TypeName "System.Text.StringBuilder";
# Remark: Assignments $null =
$null = $sb.Append("@(");
foreach ($ind in ( (0..$($count-1)) ) )
{
# Write-Host $sb.ToString()
$null = $sb.Append($ArrayVar[$ind]);
if ($ind -lt $count-1)
{
$null = $sb.Append(", ");
}
}
$null = $sb.Append(")");
return $($sb.ToString());
}
function PrintArray($ArrayVar = $null)
{
$str = ArrayToString $ArrayVar
Write-Host "$str"
}
function DictionaryToString($DictVar = $null)
{
if ("$DictVar" -eq "") { return "$null"; }
$sb = New-Object -TypeName "System.Text.StringBuilder";
foreach ($key in $dictionary.Keys) {
Write-Host " Key: $key Value: $($dictionary[$key])"
}
return $($sb.ToString());
}
function PrintDictionary($DictVar = $null)
{
$str = DictionaryToString $DictVar
Write-Host "$str"
}
function RunWithPowerShell($Command)
{
powershell.exe '#Command'
}
PowerShellInfo