PSUtil.psm1

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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
$script:ModuleRoot = $PSScriptRoot
$script:ModuleVersion = (Import-PowerShellDataFile -Path "$($script:ModuleRoot)\PSUtil.psd1").ModuleVersion

# Detect whether at some level dotsourcing was enforced
$script:doDotSource = Get-PSFConfigValue -FullName PSUtil.Import.DoDotSource -Fallback $false
if ($PSUtil_dotsourcemodule) { $script:doDotSource = $true }

<#
Note on Resolve-Path:
All paths are sent through Resolve-Path/Resolve-PSFPath in order to convert them to the correct path separator.
This allows ignoring path separators throughout the import sequence, which could otherwise cause trouble depending on OS.
Resolve-Path can only be used for paths that already exist, Resolve-PSFPath can accept that the last leaf my not exist.
This is important when testing for paths.
#>


# Detect whether at some level loading individual module files, rather than the compiled module was enforced
$importIndividualFiles = Get-PSFConfigValue -FullName PSUtil.Import.IndividualFiles -Fallback $false
if ($PSUtil_importIndividualFiles) { $importIndividualFiles = $true }
if (Test-Path (Resolve-PSFPath -Path "$($script:ModuleRoot)\..\.git" -SingleItem -NewChild)) { $importIndividualFiles = $true }
if ("<was compiled>" -eq '<was not compiled>') { $importIndividualFiles = $true }
    
function Import-ModuleFile
{
    <#
        .SYNOPSIS
            Loads files into the module on module import.
         
        .DESCRIPTION
            This helper function is used during module initialization.
            It should always be dotsourced itself, in order to proper function.
             
            This provides a central location to react to files being imported, if later desired
         
        .PARAMETER Path
            The path to the file to load
         
        .EXAMPLE
            PS C:\> . Import-ModuleFile -File $function.FullName
     
            Imports the file stored in $function according to import policy
    #>

    [CmdletBinding()]
    Param (
        [string]
        $Path
    )
    
    if ($doDotSource) { . (Resolve-Path $Path) }
    else { $ExecutionContext.InvokeCommand.InvokeScript($false, ([scriptblock]::Create([io.file]::ReadAllText((Resolve-Path $Path)))), $null, $null) }
}

#region Load individual files
if ($importIndividualFiles)
{
    # Execute Preimport actions
    . Import-ModuleFile -Path "$ModuleRoot\internal\scripts\preimport.ps1"
    
    # Import all internal functions
    foreach ($function in (Get-ChildItem "$ModuleRoot\internal\functions" -Filter "*.ps1" -Recurse -ErrorAction Ignore))
    {
        . Import-ModuleFile -Path $function.FullName
    }
    
    # Import all public functions
    foreach ($function in (Get-ChildItem "$ModuleRoot\functions" -Filter "*.ps1" -Recurse -ErrorAction Ignore))
    {
        . Import-ModuleFile -Path $function.FullName
    }
    
    # Execute Postimport actions
    . Import-ModuleFile -Path "$ModuleRoot\internal\scripts\postimport.ps1"
    
    # End it here, do not load compiled code below
    return
}
#endregion Load individual files

#region Load compiled code
Register-PSFConfigValidation -Name "PSUBrowseHistoryOptions" -ScriptBlock {
    param (
        $Value
    )
    
    $result = New-Object PSObject -Property @{
        Message  = ""
        Value    = $null
        Success  = $false
    }
    
    try { [PSUtil.Configuration.HistoryOption]$option = $Value }
    catch
    {
        $result.Message = "Could not convert $Value into a valid help option. Please specify either of these: Session | Global"
        return $result
    }
    
    $result.Success = $true
    $result.Value = $option
    
    return $result
}

Register-PSFConfigValidation -Name "PSUConsoleWidth" -ScriptBlock {
    param (
        $Value
    )
    
    $result = New-Object PSObject -Property @{
        Message  = ""
        Value    = $null
        Success  = $false
    }
    
    try { [int]$option = $Value }
    catch
    {
        $result.Message = "Could not convert $Value into a valid integer | $_"
        return $result
    }
    
    if ($option -le 0)
    {
        $result.Message = "Cannot specify a window width of 0 or less"
        return $result
    }
    
    if ($option -gt $Host.UI.RawUI.MaxWindowSize.Width)
    {
        $result.Message = "Cannot specify a window width larger than the maximum width: $option / $($Host.UI.RawUI.MaxWindowSize.Width)"
        return $result
    }
    
    $result.Success = $true
    $result.Value = $option
    
    return $result
}

Register-PSFConfigValidation -Name "PSUGetHelpOptions" -ScriptBlock {
    param (
        $Value
    )
    
    $result = New-Object PSObject -Property @{
        Message = ""
        Value = $null
        Success = $false
    }
    
    try { [PSUtil.Configuration.HelpOption]$option = $Value }
    catch
    {
        $result.Message = "Could not convert $Value into a valid help option. Please specify either of these: Short | Detailed | Examples | Full | Window | Online"
        return $result
    }
    
    $result.Success = $true
    $result.Value = $option
    
    return $result
}

# Configure the current window width
Set-PSFConfig -Module PSUtil -Name 'Console.Width' -Value ($Host.UI.RawUI.WindowSize.Width) -Initialize -Validation "PSUConsoleWidth" -Handler { Set-PSUShell -WindowWidth $args[0] } -Description "The width of the current console"

# Buffer Length
Set-PSFConfig -Module PSUtil -Name 'Console.Buffer' -Value ($Host.UI.RawUI.BufferSize.Height) -Initialize -Validation "integerpositive" -Handler { Set-PSUShell -BufferLength $args[0] } -Description "The length of the console screen history"

# Foreground Color
Set-PSFConfig -Module PSUtil -Name 'Console.ForegroundColor' -Value ($Host.ui.rawui.ForegroundColor) -Initialize -Validation "consolecolor" -Handler { Set-PSUShell -ForegroundColor $args[0] } -Description "The foreground color used in the PowerShell console"

# Background Color
Set-PSFConfig -Module PSUtil -Name 'Console.BackgroundColor' -Value ($Host.ui.rawui.BackgroundColor) -Initialize -Validation "consolecolor" -Handler { Set-PSUShell -BackgroundColor $args[0] } -Description "The background color used in the PowerShell console"

# Window Title
Set-PSFConfig -Module PSUtil -Name 'Console.WindowTitle' -Value ($Host.ui.rawui.Windowtitle) -Initialize -Validation "string" -Handler { Set-PSUShell -WindowTitle $args[0] } -Description "The background color used in the PowerShell console"

Set-PSFConfig -Module PSUtil -Name 'Import.Aliases.Grep' -Value $true -Initialize -Validation "bool" -Handler { } -Description "Whether the module will on import create an alias named 'grep' for Select-String"
Set-PSFConfig -Module PSUtil -Name 'Import.Keybindings' -Value $true -Initialize -Validation "bool" -Handler { } -Description "Whether the module will on import register keybindings in PSReadline"
Set-PSFConfig -Module PSUtil -Name 'Import.Alias.SystemOverride' -Value $false -Initialize -Validation "bool" -Description "Whether the module will on import pverwrite some default aliases with custom versions. Affects 'select' and 'gm'"

Set-PSFConfig -Module 'PSUtil' -Name 'Import.DoDotSource' -Value $false -Initialize -Validation 'bool' -Description "Whether the module files should be dotsourced on import. By default, the files of this module are read as string value and invoked, which is faster but worse on debugging."
Set-PSFConfig -Module 'PSUtil' -Name 'Import.IndividualFiles' -Value $false -Initialize -Validation 'bool' -Description "Whether the module files should be imported individually. During the module build, all module code is compiled into few files, which are imported instead by default. Loading the compiled versions is faster, using the individual files is easier for debugging and testing out adjustments."

Set-PSFConfig -Module 'PSUtil' -Name 'Keybinding.GetHelp' -Value "F1" -Initialize -Description "The key chord(s) the open help functionality is bound to. Will provide help for the currently typed command."
Set-PSFConfig -Module 'PSUtil' -Name 'Keybinding.ExpandAlias' -Value "Shift+Spacebar" -Initialize -Description "The key chord(s) the alias expansion functionality is bound to. Will expand all aliases in the current input."
Set-PSFConfig -Module 'PSUtil' -Name 'Keybinding.CopyAll' -Value "Ctrl+Shift+c" -Initialize -Description "The key chord(s) the copy all functionality is bound to. Will copy all lines of the current input to the clipboard."
Set-PSFConfig -Module 'PSUtil' -Name 'Keybinding.BrowseHistory' -Value "F7" -Initialize -Description "The key chord(s) the browse history functionality is bound to. Will open a gridview and allow you to pick from your input history, then insert the chosen line(s) as your current input."
Set-PSFConfig -Module 'PSUtil' -Name 'Keybinding.SendToHistory' -Value "Alt+w" -Initialize -Description "The key chord(s) the send to history functionality is bound to. Your current input will be sent to history without actually executing it. Access it by using the Arrow-UP key."

Set-PSFConfig -Module PSUtil -Name 'Help.Preference' -Value ([PSUtil.Configuration.HelpOption]::Window) -Initialize -Validation "PSUGetHelpOptions" -Handler { } -Description "The way in which help is shown when pressing the 'F1' key. Can be any of the following options: Short | Detailed | Examples | Full | Window | Online"
Set-PSFConfig -Module PSUtil -Name 'History.Preference' -Value ([PSUtil.Configuration.HistoryOption]::Session) -Initialize -Validation "PSUBrowseHistoryOptions" -Handler { } -Description "Where the system will retrieve input history when pressing the 'F7' key. Can be any of the following options: Session | Global. Session includes history since the process was started, Global will try to look up the history from PSReadline log-file instead"
Set-PSFConfig -Module PSUtil -Name 'History.Limit' -Value (-1) -Initialize -Validation 'integer' -Handler { } -Description "The maximum number of history entries to show when pressing the 'F7' key. Negative numbers disable limit"
Set-PSFConfig -Module PSUtil -Name 'Expand.DefaultProperties' -Value "Definition", "Guid", "DisinguishedName", "FullName", "Name", "Length" -Initialize -Validation stringarray -Description "The properties Expand-PSUObject (exp) picks from by default"

