-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJProject.psf
More file actions
97 lines (52 loc) · 1.7 KB
/
JProject.psf
File metadata and controls
97 lines (52 loc) · 1.7 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
$formFolderCreator_Load={
#TODO: Initialize Form Controls here
$compname = (Get-WmiObject -Class Win32_ComputerSystem -Property Name).Name
Write-Host $compname
}
<#TODO:add user
assaign the user to a group to a local machine
create the folder
only give administration to user for the folder
only close when all credentials are filled
#>
$buttonCreate_Click= {
$switch = "True"
if (-not $textbox1.Text)
{
[System.Windows.Forms.MessageBox]::Show($owner, 'Error, please enter information')
#Throw 'No Username Specified'
}
else
{
$name = $textbox1.Text
$Location = "C:\$name"
$compname = (Get-WmiObject -Class Win32_ComputerSystem -Property Name).Name
If ((Test-Path $Location) -eq $False)
{
New-Item -ItemType directory -Path $Location
$Username = $textbox1.Text
$Password = $textbox2.Text
$group = "Administrators"
$adsi = [ADSI]"WinNT://$env:COMPUTERNAME"
$existing = $adsi.Children | where { $_.SchemaClassName -eq 'user' -and $_.Name -eq $Username }
if ($existing -eq $null)
{
Write-Host "Creating new local user $Username."
& NET USER $Username $Password /add /y /expires:never
Write-Host "Adding local user $Username to $group."
& NET LOCALGROUP $group $Username /add
}
else
{
Write-Host "Setting password for existing local user $Username."
$existing.SetPassword($Password)
}
Write-Host "Ensuring password for $Username never expires."
& WMIC USERACCOUNT WHERE "Name='$Username'" SET PasswordExpires=FALSE
} # End of folder exists test
Else
{
[System.Windows.Forms.MessageBox]::Show($owner, 'Folder Already Exists')
}
}
}