-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.ps1
70 lines (49 loc) · 1.7 KB
/
demo.ps1
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
# Loads functions and classes from commons.ps1
. .\powerpy.ps1
# # Creates a standard powershell array
$test = @("In an array","test1")
# Using the print function from commons to print an array
print($test)
# Using the len() function from commons to check the length of an array
if(len($test) -eq 2){
# Demonstrating the use of arguments with the print() function
print -data "test" -end " no"
# Demonstating another syntax of how args can be used with the print() function
print(int(10))("")(" ")
}
# Demonstrates the new list class (How to create, add data, get data)
$a = [list]::new()
$a.data = @("test", "test 1")
# Prints the data from the list class at index 1 (starts at index 0)
print $a.get(1)
# Creating a list from an array
$list = list($test)
$list.add("Third object")
# Remove an object at a given index
$list.remove(1)
# Demonstrate the request class
$req = [request]::get("https://google.com")
# Create a new dict object and set values
$dict = [dict]::new()
$dict.set("test", "testing")
$dict.set("index", "10")
# Remove an item via key from a dict
$dict.remove("index")
# Rremove a pair from a dict and return the value
$key = $dict.pop("test")
# Create a new instance of the PowerSys class
$sys = [PowerSys]::new()
# Write to the stdout (by default the terminal/console)
$sys.stdout.write('This will show in the console')
# Create a new file
$file = [file]::new()
# Set the name of the file
$file.filename = "test.txt"
# Set the stdout to be the file
$sys.stdout.set($file)
# Write to the stdout (now a file)
$sys.stdout.write('This will appear in a file')
# Gets the cwd
$location = Get-Location
# Prints the name of all files and folders within the cwd
print([os]::listdir($location))