Set-PSFConfig -Module PSUtil -Name 'Path.Temp' -Value $([System.IO.Path]::GetTempPath()) -Initialize -Validation "string" -Handler { } -Description "The path to move to when calling Invoke-PSUTemp (temp)"
Set-PSFConfig -Module PSUtil -Name 'Path.BackupStepsDefault' -Value 1 -Initialize -Validation "integer" -Description "The number of levels you stup up when calling Backup-PSULocation (bu) without parameter"


function Import-PSUAlias
{
    <#
        .SYNOPSIS
            Internal command to set aliases in a user-controlled fashion.
         
        .DESCRIPTION
            Internal command to set aliases in a user-controlled fashion.
            - Can be blocked by setting a config "PSUtil.Import.Aliases.$Name" to $false.
            - Will not overwrite existing aliases
         
        .PARAMETER Name
            Name of the alias to set.
         
        .PARAMETER Command
            Name of the command to alias.
         
        .EXAMPLE
            PS C:\> Import-PSUAlias -Name grep -Command Select-String
     
            Sets the alias grep for the command Select-String
    #>

    
    [CmdletBinding()]
    Param (
        $Name,
        
        $Command
    )
    
    if ((-not (Test-Path alias:$name)) -and (Get-PSFConfigValue -FullName PSUtil.Import.Aliases.$name -Fallback $true))
    {
        New-Alias -Name $Name -Value $Command -Force -Scope Global
    }
}

function Backup-PSULocation
{
<#
    .SYNOPSIS
        Sets the location n number of levels up.
     
    .DESCRIPTION
        You no longer have to cd ..\..\..\..\ to move back four levels. You can now
        just type bu 4
     
    .PARAMETER Levels
        Number of levels to move back.
     
    .EXAMPLE
        PS C:\Users\dlbm3\source\pullrequests\somePR\vsteam> bu 4
         
        PS C:\Users\dlbm3>
     
    .NOTES
        Author: Donovan Brown
        Source: http://donovanbrown.com/post/Why-cd-when-you-can-just-backup
     
        Thank you for sharing and granting permission to use this convenience :)
#>

    [CmdletBinding()]
    param (
        [int]
        $Levels = (Get-PSFConfigValue -FullName 'PSUtil.Path.BackupStepsDefault' -Fallback 1)
    )
    
    Set-Location -Path (,".." * $Levels | Join-PSUString -With ([System.IO.Path]::DirectorySeparatorChar))
}

Import-PSUAlias -Name "bu" -Command "Backup-PSULocation"

function Invoke-PSUDesktop
{
    <#
        .SYNOPSIS
            Function that sets the current console path to the user desktop.
         
        .DESCRIPTION
            Function that sets the current console path to the user desktop.
            Uses the current user's desktop by default, but can be set to the desktop of any locally available profile.
         
        .PARAMETER User
            Alias: u
            Choose which user's desktop path to move to. Must be available as a local profile for things to work out.
     
        .PARAMETER Get
            Alias: g
            Returns the path, rather than changing the location
         
        .EXAMPLE
            PS C:\> Desktop
     
            Sets the current location to the desktop path of the current user.
    #>

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseOutputTypeCorrectly", "")]
    [CmdletBinding()]
    Param (
        [Parameter(Position = 0)]
        [Alias('u')]
        [string]
        $User = $env:USERNAME,
        
        [Alias('g')]
        [switch]
        $Get
    )
    
    # Default Path for current user
    $Path = "$env:SystemDrive\Users\$User\Desktop"
    
    if (-not (Test-Path $Path))
    {
        Stop-PSFFunction -Message "Path to Desktop not found: $Path" -Tag fail -Target $User -Category InvalidArgument
        return
    }
    
    if ($Get) { return $Path }
    else { Push-Location $Path }
}
Import-PSUAlias -Name "desktop" -Command "Invoke-PSUDesktop"

function Invoke-PSUExplorer
{
<#
    .SYNOPSIS
        Opens the windows explorer at the specified position.
     
    .DESCRIPTION
        Opens the windows explorer at the specified position.
     
    .PARAMETER Path
        Alias: FullName
        Default: (Get-Location).Path
        The folder to open in explorer. If a file was passed the containing folder will be opened instead.
     
    .PARAMETER Module
        The module, the base folder of which should be opened.
     
    .PARAMETER Duplicates
        Setting this switch will cause the function to open the same folder multiple times, if it was passed multiple times.
        By default, the function will not open the same folder multiple times (a dir of a directory with multiple files would otherwise cause multiple open windows).
     
    .EXAMPLE
        PS C:\> dir | Explorer
         
        Opens each folder in the current directory in a separate explorer Window.
#>

    [CmdletBinding()]
    Param (
        [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
        [Alias('FullName')]
        [string[]]
        $Path = (Get-Location).ProviderPath,
        
        [System.Management.Automation.PSModuleInfo[]]
        $Module,
        
        [switch]
        $Duplicates
    )
    
    Begin {
        Write-PSFMessage -Level Debug -Message "Opening Windows Explorer at target path(s)" -Tag start
        
        # Contains previously opened folders
        $List = @()
    }
    Process {
        foreach ($Item in $Path) {
            $resolvedPath = Resolve-Path $Item
            
            if (-not (Test-Path $resolvedPath))
            {
                Stop-PSFFunction -Message "Path not found: $resolvedPath | $Item" -Continue -Category InvalidArgument -Tag input -Target $Item
            }
            
            $object = Get-Item $resolvedPath
            
            if ($object.PSIsContainer) { $finalPath = $object.FullName }
            else { $finalPath = $object.Directory.FullName }
            
            # If it was already opened once, skip it unless duplicates are enabled
            if ((-not $Duplicates) -and ($List -contains $finalPath))
            {
                Write-PSFMessage -Level Verbose -Message "Skipping folder since it already was opened once: $finalPath" -Target $Item -Tag skip
                continue
            }
            
            explorer.exe $finalPath
            $List += $finalPath
        }
        
        foreach ($Item in $Module)
        {
            if ((-not $Duplicates) -and ($List -contains $Item.ModuleBase))
            {
                Write-PSFMessage -Level Verbose -Message "Skipping folder since it already was opened once: $($Item.ModuleBase)" -Target $Item -Tag skip
                continue
            }
            explorer.exe $Item.ModuleBase
            $List += $Item.ModuleBase
        }
    }
    End {
        Write-PSFMessage -Level Debug -Message "Opening Windows Explorer at target path(s)" -Tag end
    }
}
Import-PSUAlias -Name "explorer" -Command "Invoke-PSUExplorer"

function Invoke-PSUTemp
{
    <#
        .SYNOPSIS
            Moves the current location to a temp directory.
         
        .DESCRIPTION
            Moves the current location to a temp directory.
     
            The path returned can be set by configuring the 'psutil.path.temp' configuration. E.g.:
            Set-PSFConfig "psutil.path.temp" "D:\temp\_Dump"
     
            If this configuration is not set, it will check the following locations and return the first one found:
            C:\Temp
            D:\Temp
            E:\Temp
            C:\Service
            $env:temp
         
        .PARAMETER Get
            Alias: g
            Rather than move to the directory, return its path.
         
        .EXAMPLE
            PS C:\> Invoke-PSUTemp
     
            Moves to the temporary directory.
    #>

    [CmdletBinding()]
    Param (
        [Alias('g')]
        [switch]
        $Get
    )
    
    if ($Get) { Get-PSFConfigValue -FullName 'PSUtil.Path.Temp' -Fallback $env:TEMP }
    else { Push-Location -Path (Get-PSFConfigValue -FullName 'PSUtil.Path.Temp' -Fallback $env:TEMP) }
}
Import-PSUAlias -Name "temp" -Command "Invoke-PSUTemp"

function New-PSUDirectory
{
<#
    .SYNOPSIS
        Creates a folder and moves the current path to it.
     
    .DESCRIPTION
        Creates a folder and moves the current path to it.
     
    .PARAMETER Path
        Name of the folder to create and move to.
     
    .EXAMPLE
        PS C:\> mcd Test
     
        creates folder C:\Test, then moves the current location to it.
     
    .NOTES
        Author: Donovan Brown
        Source: http://donovanbrown.com/post/How-to-create-and-navigate-a-directory-with-a-single-command
     
        Thank you for sharing and granting permission to use this convenience :)
#>

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        $Path
    )
    
    New-Item -Path $Path -ItemType Directory
    
    Set-Location -Path $Path
}

Import-PSUAlias -Name "mcd" -Command "New-PSUDirectory"

function Set-PSUDrive
{
<#
    .SYNOPSIS
        Creates a new psdrive, and moves location to it.
     
    .DESCRIPTION
        Will create a PSDrive, by default in the current path.
        This allows swiftly reducing path length.
        Then it will immediately change location to the new drive.
     
    .PARAMETER Name
        What to name the new PSDrive?
     
    .PARAMETER Root
        Default: .
        The root of the new drive.
     
    .EXAMPLE
        PS C:\> set-as pr
     
        Sets the current path as drive "pr" and sets it as the current location.
     
    .NOTES
        Author: Donovan Brown
        Source: http://donovanbrown.com/post/Shorten-your-PowerShell-directory-path
     
        Thank you for sharing and granting permission to use this convenience :)
#>

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        $Name,
        
        [string]
        $Root = "."
    )
    
    $path = Resolve-Path $Root
    $null = New-PSDrive -PSProvider $path.Provider -Name $Name -Root $Root -Scope Global
    Set-Location -LiteralPath "$($Name):"
}

Import-PSUAlias -Name "set-as" -Command "Set-PSUDrive"

