-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPowershell-Utilities.ps1
More file actions
122 lines (98 loc) · 5.01 KB
/
Powershell-Utilities.ps1
File metadata and controls
122 lines (98 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
## ██╗ ██╗████████╗██╗██╗ ██╗████████╗██╗███████╗███████╗
## ██║ ██║╚══██╔══╝██║██║ ██║╚══██╔══╝██║██╔════╝██╔════╝
## ██║ ██║ ██║ ██║██║ ██║ ██║ ██║█████╗ ███████╗
## ██║ ██║ ██║ ██║██║ ██║ ██║ ██║██╔══╝ ╚════██║
## ╚██████╔╝ ██║ ██║███████╗██║ ██║ ██║███████╗███████║
## ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝
##
## Scripts section
##
## Used for getting api keys / passwords / anything sensitive without exposing the info via uploaded scripts
function Get-SecretInfo() {
param(
[Parameter(Mandatory=$True)][string]$Name
)
$Data = Get-Content -Path "C:\PSScripts\Kingdom.txt"
foreach($Line in $Data) {
if($Line -match $Name) {
$SecureKey = $Line -replace "$Name=", "" | ConvertTo-SecureString
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureKey)
$Return = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
}
}
Return $Return
}
## For adding new keys / passwords / anything sensitive to the kingdom.txt file.
function Set-SecretInfo() {
param(
[Parameter(Mandatory=$True)][string]$Name,
[Parameter(Mandatory=$True)][string]$Key
)
$Data = Get-ChildItem -Path "C:\PSScripts\Kingdom.txt"
$SecureKey = ConvertTo-SecureString $Key -AsPlainText -Force | ConvertFrom-SecureString
Add-Content -Path $Data "$Name=$SecureKey"
Write-Host "Added $Name=$Key"
}
##
## QoL Scripts
##
## Camel Case
function ConvertTo-CamelCase() {
param(
[Parameter(Mandatory=$True)][string]$Text
)
Return (Get-Culture).TextInfo.ToTitleCase($Text)
}
## Upper Case
function ConvertTo-UpperCase() {
param(
[Parameter(Mandatory=$True)][string]$Text
)
Return $Text.ToUpper()
}
## Lower Case
function ConvertTo-LowerCase() {
param(
[Parameter(Mandatory=$True)][string]$Text
)
Return $Text.ToLower()
}
## Cause I'm Lazy
function Write-Message() {
param(
[Parameter(Mandatory=$True)][string][ValidateSet("Error", "Bot", "Load", "Blank")]$Type,
[Parameter(Mandatory=$True)][string]$Text,
[Parameter(Mandatory=$False)][string]$Username,
[Parameter(Mandatory=$False)][string]$Prefix,
[Parameter(Mandatory=$False)][string][ValidateScript({ $_ -in [Enum]::GetValues([System.ConsoleColor])})]$PrefixColour = "White",
[Parameter(Mandatory=$False)][string][ValidateScript({ $_ -in [Enum]::GetValues([System.ConsoleColor])})]$PrefixBackgroundColour = "Magenta",
[Parameter(Mandatory=$False)][string][ValidateScript({ $_ -in [Enum]::GetValues([System.ConsoleColor])})]$UsernameColour
)
if($Type -eq "Error") { Write-Host " Error! " -ForegroundColor Red -BackgroundColor Yellow -NoNewline; Write-Host " $Text " -ForegroundColor White -BackgroundColor Black -NoNewline; Write-Host " " -BackgroundColor Yellow }
if($Type -eq "Bot") { $Date = Get-Date -Format "yyyy-MM-dd hh:mm:ss"; Write-Host "$Date | " -NoNewline; Write-Host "$Username" -NoNewline -ForegroundColor $UsernameColour ; Write-Host ": $Text" }
if($Type -eq "Load") { Write-Host " Loaded " -ForegroundColor White -BackgroundColor Green -NoNewline; Write-Host " $Text " -ForegroundColor White -BackgroundColor Black }
if($Type -eq "Blank") { Write-Host " $Prefix " -ForegroundColor $PrefixColour -BackgroundColor $PrefixBackgroundColour -NoNewline; Write-Host " $Text " -ForegroundColor White -BackgroundColor Black }
}
function Write-Log {
param(
[Parameter(Mandatory=$False)][string]$Path,
[Parameter(Mandatory=$False)][validateset("Tv", "Telegram", "Test")][string]$Type,
[Parameter(Mandatory=$True)][string]$Text,
[Parameter(Mandatory=$False)][switch]$RotateLogs
)
#if(!(Test-Path -Path $Path)) { Write-Message -Type Error -Text "Path does not exist $Path" }
if($RotateLogs) {
New-Item "$Path" -type file
Add-Content $loglocation "$date > Created Logfile"
}
switch($Type) {
{$_ -match "Tv"} {
#Add-Content -Value "$Text"
Add-Content -Path "E:\log.txt" "$date > Oldname is: $oldname"
Add-Content -Path "E:\log.txt" " > Newname is: $newname$extension"
Add-Content -Path "E:\log.txt" " > Maybe junk: $maybejunk"
}
{$_ -match "Telegram"} { Add-Content -Path "E:\telegram_chatlog.txt" -Value "$Text" }
{$_ -match "Test"} { Add-Content -Path "E:\testlog.txt" -Value "$Text" }
}
}