function Convert-PSUObject
{
<#
    .SYNOPSIS
        Converts objects from one data-type/-format to another.
     
    .DESCRIPTION
        Converts objects from one data-type/-format to another.
        For example can this be used to convert numbers from binary to hex.
     
        This function can be dynamically extended by registering conversion paths.
        Use Register-PSUObjectConversion to set up such a type conversion.
     
    .PARAMETER InputObject
        The object(s) to convert.
     
    .PARAMETER From
        The type/format that is assumed to be the input type.
     
    .PARAMETER To
        The type/format that the input is attempted to convert to.
     
    .PARAMETER EnableException
        Replaces user friendly yellow warnings with bloody red exceptions of doom!
        Use this if you want the function to throw terminating errors you want to catch.
     
    .EXAMPLE
        PS C:\> 100..110 | convert IntDec IntHex
     
        Converts the numbers 100 through 110 from decimal to hexadecimal.
#>

    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        $InputObject,
        
        [Parameter(Mandatory = $true, Position = 0)]
        [string]
        $From,
        
        [Parameter(Mandatory = $true, Position = 1)]
        [string]
        $To,
        
        [switch]
        $EnableException
    )
    
    begin
    {
        Write-PSFMessage -Level InternalComment -Message "Bound parameters: $($PSBoundParameters.Keys -join ", ")" -Tag 'debug','start','param'
        
        if (-not ([PSUtil.Object.ObjectHost]::Conversions.ContainsKey("$($From):$($To)".ToLower())))
        {
            Stop-PSFFunction -Message "No conversion path configured for $From --> $To" -EnableException $EnableException -Category NotImplemented -Tag 'fail', 'input', 'convert'
            return
        }
        
        $scriptBlock = [System.Management.Automation.ScriptBlock]::Create([PSUtil.Object.ObjectHost]::Conversions["$($From):$($To)".ToLower()].Script)
    }
    process
    {
        if (Test-PSFFunctionInterrupt) { return }
        
        foreach ($item in $InputObject)
        {
            try { $scriptBlock.Invoke($item) }
            catch
            {
                Stop-PSFFunction -Message "Failed to convert $item from $From to $To" -EnableException $EnableException -ErrorRecord $_ -Target $item -Tag 'fail','convert','item' -Continue
            }
        }
    }
    end
    {
        if (Test-PSFFunctionInterrupt) { return }
    }
}
Import-PSUAlias -Name convert -Command Convert-PSUObject

function Expand-PSUObject
{
    <#
        .SYNOPSIS
            A comfortable replacement for Select-Object -ExpandProperty.
         
        .DESCRIPTION
            A comfortable replacement for Select-Object -ExpandProperty.
            Allows extracting properties with less typing and more flexibility:
     
            Preferred Properties:
            By defining a list of property-names in $DefaultExpandedProperties the user can determine his own list of preferred properties to expand.
            This allows using this command without specifying a property at all.
            It will then check the first object for the property to use (starting from the first element of the list until it finds an exact case-insensitive match).
     
            Defined Property:
            The user can specify the exact property to extract. This is the same behavior as Select-Object -ExpandProperty, with less typing (dir | exp length).
     
            Like / Match comparison:
            Specifying either like or match allows extracting any number of matching properties from each object.
            Note that this is a somewhat more CPU-expensive operation (which shouldn't matter unless with gargantuan numbers of objects).
         
        .PARAMETER Name
            ParSet: Equals, Like, Match
            The name of the Property to expand.
         
        .PARAMETER Like
            ParSet: Like
            Expands all properties that match the -Name parameter using -like comparison.
         
        .PARAMETER Match
            ParSet: Match
            Expands all properties that match the -Name parameter using -match comparison.
         
        .PARAMETER InputObject
            The objects whose properties are to be expanded.
         
        .EXAMPLE
            PS C:\> dir | exp
     
            Expands the property whose name is the first on the defaults list ($DefaultExpandedProperties).
            By default, FullName would be expanded.
     
        .EXAMPLE
            PS C:\> dir | exp length
     
            Expands the length property of all objects returned by dir. Simply ignores those that do not have the property (folders).
     
        .EXAMPLE
            PS C:\> dir | exp name -match
     
            Expands all properties from all objects returned by dir that match the string "name" ("PSChildName", "FullName", "Name", "BaseName" for directories)
    #>

    [CmdletBinding(DefaultParameterSetName = "Equals")]
    Param (
        [Parameter(Position = 0, ParameterSetName = "Equals")]
        [Parameter(Position = 0, ParameterSetName = "Like", Mandatory = $true)]
        [Parameter(Position = 0, ParameterSetName = "Match", Mandatory = $true)]
        [string]
        $Name,
        
        [Parameter(ParameterSetName = "Like", Mandatory = $true)]
        [switch]
        $Like,
        
        [Parameter(ParameterSetName = "Match", Mandatory = $true)]
        [switch]
        $Match,
        
        [Parameter(ValueFromPipeline = $true)]
        [object]
        $InputObject
    )
    
    Begin
    {
        Write-PSFMessage -Level Debug -Message "Expanding Objects" -Tag start
        $ParSet = $PSCmdlet.ParameterSetName
        Write-PSFMessage -Level InternalComment -Message "Active Parameterset: $ParSet | Bound Parameters: $($PSBoundParameters.Keys -join ", ")" -Tag start
        
        # Null the local scoped variable (So later checks for existence don't return super-scoped variables)
        $n9ZPiBh8CI = $null
        [bool]$____found = $false
        
        # If a property was specified, set it and return it
        if (Test-PSFParameterBinding -ParameterName "Name")
        {
            $n9ZPiBh8CI = $Name
            $____found = $true
        }
        $DefaultExpandedProperties = Get-PSFConfigValue -FullName 'PSutil.Expand.DefaultProperties'
    }
    
    process
    {
        :main foreach ($Object in $InputObject)
        {
            if ($null -eq $Object) { continue }
            
            switch ($ParSet)
            {
                #region Equals
                "Equals"
                {
                    # If we didn't ask for a property in specific, and we have something prepared for this type: Run it
                    if ((Test-PSFParameterBinding -ParameterName "Name" -Not) -and ([PSUtil.Object.ObjectHost]::ExpandedTypes[$Object.GetType().FullName]))
                    {
                        [PSUtil.Object.ObjectHost]::ExpandedTypes[$Object.GetType()].Invoke($Object)
                        continue main
                    }
                    
                    # If we already have determined the property to use, return it
                    if ($____found)
                    {
                        if ($null -ne $Object.$n9ZPiBh8CI) { $Object.$n9ZPiBh8CI }
                        continue main
                    }
                    
                    # Otherwise, search through defaults and try to match
                    foreach ($Def in $DefaultExpandedProperties)
                    {
                        if (Get-Member -InputObject $Object -MemberType 'Properties' -Name $Def)
                        {
                            $n9ZPiBh8CI = $Def
                            $____found = $true
                            if ($null -ne $Object.$n9ZPiBh8CI) { $Object.$n9ZPiBh8CI }
                            
                            break
                        }
                    }
                    continue main
                }
                #endregion Equals
                
                #region Like
                "Like"
                {
                    # Return all properties whose name are similar
                    foreach ($prop in ($Object.PSObject.Properties | Where-Object Name -like $Name | Select-Object -ExpandProperty Name))
                    {
                        if ($null -ne $Object.$prop) { $Object.$prop }
                    }
                    continue
                }
                #endregion Like
                
                #region Match
                "Match"
                {
                    # Return all properties whose name match
                    foreach ($prop in ($Object.PSObject.Properties | Where-Object Name -Match $Name | Select-Object -ExpandProperty Name))
                    {
                        if ($null -ne $Object.$prop) { $Object.$prop }
                    }
                    continue main
                }
                #endregion Match
            }
        }
    }
    
    End
    {
        Write-PSFMessage -Level Debug -Message "Expanding Objects" -Tag end
    }
}
Import-PSUAlias -Name "exp" -Command "Expand-PSUObject"

function Register-PSUObjectConversion
{
<#
    .SYNOPSIS
        Registers an object conversion for Convert-PSUObject.
     
    .DESCRIPTION
        This command can be used to register an object conversion for Convert-PSUObject, allowing the user to extend the conversion utility as desired.
     
    .PARAMETER From
        The input type. Using a suitable shorthand is recommended ("int" rather than "System.Int32", etc.).
     
    .PARAMETER To
        The conversion target type. Using a suitable shorthand is recommended ("int" rather than "System.Int32", etc.).
     
    .PARAMETER ScriptBlock
        The scriptblock that will be invoked to convert.
        Receives a single argument: The input object to convert.
     
    .EXAMPLE
        PS C:\> Register-PSUObjectConversion -From 'dec' -To 'oct' -ScriptBlock $ScriptBlock
     
        Registers a conversion that is supposed to convert a decimal into an octal number.
#>

    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true)]
        [string]
        $From,
        
        [Parameter(Mandatory = $true)]
        [string]
        $To,
        
        [Parameter(Mandatory = $true)]
        [System.Management.Automation.ScriptBlock]
        $ScriptBlock
    )
    
    process
    {
        $conversion = New-Object PSUtil.Object.ObjectConversionMapping -Property @{
            From   = $From.ToLower()
            To     = $To.ToLower()
            Script = $ScriptBlock
        }
        
        [PSUtil.Object.ObjectHost]::Conversions["$($From):$($To)".ToLower()] = $conversion
    }
}

function Select-PSUObjectSample
{
    <#
        .SYNOPSIS
            Used to only pick a sample from the objects passed to the function.
         
        .DESCRIPTION
            Used to only pick a sample from the objects passed to the function.
         
        .PARAMETER InputObject
            The objects to pick a sample from.
         
        .PARAMETER Skip
            How many objects to skip.
         
        .PARAMETER Number
            How many objects to pick
            Use a negative number to pick the last X items instead.
         
        .EXAMPLE
            PS C:\> Get-ChildItem | Select-PSUObjectSample -Skip 1 -Number 3
     
            Scans the current directory, skips the first returned object, then passes through the next three objects and skips the rest.
         
        .EXAMPLE
            PS C:\> dir | s 3 1
     
            Same as the previous example, only this time using aliases and positional binding.
            Scans the current directory, skips the first returned object, then passes through the next three objects and skips the rest.
    #>

    [CmdletBinding()]
    Param (
        [Parameter(ValueFromPipeline = $true, Mandatory = $true)]
        $InputObject,
        
        [Parameter(Position = 1)]
        [int]
        $Skip = 0,
        
        [Parameter(Position = 0)]
        [int]
        $Number = 1
    )
    
    Begin
    {
        $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Select-Object', [System.Management.Automation.CommandTypes]::Cmdlet)
        $splat = @{ }
        if ($Skip -gt 0) { $splat["Skip"] = $Skip }
        if ($Number -ge 0) { $splat["First"] = $Number + 1 }
        else { $splat["Last"] = $Number * -1 }
        $scriptCmd = { & $wrappedCmd @splat }
        $steppablePipeline = $scriptCmd.GetSteppablePipeline()
        $steppablePipeline.Begin($true)
    }
    
    Process
    {
        foreach ($o in $InputObject)
        {
            $steppablePipeline.Process($o)
        }
    }
    
    End
    {
        $steppablePipeline.End()
    }
}
Import-PSUAlias -Name "s" -Command "Select-PSUObjectSample"

function Set-PSUObjectType
{
    <#
        .SYNOPSIS
            Tries to convert an object from one type of another.
         
        .DESCRIPTION
            Tries to convert an object from one type of another.
         
        .PARAMETER InputObject
            The objects to convert.
         
        .PARAMETER Type
            ParSet: Type
            The type to cast to.
         
        .PARAMETER TypeName
            ParSet: String
            The type to cast to.
         
        .PARAMETER EnableException
            Replaces user friendly yellow warnings with bloody red exceptions of doom!
            Use this if you want the function to throw terminating errors you want to catch.
         
        .EXAMPLE
            PS C:\> "01", "02", "03", "42" | Set-PSUObjectType "int"
             
            Tries to convert strings with numeric values into pure integers (hint: This will probably succeede).
    #>

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
    [CmdletBinding(DefaultParameterSetName = "String")]
    Param (
        [Parameter(ValueFromPipeline = $true)]
        $InputObject,
        
        [Parameter(ParameterSetName = "Type")]
        [Type]
        $Type,
        
        [Parameter(ParameterSetName = "String", Position = 0)]
        [String]
        $TypeName,
        
        [switch]
        $EnableException
    )
    
    Begin
    {
        Write-PSFMessage -Level Debug -Message "Casting Objects to another type" -Tag start
        $ParSet = $PSCmdlet.ParameterSetName
        Write-PSFMessage -Level InternalComment -Message "Active Parameterset: $ParSet | Bound Parameters: $($PSBoundParameters.Keys -join ", ")" -Tag start
        
        switch ($ParSet)
        {
            "Type" { $name = $Type.FullName }
            "String" { $name = $TypeName }
        }
    }
    Process
    {
        foreach ($object in $InputObject)
        {
            $temp = $null
            $temp = $object -as $name
            if ($temp) { $temp }
            else { Stop-PSFFunction -Message "Failed to convert '$object' to '$name'" -EnableException $EnableException -Category InvalidData -Tag fail, cast -Target $object -Continue }
        }
    }
    End
    {
        Write-PSFMessage -Level Debug -Message "Casting Objects to another type" -Tag end
    }
}
Import-PSUAlias -Name "cast" -Command "Set-PSUObjectType"

function Select-PSUFunctionCode
{
<#
    .SYNOPSIS
        Function that shows you the definition of a function and allows you to select lines to copy to your clipboard.
     
    .DESCRIPTION
        Function that shows you the definition of a function and allows you to select lines to copy to your clipboard.
        After running this command you will see a GridView pop up. Select as many lines of code as you would like and select
        ok to copy them to your clipboard.
     
    .PARAMETER Function
        A description of the Function parameter.
     
    .PARAMETER NoWait
        Shows function code in gridview and returns control without waiting for the window to close
     
    .PARAMETER PassThru
        Presents input command(s) in gridview, selected lines (if any) get returned as output
     
    .PARAMETER NoTrim
        If enabled, the white space will not be trimmed.
     
    .PARAMETER EnableException
        Replaces user friendly yellow warnings with bloody red exceptions of doom!
        Use this if you want the function to throw terminating errors you want to catch.
     
    .EXAMPLE
        PS C:\> Select-PSUFunctionCode -function 'Start-PSUTimer'
         
        This will open up the code for the function Start-PSUTimer in a GridView window.
     
    .EXAMPLE
        PS C:\> Get-Command timer | Select-PSUFunctionCode
         
        You can also pipe functions in.
     
    .NOTES
        Author: Andrew Pla
#>

    
    [CmdletBinding(DefaultParameterSetName = 'Default')]
    param (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)]
        [ValidateNotNullOrEmpty()]
        [string[]]
        $Function,
        
        [Alias('w')]
        [Parameter(ParameterSetName = 'NoWait')]
        [switch]
        $NoWait,
        
        [Alias('p')]
        [Parameter(ParameterSetName = 'PassThru')]
        [switch]
        $PassThru,
        
        [Alias('t')]
        [switch]
        $NoTrim,
        
        [switch]
        $EnableException
    )
    
    begin
    {
        Write-PSFMessage -Level InternalComment -Message "Bound parameters: $($PSBoundParameters.Keys -join ", ")" -Tag 'debug', 'start', 'param'
        
        if ($PSVersionTable.PSVersion.Major -ge 6)
        {
            Stop-PSFFunction -Message "This command is not supported on PowerShell v6 or later!" -Category NotEnabled -Tag fail, ps6
            return
        }
        
        $FinalArray = [System.Collections.Arraylist]@()
    }
    process
    {
        if (Test-PSFFunctionInterrupt) { return }
        
        #region Process Items
        :main foreach ($item in $Function)
        {
            #region Resolve Command
            try { $command = Get-Command $item -ErrorAction Stop }
            catch { Stop-PSFFunction -Message "Failed to resolve command $item" -Tag fail -ErrorRecord $_ -Target $item -Continue -ContinueLabel main -EnableException $EnableException }
            
            switch ($command.CommandType)
            {
                'Alias'
                {
                    if ($command.ResolvedCommand.CommandType -eq "Function")
                    {
                        $functionText = $command.ResolvedCommand | Expand-PSUObject | Split-PSUString "`n"
                    }
                    else
                    {
                        Stop-PSFFunction -Message "$($command.ResolvedCommand.CommandType) not supported: The alias $item resolves to $($command.ResolvedCommand). Please supply a function or an alias for a function." -Tag fail -Target $item -Continue -ContinueLabel main -EnableException $EnableException
                    }
                }
                'Function'
                {
                    $functionText = $command | Expand-PSUObject | Split-PSUString "`n"
                }
                default
                {
                    Stop-PSFFunction -Message "$($command.CommandType) not supported: $item. Please supply a function or an alias for a function." -Tag fail -Target $item -Continue -ContinueLabel main -EnableException $EnableException
                }
            }
            #endregion Resolve Command
            
            #region Process Definition content
            $count = 1
            foreach ($line in $functionText)
            {
                $Object = [PSCustomObject]@{
                    LineNumber       = $Count
                    Text           = $line
                    Function       = $item
                }
                
                $count++
                
                if ($NoTrim)
                {
                    $null = $FinalArray.add($Object)
                }
                else
                {
                    if (-not ([string]::IsNullOrWhiteSpace($line)))
                    {
                        $null = $FinalArray.add($Object)
                    }
                }
            }
            #endregion Process Definition content
        }
        #endregion Process Items
    }
    
    end
    {
        if (Test-PSFFunctionInterrupt) { return }
        
        # This is the default behavior with no params
        if (-not ($NoWait -or $PassThru))
        {
            $data = $FinalArray | Out-GridView -PassThru -Title 'Select-PSFunctionCode' | Expand-PSUObject text
            if ($data) { $data | Set-Clipboard }
        }
        
        if ($NoWait)
        {
            $FinalArray | Out-GridView -Title 'Select-PSFunctionCode'
        }
        if ($PassThru)
        {
            $FinalArray | Out-GridView -PassThru -Title 'Select-PSFunctionCode'
        }
    }
}

Import-PSUAlias -Name "inspect" -Command "Select-PSUFunctionCode"

function Set-PSUShell
{
    <#
        .SYNOPSIS
            Command that sets various console properties
         
        .DESCRIPTION
            Command that sets various console properties.
         
        .PARAMETER WindowWidth
            The width of the console window.
            Not much of a change on windows 10, more of a chore on older console hosts.
         
        .PARAMETER BackgroundColor
            The background color to use.
            Is PSReadline aware.
         
        .PARAMETER ForegroundColor
            The foreground color to use.
            Is PSReadline aware.
         
        .PARAMETER BufferLength
            How lengthy a memory the console screen keeps.
            The size of the stuff cls clears.
         
        .PARAMETER WindowTitle
            The title the window should have.
         
        .PARAMETER EnableException
            Replaces user friendly yellow warnings with bloody red exceptions of doom!
            Use this if you want the function to throw terminating errors you want to catch.
         
        .EXAMPLE
            PS C:\> Set-PSUShell -WindowWidth 140 -WindowTitle "The Foo Shell" -ForegroundColor DarkGreen -BackgroundColor Black
     
            Sets the current shell to ...
            - 140 pixel width
            - have a title of "The Foo Shell"
            - Use a foreground color of DarkGreen for all output, default prompt color and comment color (PSReadline syntax detection remains unaffected)
            - Use a background color of Black
    #>

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
    [CmdletBinding()]
    Param (
        [int]
        $WindowWidth,
        
        [System.ConsoleColor]
        $BackgroundColor,
        
        [System.ConsoleColor]
        $ForegroundColor,
        
        [int]
        $BufferLength,
        
        [string]
        $WindowTitle,
        
        [switch]
        $EnableException
    )
    
    # Test whether the PSReadline Module is loaded
    $PSReadline = $null -ne (Get-Module PSReadline)
    
    #region Utility Functions
    function Set-ShellWindowWidth
    {
        [CmdletBinding()]
        Param (
            $WindowWidth
        )
        
        $currentWindow = $host.ui.rawui.WindowSize
        $currentBuffer = $host.ui.rawui.Buffersize
        
        if ($currentBuffer.Width -gt $WindowWidth)
        {
            # Set Window
            $currentWindow.Width = $WindowWidth
            $host.ui.rawui.WindowSize = $currentWindow
            
            # Set Buffer
            $currentBuffer.Width = $WindowWidth
            $host.ui.rawui.Buffersize = $currentBuffer
        }
        else
        {
            # Set Buffer
            $currentBuffer.Width = $WindowWidth
            $host.ui.rawui.Buffersize = $currentBuffer
            
            # Set Window
            $currentWindow.Width = $WindowWidth
            $host.ui.rawui.WindowSize = $currentWindow
        }
    }
    #endregion Utility Functions
    
    #region Set Buffer
    if (Test-PSFParameterBinding -ParameterName "BufferLength")
    {
        $currentBuffer = $host.ui.rawui.Buffersize
        $currentBuffer.Height = $BufferLength
        $host.ui.rawui.Buffersize = $currentBuffer
    }
    #endregion Set Buffer
    
    #region Set Foreground Color
    if (Test-PSFParameterBinding -ParameterName "ForegroundColor")
    {
        $host.ui.rawui.ForegroundColor = $ForegroundColor
        
        if ($PSReadline)
        {
            Set-PSReadlineOption -ContinuationPromptForegroundColor $ForegroundColor
            Set-PSReadlineOption -ForegroundColor $ForegroundColor -TokenKind 'Comment'
            Set-PSReadlineOption -ForegroundColor $ForegroundColor -TokenKind None
        }
    }
    #endregion Set Foreground Color
    
    #region Set Background Color
    if (Test-PSFParameterBinding -ParameterName "BackgroundColor")
    {
        $host.ui.rawui.BackgroundColor = $BackgroundColor
        if ($PSReadline)
        {
            Set-PSReadlineOption -ContinuationPromptBackgroundColor $BackgroundColor
            Set-PSReadlineOption -BackgroundColor $BackgroundColor -TokenKind 'None'
            Set-PSReadlineOption -BackgroundColor $BackgroundColor -TokenKind 'Comment'
            Set-PSReadlineOption -BackgroundColor $BackgroundColor -TokenKind 'Keyword'
            Set-PSReadlineOption -BackgroundColor $BackgroundColor -TokenKind 'String'
            Set-PSReadlineOption -BackgroundColor $BackgroundColor -TokenKind 'Operator'
            Set-PSReadlineOption -BackgroundColor $BackgroundColor -TokenKind 'Variable'
            Set-PSReadlineOption -BackgroundColor $BackgroundColor -TokenKind 'Command'
            Set-PSReadlineOption -BackgroundColor $BackgroundColor -TokenKind 'Type'
            Set-PSReadlineOption -BackgroundColor $BackgroundColor -TokenKind 'Number'
            Set-PSReadlineOption -BackgroundColor $BackgroundColor -TokenKind 'Member'
            Set-PSReadlineOption -BackgroundColor $BackgroundColor -TokenKind 'Parameter'
            Set-PSReadlineOption -EmphasisBackgroundColor $BackgroundColor
            Set-PSReadlineOption -ErrorBackgroundColor $BackgroundColor
        }
    }
    #endregion Set Background Color
    
    #region Set Window Title
    if (Test-PSFParameterBinding -ParameterName "WindowTitle")
    {
        $host.ui.rawui.Windowtitle = $WindowTitle
    }
    #endregion Set Window Title
    
    #region Set Window Width
    if (Test-PSFParameterBinding -ParameterName "WindowWidth")
    {
        try { Set-ShellWindowWidth -WindowWidth $WindowWidth -ErrorAction Stop }
        catch
        {
            Stop-PSFFunction -Message "Failed to set window width to $WindowWidth" -EnableException $EnableException -ErrorRecord $_ -Tag 'fail', 'width', 'console', 'window'
            return
        }
    }
    #endregion Set Window Width
}

function Start-PSUTimer
{
<#
    .SYNOPSIS
        Creates a timer that will alarm the user after it has expired.
     
    .DESCRIPTION
        Creates a timer that will alarm the user after it has expired.
        Provides both visual and sound warnings.
        Also provides a progress bar with a time remaining display.
     
    .PARAMETER Duration
        The time to wait.
     
    .PARAMETER Message
        What to wait for.
     
    .PARAMETER NoProgress
        Disables progress bar.
     
    .PARAMETER AlarmInterval
        In what time interval to write warnings and send sound.
     
    .PARAMETER AlarmCount
        How often to give warning.
     
    .EXAMPLE
        PS C:\> timer 170 Tea
     
        After 170 Duration give warning that the tea is ready.
#>

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
    [CmdletBinding()]
    param (
        [Parameter(Position = 0, Mandatory = $true)]
        [Alias('Seconds')]
        [PSFDateTime]
        $Duration,
        
        [Parameter(Position = 1, Mandatory = $true)]
        $Message,
        
        [switch]
        $NoProgress,
        
        [int]
        $AlarmInterval = 250,
        
        [int]
        $AlarmCount = 25
    )
    
    begin
    {
        Write-PSFMessage -Level InternalComment -Message "Bound parameters: $($PSBoundParameters.Keys -join ", ")" -Tag 'debug', 'start', 'param'
        
        $start = Get-Date
        $end = $Duration.Value
        
        function Get-FriendlyTime
        {
            [CmdletBinding()]
            param (
                [int]
                $Seconds
            )
            
            $tempSeconds = $Seconds
            $strings = @()
            if ($tempSeconds -gt 3599)
            {
                [int]$count = [math]::Floor(($tempSeconds / 3600))
                $strings += "{0}h" -f $count
                $tempSeconds = $tempSeconds - ($count * 3600)
            }
            
            if ($tempSeconds -gt 59)
            {
                [int]$count = [math]::Floor(($tempSeconds / 60))
                $strings += "{0}m" -f $count
                $tempSeconds = $tempSeconds - ($count * 60)
            }
            
            $strings += "{0}s" -f $tempSeconds
            
            $strings -join " "
        }
    }
    process
    {
        if (-not $NoProgress)
        {
            Write-Progress -Activity "Waiting for $Message" -Status "Starting" -PercentComplete 0
        }
        
        while ($end -gt (Get-Date))
        {
            Start-Sleep -Milliseconds 500
            
            if (-not $NoProgress)
            {
                $friendlyTime = Get-FriendlyTime -Seconds ($end - (Get-Date)).TotalSeconds
                [int]$percent = ((Get-Date) - $start).TotalSeconds / ($end - $start).TotalSeconds * 100
                Write-Progress -Activity "Waiting for $Message" -Status "Time remaining: $($friendlyTime)" -PercentComplete ([System.Math]::Min($percent, 100))
            }
        }
        
        if (-not $NoProgress)
        {
            Write-Progress -Activity "Waiting for $Message" -Completed
        }
        
        $countAlarm = 0
        while ($countAlarm -lt $AlarmCount)
        {
            Write-PSFMessage -Level Warning -Message "### $($Message) ###"
            [System.Console]::Beep(3000, $AlarmInterval)
            Start-Sleep -Milliseconds $AlarmInterval
            $countAlarm++
        }
    }
    end
    {
        
    }
}
Import-PSUAlias -Name "timer" -Command "Start-PSUTimer"

function Get-PSUPathAlias
{
<#
    .SYNOPSIS
        Gets the PSUPathAlias configuration values.
 
    .DESCRIPTION
        Gets the PSUPathAlias configuration values from the PSFConfig system.
 
    .PARAMETER Alias
        This is the name of the alias that you want for Set-PSUPath. Wildcards accepted
 
        Default Value: *
 
    .EXAMPLE
        PS C:\> Get-PSUPathAlias
     
        Returns all aliases
#>

    [CmdletBinding()]
    param (
        [string]
        $Alias = '*'
    )
    
    $aliases = Get-PSFConfig -FullName psutil.pathalias.$Alias
    
    foreach ($alias in $aliases)
    {
        [pscustomobject]@{
            Alias = ($alias.fullname -replace '^psutil.pathalias.')
            Path  = $alias.value
        }
    }
}

function Remove-PSUPathAlias
{
<#
    .SYNOPSIS
        Removes a path alias fromm the configuration system.
     
    .DESCRIPTION
        Removes a path alias from the configuration system using Unregister-PSFConfig.
        Note: This command has no effect on configuration setings currently in memory.
     
    .PARAMETER Alias
        The name of the Alias that you want to remove from the configuration system.
     
    .EXAMPLE
        PS C:\> Remove-PSUPathAlias -Alias work
     
        Removes the path alias named work from the configuration system.
    #>

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
    [CmdletBinding()]
    param (
        [Parameter(ValuefromPipelineByPropertyName = $true)]
        $Alias
    )
    
    process
    {
        Get-PSFConfig -FullName psutil.pathalias.$Alias | Unregister-PSFConfig
        Remove-PSFAlias -Name $Alias
    }
}

function Set-PSUPath
{
<#
    .SYNOPSIS
        Detects the alias that called it and sets the location to the corresponding path found in the configuration system.
 
    .DESCRIPTION
        Detects the alias that called it and sets the location to the corresponding path.
        This function will normally be called using an alias that gets set by using Set-PSUPathAlias.
 
    .PARAMETER Alias
        This is the name of the alias that called the command.
            Default Value is $MyInvocation.line and is detected automatically
 
    .PARAMETER EnableException
        Replaces user friendly yellow warnings with bloody red exceptions of doom!
        Use this if you want the function to throw terminating errors you want to catch.
 
    .EXAMPLE
        PS C:\> Software
        PS C:\Software>
 
        In this example 'Software' is an alias for Set-PSUPath that was created by using Set-PSUPathAlias.
        Set-PSUPath detected that 'Software' was the alias that called it and then sends it to the path.
        It receives the path from Get-PSUPathAlias 'software'
#>

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
    [CmdletBinding()]
    param (
        $Alias = $MyInvocation.line,
        
        [switch]
        $EnableException
    )
    
    Write-PSFMessage -Level InternalComment -Message "Bound parameters: $($PSBoundParameters.Keys -join ", ")" -Tag 'debug', 'start', 'param'
    try
    {
        $PSFConfigPath = Get-PSFConfigValue -FullName psutil.pathalias.$Alias -NotNull
    }
    
    catch
    {
        Stop-PSFFunction -Message "Unable to find a path setting for the alias" -Category InvalidOperation -Tag fail -Exception $_
        return
    }
    
    try
    {
        
        if ($PSFConfigPath -contains '$env:')
        {
            Write-PSFMessage "Environmental variable detected, resolving path" -Level internalcomment
            Set-Location (Resolve-Path $PSFConfigPath)
        }
        
        else
        {
            Set-Location $PSFConfigPath
        }
    }
    catch
    {
        
        $psfFuncParams = @{
            Message = "Unable to set location to $PSFConfigPath"
            Category = 'InvalidOperation'
            Tag        = 'fail'
            ErrorRecord = $_
            EnableException = $EnableException
        }
        Stop-PSFFunction @psfFuncParams
        return
    }
}


function Set-PSUPathAlias
{
<#
    .SYNOPSIS
        Used to create an an alias that sets your location to the path you specify.
     
    .DESCRIPTION
        A detailed description of the Set-PSUPathAlias function.
     
    .PARAMETER Alias
        Name of the Alias that will be created for Set-PSUPath.
        Set-PSU Path detects the alias that called it and then finds the corresponding PSFConfig entry for it.
     
    .PARAMETER Path
        This is the path that you want your location to change to when the alias is called.
     
    .PARAMETER Register
        Causes PSUtil to remember the alias across sessions.
        For more advanced options, see Register-PSFConfig.
     
    .PARAMETER EnableException
        Replaces user friendly yellow warnings with bloody red exceptions of doom!
        Use this if you want the function to throw terminating errors you want to catch.
     
    .EXAMPLE
        PS C:\> Set-PSUPathAlias -Alias 'work' -Path 'C:\work'
        Creates an alias to Set-PSUPath that will set the location to 'c:\work'
     
    .EXAMPLE
        PS C:\> Set-PSUPathAlias -Alias 'repos' -Path 'C:\repos' -Register
         
        Creates an alias for repos and registers the setting so that it will persist between sessions.
#>

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
    [CmdletBinding()]
    param
    (
        [Parameter(Position = 0, Mandatory)]
        [string]
        $Alias,
        
        [Parameter(Position = 1, Mandatory)]
        [string]
        $Path,
        
        [switch]
        $Register,
        
        [switch]
        $EnableException
    )
    
    try
    {
        Set-PSFConfig -FullName psutil.pathalias.$Alias -Value $Path -Description 'Sets an alias for Set-PSUPath that takes you to the path specified in the value.'
    }
    catch
    {
        $stopParams = @{
            Message            = 'Error encountered. Alias not set'
            Category        = 'InvalidOperation'
            Tag                = 'Fail'
            ErroRecord        = $_
            EnableException = $EnableException
        }
        Stop-PSFFunction @stopParams
        return
    }
    
    if ($Register)
    {
        Get-PSFConfig -FullName psutil.pathalias.$Alias | Register-PSFConfig
    }
    
    try
    {
        Import-PSUAlias -Name $Alias -Command Set-PSUPath
    }
    catch
    {
        $stopParams = @{
            Message            = 'Error. Alias not set'
            Category        = 'InvalidOperation'
            Tag                = 'Fail'
            ErroRecord        = $_
            EnableException = $EnableException
        }
        Stop-PSFFunction @stopParams
        return
    }
}


function Add-PSUString
{
<#
    .SYNOPSIS
        Makes it easy to add content to a string at pipeline.
     
    .DESCRIPTION
        Makes it easy to add content to a string at pipeline.
     
    .PARAMETER InputString
        The string(s) to add content to
     
    .PARAMETER Before
        What is prepended to the input string.
     
    .PARAMETER After
        What is appended to the input string
     
    .EXAMPLE
        1..10 | Add-PSUString "srv-ctx" "-dev"
     
        Returns a set of strings from 'srv-ctx1-dev' through 'srv-ctx10-dev'
#>

    [OutputType([System.String])]
    [CmdletBinding()]
    Param (
        [Parameter(ValueFromPipeline = $true)]
        [string[]]
        $InputString,
        
        [Parameter(Position = 0)]
        [string]
        $Before = "",
        
        [Parameter(Position = 1)]
        [string]
        $After = ""
    )
    
    begin { }
    process
    {
        foreach ($line in $InputString)
        {
            "$($Before)$($line)$($After)"
        }
    }
    end { }
}
Import-PSUAlias -Name add -Command Add-PSUString
Import-PSUAlias -Name wrap -Command Add-PSUString

function Format-PSUString
{
<#
    .SYNOPSIS
        Allows formatting objects into strings.
     
    .DESCRIPTION
        Allows formatting objects into strings.
        This is equivalent to the '-f' operator, but supports input from pipeline.
     
    .PARAMETER InputObject
        The object to format
     
    .PARAMETER Format
        The format to apply to the object
     
    .PARAMETER LotSize
        Default: 1
        How many inputo bjects should be packed into the same format string.
     
    .EXAMPLE
        1..5 | format "foo {0:D2}"
     
        returns "foo 01" through "foo 05"
     
    .EXAMPLE
        1..6 | format "foo {0:D3}-{1:D3}" -LotSize 2
     
        returns "foo 001-002","foo 003-004","foo 005-006"
#>

    [OutputType([System.String])]
    [CmdletBinding()]
    Param (
        [Parameter(ValueFromPipeline = $true)]
        $InputObject,
        
        [Parameter(Position = 0, Mandatory = $true)]
        [string]
        $Format,
        
        [int]
        $LotSize = 1
    )
    
    begin
    {
        $values = @()
    }
    process
    {
        foreach ($item in $InputObject)
        {
            $values += $item
            if ($values.Count -ge $LotSize)
            {
                $Format -f $values
                $values = @()
            }
        }
    }
    end
    {
        if ($values.Count -gt 0)
        {
            $Format -f $values
        }
    }
}
Import-PSUAlias -Name format -Command Format-PSUString

function Join-PSUString
{
<#
    .SYNOPSIS
        Joins input strings together.
     
    .DESCRIPTION
        Joins input strings together.
     
    .PARAMETER InputString
        The strings to join
     
    .PARAMETER With
        What to join the strings with.
     
    .PARAMETER BatchSize
        Default: 0
        How many to join together at a time.
        If 0 or lower are specfied, all strings will be joined together.
        Otherwise, it will join [BatchSize] strigns together at a time.
     
    .EXAMPLE
        1..9 | join ","
     
        Returns "1,2,3,4,5,6,7,8,9"
     
    .EXAMPLE
        1..9 | join "," -BatchSize 5
     
        Returns "1,2,3,4,5", "6,7,8,9"
#>

    [OutputType([System.String])]
    [CmdletBinding()]
    Param (
        [Parameter(ValueFromPipeline = $true)]
        [string[]]
        $InputString,
        
        [Parameter(Position = 0)]
        [string]
        $With = ([System.Environment]::NewLine),
        
        [int]
        $BatchSize
    )
    
    begin
    {
        $lines = @()
    }
    process
    {
        foreach ($line in $InputString)
        {
            $lines += $line
            
            if (($BatchSize -gt 0) -and ($lines.Count -ge $BatchSize))
            {
                $lines -join $With
                $lines = @()
            }
        }
    }
    end
    {
        $lines -join $With
    }
}
Import-PSUAlias -Name join -Command Join-PSUString

function Remove-PSUString
{
<#
    .SYNOPSIS
        Trims a string.
     
    .DESCRIPTION
        Trims a string.
     
    .PARAMETER InputString
        The string that will be trimmed
     
    .PARAMETER What
        What should be trimmed?
     
    .PARAMETER Start
        Should only the start be trimmed?
     
    .PARAMETER End
        Should only the end be trimmed?
     
    .EXAMPLE
        Get-Content file.txt | trim
     
        Retrieves all content from file.txt, then trims each line.
#>

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
    [OutputType([System.String])]
    [CmdletBinding()]
    Param (
        [Parameter(ValueFromPipeline = $true)]
        [string[]]
        $InputString,
        
        [Parameter(Position = 0)]
        [string]
        $What = "",
        
        [switch]
        $Start,
        
        [switch]
        $End
    )
    
    begin { }
    process
    {
        foreach ($line in $InputString)
        {
            if ($Start -and (-not $End)) { $line.TrimStart($What) }
            elseif ((-not $Start) -and $End) { $line.TrimEnd($What) }
            else { $line.Trim($What) }
        }
    }
    end { }
}
Import-PSUAlias -Name trim -Command Remove-PSUString

function Set-PSUString
{
<#
    .SYNOPSIS
        Replaces a part of the input string with another.
     
    .DESCRIPTION
        Replaces a part of the input string with another.
        Supports both regex replace as well as regular .replace().
     
    .PARAMETER InputString
        The stringgs on which replacement will be performed.
     
    .PARAMETER What
        What should be replace?
     
    .PARAMETER With
        With what should it be replaced?
     
    .PARAMETER Simple
        By default, this function uses regex replace. Sometimes this may not be desirable.
        This switch enforces simple replacement, not considering any regular expression functionality.
     
    .PARAMETER Options
        Default: IgnoreCase
        When using regex replace, it may become desirable to specify options to the system.
     
    .PARAMETER EnableException
        Replaces user friendly yellow warnings with bloody red exceptions of doom!
        Use this if you want the function to throw terminating errors you want to catch.
     
    .EXAMPLE
        "abc ABC" | replace b d
     
        Returns "adc AdC".
     
    .EXAMPLE
        "abc ABC" | replace b d -Options None
     
        Returns "adc ABC"
     
    .EXAMPLE
        "abc \def" | replace "\de" "&ed" -s
     
        Returns "abc &edf"
#>

    [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
    [OutputType([System.String])]
    [CmdletBinding(DefaultParameterSetName = "regex")]
    Param (
        [Parameter(ValueFromPipeline = $true)]
        [string[]]
        $InputString,
        
        [Parameter(Position = 0, Mandatory = $true)]
        [string]
        $What,
        
        [Parameter(Position = 1, Mandatory = $true)]
        [AllowEmptyString()]
        [object]
        $With,
        
        [Parameter(ParameterSetName = "Simple")]
        [Alias('s')]
        [switch]
        $Simple,
        
        [Parameter(ParameterSetName = "Regex")]
        [System.Text.RegularExpressions.RegexOptions]
        $Options = [System.Text.RegularExpressions.RegexOptions]::IgnoreCase,
        
        [switch]
        $EnableException
    )
    
    begin
    {
        if ($With -isnot [System.Management.Automation.ScriptBlock])
        {
            $With = "$With"
        }
        elseif ($Simple)
        {
            Stop-PSFFunction -Message "Cannot do a lambda replace with a simple string replacement. Please specify a string or remove the simple parameter." -EnableException $EnableException -Category InvalidArgument -Tag 'fail','validate'
            return
        }
    }
    process
    {
        if (Test-PSFFunctionInterrupt) { return }
        
        foreach ($line in $InputString)
        {
            try
            {
                if ($Simple) { $line.Replace($What, $With) }
                else { [regex]::Replace($line, $What, $With, $Options) }
            }
            catch
            {
                Stop-PSFFunction -Message "Failed to replace line" -EnableException $EnableException -ErrorRecord $_ -Tag 'Fail', 'record' -Continue
            }
        }
    }
    end { }
}
Import-PSUAlias -Name replace -Command Set-PSUString

function Split-PSUString
{
<#
    .SYNOPSIS
        Splits a string. In a pipeline.
     
    .DESCRIPTION
        Splits a string. In a pipeline.
     
    .PARAMETER InputString
        The string(s) to split
     
    .PARAMETER With
        Default: "`n"
        What to split the string with
     
    .PARAMETER Simple
        Whether to disable regex when splitting.
     
    .PARAMETER Options
        Regex options to consider
     
    .EXAMPLE
        "abc,def" | split ","
     
        Returns "abc","def"
#>

    [OutputType([System.String[]])]
    [CmdletBinding(DefaultParameterSetName = "Regex")]
    Param (
        [Parameter(ValueFromPipeline = $true)]
        [string[]]
        $InputString,
        
        [Parameter(Position = 0)]
        [string]
        $With = "`n",
        
        [Alias('r')]
        [Parameter(ParameterSetName = "Simple")]
        [switch]
        $Simple,
        
        [Parameter(ParameterSetName = "Regex")]
        [System.Text.RegularExpressions.RegexOptions]
        $Options = [System.Text.RegularExpressions.RegexOptions]::IgnoreCase
    )
    
    begin
    {
        $IsRegex = $PSCmdlet.ParameterSetName -eq "Regex"
    }
    process
    {
        foreach ($line in $InputString)
        {
            if ($IsRegex) { [regex]::Split($line, $With, $Options) }
            else { $line.Split($With) }
        }
    }
    end { }
}
Import-PSUAlias -Name split -Command Split-PSUString

Register-PSFTeppScriptblock -Name psutil-convert-object-from -ScriptBlock {
    [PSUtil.Object.ObjectHost]::Conversions.Values.From | Select-Object -Unique
}

Register-PSFTeppScriptblock -Name psutil-convert-object-to -ScriptBlock {
    [PSUtil.Object.ObjectHost]::Conversions.Values | Where-Object From -EQ $fakeBoundParameter.From | Expand-PSUObject -Name To
}

Register-PSFTeppScriptblock -Name PSUtil-Input-Object -ScriptBlock {
    [System.Management.Automation.Language.PipelineAst]$pipelineAst = $commandAst.parent
    $index = $pipelineAst.PipelineElements.IndexOf($commandAst)
    
    #region If it's the first command
    if ($index -lt 1)
    {
        return
    }
    #endregion If it's the first command
    
    $properties = @()
    $constraintsPositive = @()
    
    #region Process pre-commands
    $inputIndex = $index - 1
    :main while ($true)
    {
        if ($pipelineAst.PipelineElements[$inputIndex].CommandElements)
        {
            # Resolve command and fail if it breaks
            $command = Get-Command $pipelineAst.PipelineElements[$inputIndex].CommandElements[0].Value -ErrorAction Ignore
            if ($command -is [System.Management.Automation.AliasInfo]) { $command = $command.ResolvedCommand }
            if (-not $command) { break }
            
            switch ($command.Name)
            {
                'Where-Object' { $inputIndex = $inputIndex - 1; continue main }
                'Tee-Object' { $inputIndex = $inputIndex - 1; continue main }
                #region Select-Object
                'Select-Object'
                {
                    $firstAst = $pipelineAst.PipelineElements[$inputIndex].CommandElements | Where-Object { $_ -is [System.Management.Automation.Language.ArrayLiteralAst] } | Select-Object -First 1
                    
                    foreach ($element in $firstAst.Elements)
                    {
                        switch ($element.GetType().FullName)
                        {
                            'System.Management.Automation.Language.StringConstantExpressionAst'
                            {
                                $constraintsPositive += $element.Value
                                if ($element.Value -notmatch "\*") { $properties += $element.Value }
                            }
                            'System.Management.Automation.Language.HashtableAst'
                            {
                                $constraintsPositive += ($element.KeyValuePairs | Where-Object Item1 -Match '^N$|^Name$' | Select-Object -First 1).Item2.ToString().Trim('"')
                                $properties += ($element.KeyValuePairs | Where-Object Item1 -Match '^N$|^Name$' | Select-Object -First 1).Item2.ToString().Trim('"')
                            }
                        }
                    }
                    $inputIndex = $inputIndex - 1;
                    continue main
                }
                #endregion Select-Object
                #region Select-PSFObject
                'Select-PSFObject'
                {
                    $firstAst = $pipelineAst.PipelineElements[$inputIndex].CommandElements | Where-Object { $_ -is [System.Management.Automation.Language.ArrayLiteralAst] } | Select-Object -First 1
                    foreach ($element in $firstAst.Elements)
                    {
                        switch ($element.GetType().FullName)
                        {
                            "System.Management.Automation.Language.StringConstantExpressionAst"
                            {
                                $par = [PSFramework.Parameter.SelectParameter]$element.Value
                                if ($par.Value -match "\*") { $constraintsPositive += $par.Value }
                                else
                                {
                                    if ($par.Value -is [System.String])
                                    {
                                        $properties += $par.Value
                                        $constraintsPositive += $par.Value
                                    }
                                    else
                                    {
                                        $properties += $par.Value["Name"]
                                        $constraintsPositive += $par.Value["Name"]
                                    }
                                }
                            }
                            "System.Management.Automation.Language.HashtableAst"
                            {
                                $properties += ($element.KeyValuePairs | Where-Object Item1 -Match '^N$|^Name$' | Select-Object -First 1).Item2.ToString().Trim('"')
                                $constraintsPositive += ($element.KeyValuePairs | Where-Object Item1 -Match '^N$|^Name$' | Select-Object -First 1).Item2.ToString().Trim('"')
                            }
                        }
                    }
                    $inputIndex = $inputIndex - 1;
                }
                #endregion Select-PSFObject
                default { break main }
            }
        }
        
        else
        {
            break
        }
    }
    
    # Catch moving through _all_ options in the pipeline
    if ($inputIndex -lt 0) { return $properties }
    #endregion Process pre-commands
    
    
    #region Input from command
    if ($pipelineAst.PipelineElements[$inputIndex].CommandElements)
    {
        if ($command = Get-Command $pipelineAst.PipelineElements[$inputIndex].CommandElements[0].Value -ErrorAction Ignore)
        {
            switch ($command.Name)
            {
                #region Default for commands
                default
                {
                    foreach ($type in $command.OutputType.Type)
                    {
                        switch ($type.GetType().FullName)
                        {
                            'System.IO.FileInfo'
                            {
                                $properties += ($type.GetMembers("Instance, Public") | Where-Object MemberType -match "Field|Property").Name
                                $properties += 'PSChildName', 'PSDrive', 'PSIsContainer', 'PSParentPath', 'PSPath', 'PSProvider', 'BaseName'
                                break
                            }
                            'System.IO.DirectoryInfo'
                            {
                                $properties += ($type.GetMembers("Instance, Public") | Where-Object MemberType -match "Field|Property").Name
                                $properties += 'PSChildName', 'PSDrive', 'PSIsContainer', 'PSParentPath', 'PSPath', 'PSProvider', 'BaseName', 'VersionInfo'
                                break
                            }
                            default { $properties += ($type.GetMembers("Instance, Public") | Where-Object MemberType -match "Field|Property").Name }
                        }
                    }
                }
                #endregion Default for commands
            }
        }
    }
    #endregion Input from command
    
    #region Input from Variable
    if ($pipelineAst.PipelineElements[$inputIndex].Expression -and $pipelineAst.PipelineElements[0].Expression[0].VariablePath)
    {
        $properties += ((Get-Variable -Name $pipelineAst.PipelineElements[0].Expression[0].VariablePath.UserPath -ValueOnly) | Select-Object -First 1 | Get-Member -MemberType Properties).Name
    }
    #endregion Input from Variable
    
    $properties | Select-Object -Unique | Sort-Object | ForEach-Object {
        if (-not $constraintsPositive) { $_ }
        foreach ($constraint in $constraintsPositive)
        {
            if ($_ -like $constraint)
            {
                $_
                break
            }
        }
    }
}

Register-PSFTeppScriptBlock -Name 'PSUtil-Module-Installed' -ScriptBlock {
    (Get-InstalledModule).Name | Select-Object -Unique
}

Register-PSFTeppScriptBlock -Name 'PSUtil-Module-Total' -ScriptBlock {
    (Get-Module -ListAvailable).Name | Select-Object -Unique
}

Register-PSFTeppScriptblock -Name 'PSUtil-Module-Repository' -ScriptBlock {
    (Get-PSRepository).Name
}

Register-PSFTeppScriptblock -Name 'PSUtil-Module-PackageProvider' -ScriptBlock {
    (Get-PackageProvider).Name
}

Register-PSFTeppScriptblock -Name psutil-userprofile -ScriptBlock {
    Get-ChildItem "$env:SystemDrive\Users" -Force | Where-Object PSIsContainer | Expand-PSUObject Name
}

Register-PSFTeppArgumentCompleter -Command Invoke-PSUDesktop -Parameter User -Name psutil-userprofile

Register-PSFTeppArgumentCompleter -Command Convert-PSUObject -Parameter From -Name psutil-convert-object-from
Register-PSFTeppArgumentCompleter -Command Convert-PSUObject -Parameter To -Name psutil-convert-object-to

#region Module
Register-PSFTeppArgumentCompleter -Command Update-Module -Parameter Name -Name 'PSUtil-Module-Installed'
Register-PSFTeppArgumentCompleter -Command Uninstall-Module -Parameter Name -Name 'PSUtil-Module-Installed'
Register-PSFTeppArgumentCompleter -Command Install-Module -Parameter Name -Name 'PSUtil-Module-Total'

Register-PSFTeppArgumentCompleter -Command Find-Command -Parameter Repository -Name 'PSUtil-Module-Repository'
Register-PSFTeppArgumentCompleter -Command Find-DscResource -Parameter Repository -Name 'PSUtil-Module-Repository'
Register-PSFTeppArgumentCompleter -Command Find-Module -Parameter Repository -Name 'PSUtil-Module-Repository'
Register-PSFTeppArgumentCompleter -Command Find-RoleCapability -Parameter Repository -Name 'PSUtil-Module-Repository'
Register-PSFTeppArgumentCompleter -Command Find-Script -Parameter Repository -Name 'PSUtil-Module-Repository'
Register-PSFTeppArgumentCompleter -Command Install-Module -Parameter Repository -Name 'PSUtil-Module-Repository'
Register-PSFTeppArgumentCompleter -Command Install-Script -Parameter Repository -Name 'PSUtil-Module-Repository'
Register-PSFTeppArgumentCompleter -Command Publish-Module -Parameter Repository -Name 'PSUtil-Module-Repository'
Register-PSFTeppArgumentCompleter -Command Publish-Script -Parameter Repository -Name 'PSUtil-Module-Repository'
Register-PSFTeppArgumentCompleter -Command Save-Module -Parameter Repository -Name 'PSUtil-Module-Repository'
Register-PSFTeppArgumentCompleter -Command Save-Script -Parameter Repository -Name 'PSUtil-Module-Repository'
Register-PSFTeppArgumentCompleter -Command Get-PSRepository -Parameter Name -Name 'PSUtil-Module-Repository'
Register-PSFTeppArgumentCompleter -Command Unregister-PSRepository -Parameter Name -Name 'PSUtil-Module-Repository'
Register-PSFTeppArgumentCompleter -Command Register-PSRepository -Parameter PackageManagementProvider -Name 'PSUtil-Module-PackageProvider'
#endregion Module

#region Select
Register-PSFTeppArgumentCompleter -Command Select-PSFObject -Parameter Property -Name PSUtil-Input-Object
Register-PSFTeppArgumentCompleter -Command Select-PSFObject -Parameter ExpandProperty -Name PSUtil-Input-Object
Register-PSFTeppArgumentCompleter -Command Select-PSFObject -Parameter ExcludeProperty -Name PSUtil-Input-Object
Register-PSFTeppArgumentCompleter -Command Select-PSFObject -Parameter ShowProperty -Name PSUtil-Input-Object
Register-PSFTeppArgumentCompleter -Command Select-PSFObject -Parameter ShowExcludeProperty -Name PSUtil-Input-Object

Register-PSFTeppArgumentCompleter -Command Select-Object -Parameter Property -Name PSUtil-Input-Object
Register-PSFTeppArgumentCompleter -Command Select-Object -Parameter ExpandProperty -Name PSUtil-Input-Object
Register-PSFTeppArgumentCompleter -Command Select-Object -Parameter ExcludeProperty -Name PSUtil-Input-Object
#endregion Select

New-PSFLicense -Product 'PSUtil' -Manufacturer 'Friedrich Weinmann' -ProductVersion $script:ModuleVersion -ProductType Module -Name MIT -Version "1.0.0.0" -Date (Get-Date "2018-12-16") -Text @"
Copyright (c) 2018 Friedrich Weinmann
 
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
 
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"@


<#
In this file, all default expansion definitions are stored.
Wrap into a region each, with corresponding region label.
#>


#region Microsoft.PowerShell.Commands.MatchInfo
[PSUtil.Object.ObjectHost]::ExpandedTypes["Microsoft.PowerShell.Commands.MatchInfo"] = {
    param (
        $Object
    )
    
    foreach ($item in $Object.Matches)
    {
        $item.Groups[1 .. ($item.Groups.Count - 1)].Value
    }
}
#endregion Microsoft.PowerShell.Commands.MatchInfo

#region Microsoft.PowerShell.Commands.MemberDefinition
[PSUtil.Object.ObjectHost]::ExpandedTypes["Microsoft.PowerShell.Commands.MemberDefinition"] = {
    param (
        $Object
    )
    
    $Object.Definition.Replace("), ", ")þ").Split("þ")
}
#endregion Microsoft.PowerShell.Commands.MemberDefinition

#region System.Management.Automation.FunctionInfo
[PSUtil.Object.ObjectHost]::ExpandedTypes["System.Management.Automation.FunctionInfo"] = {
    param (
        $Object
    )
    
    @"
function $($Object.Name)
{
$($Object.Definition)
}
"@

}
#endregion System.Management.Automation.FunctionInfo

#region System.Management.Automation.AliasInfo
[PSUtil.Object.ObjectHost]::ExpandedTypes["System.Management.Automation.AliasInfo"] = {
    param (
        $Object
    )
    
    if ($Object.ResolvedCommand.CommandType -eq "Function")
    {
        @"
function $($Object.ResolvedCommand.Name)
{
$($Object.ResolvedCommand.Definition)
}
"@

    }
    else
    {
        $Object.ResolvedCommand
    }
}
#endregion System.Management.Automation.AliasInfo

# The king of aliases
Import-PSUAlias -Name "grep" -Command "Select-String"

# Add simple aliases for everyday cmdlets
Import-PSUAlias -Name "a" -Command "Get-Alias"
Import-PSUAlias -Name "c" -Command "Get-Command"
Import-PSUAlias -Name "m" -Command "Measure-Object"
Import-PSUAlias -Name "v" -Command "Get-Variable"

# Add aliases for frequent export commands
Import-PSUAlias -Name "ix" -Command "Import-PSFClixml"
Import-PSUAlias -Name "ex" -Command "Export-PSFClixml"
Import-PSUAlias -Name "ic" -Command "Import-Csv"
Import-PSUAlias -Name "ec" -Command "Export-Csv"

# Add alias for easy clipboarding
Import-PSUAlias -Name "ocb" -Command "Set-Clipboard"

# Add alias for creating object
Import-PSUAlias -Name "new" -Command "New-Object"

# Add alias for the better select and to avoid breaking on old command
Import-PSUAlias -Name "spo" -Command "Select-PSFObject"
Import-PSUAlias -Name "Select-PSUObject" -Command "Select-PSFObject"

if (Get-PSFConfigValue -FullName 'PSUtil.Import.Alias.SystemOverride')
{
    Remove-PSFAlias -Name select -Force
    Remove-PSFAlias -Name gm -Force
    Import-PSUAlias -Name select -Command 'Select-PSFObject'
    Import-PSUAlias -Name gm -Command 'Get-PSMDMember'
}

if ((Get-PSFConfigValue -FullName "PSUtil.Import.Keybindings" -Fallback $true) -and (Get-Module PSReadline))
{
    foreach ($file in (Get-ChildItem -Path (Join-PSFPath $script:ModuleRoot 'internal' 'keybindings')))
    {
        . Import-ModuleFile -Path $file.FullName
    }
}


Set-PSFTypeAlias -Mapping @{
    "PSUSelectParameter" = "PSUtil.Parameter.SelectParameter"
}

Register-PSUObjectConversion -From dec -To bin -ScriptBlock {
    Param (
        $InputObject
    )
    
    [System.Convert]::ToString($InputObject, 2)
}

Register-PSUObjectConversion -From bin -To dec -ScriptBlock {
    Param (
        $InputObject
    )
    
    [System.Convert]::ToInt32($InputObject, 2)
}

Register-PSUObjectConversion -From dec -To hex -ScriptBlock {
    Param (
        $InputObject
    )
    
    [System.Convert]::ToString($InputObject, 16)
}

Register-PSUObjectConversion -From hex -To dec -ScriptBlock {
    Param (
        $InputObject
    )
    
    [System.Convert]::ToInt32($InputObject, 16)
}


Register-PSUObjectConversion -From dec -To oct -ScriptBlock {
    Param (
        $InputObject
    )
    
    [System.Convert]::ToString($InputObject, 8)
}

Register-PSUObjectConversion -From oct -To dec -ScriptBlock {
    Param (
        $InputObject
    )
    
    [System.Convert]::ToInt32($InputObject, 8)
}


Register-PSUObjectConversion -From hex -To bin -ScriptBlock {
    Param (
        $InputObject
    )
    
    $temp = [System.Convert]::ToInt32($InputObject, 16)
    [System.Convert]::ToString($temp, 2)
}

Register-PSUObjectConversion -From bin -To hex -ScriptBlock {
    Param (
        $InputObject
    )
    
    $temp = [System.Convert]::ToInt32($InputObject, 2)
    [System.Convert]::ToString($temp, 16)
}


Register-PSUObjectConversion -From hex -To oct -ScriptBlock {
    Param (
        $InputObject
    )
    
    $temp = [System.Convert]::ToInt32($InputObject, 16)
    [System.Convert]::ToString($temp, 8)
}

Register-PSUObjectConversion -From oct -To hex -ScriptBlock {
    Param (
        $InputObject
    )
    
    $temp = [System.Convert]::ToInt32($InputObject, 8)
    [System.Convert]::ToString($temp, 16)
}


Register-PSUObjectConversion -From bin -To oct -ScriptBlock {
    Param (
        $InputObject
    )
    
    $temp = [System.Convert]::ToInt32($InputObject, 2)
    [System.Convert]::ToString($temp, 8)
}

Register-PSUObjectConversion -From oct -To bin -ScriptBlock {
    Param (
        $InputObject
    )
    
    $temp = [System.Convert]::ToInt32($InputObject, 8)
    [System.Convert]::ToString($temp, 2)
}


Register-PSUObjectConversion -From script -To encoded -ScriptBlock {
    Param (
        $InputObject
    )
    
    $bytes = [System.Text.Encoding]::Unicode.GetBytes($InputObject)
    [Convert]::ToBase64String($bytes)
}

Register-PSUObjectConversion -From encoded -To script -ScriptBlock {
    Param (
        $InputObject
    )
    
    $bytes = [System.Convert]::FromBase64String($InputObject)
    [System.Text.Encoding]::Unicode.GetString($bytes)
}

#endregion Load compiled code