-
Notifications
You must be signed in to change notification settings - Fork 0
/
homeDrivePermissionCheck.ps1
42 lines (38 loc) · 1.45 KB
/
homeDrivePermissionCheck.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
$ErrorActionPreference='Stop'
function Check-Command($cmdname)
{
return [bool](Get-Command -Name $cmdname -ErrorAction SilentlyContinue)
}
$destinationFile = 'survey.txt'
remote-item $destinationFile -force
$padding='############################################'
$fileName='PermissionsTest.txt'
$entries = @()
gci | select -first 5 | % {
$username = 'username placeholder'
$object = New-Object PSObject -property @{
username = $userName
HomeDirectory = $_.Name
}
$entries += $object
}
$entries | Foreach-Object {
[string]$homeDirectory=$_.HomeDirectory
[string]$name=$_.username
write-output "Testing Path $homeDirectory" | out-file -Append $destinationFIle
Get-Acl $homeDirectory | select -ExpandProperty Access | ? { $_.IdentityReference -eq "Place username here" } | Out-FIle -Append $destinationFile
Try {
new-item -path $HomeDirectory -Name $filename -type "file" -value "this is a test file" -force
Invoke-Item $homeDirectory
Start-Sleep 5
$shell = new-object -ComObject shell.application
$window = $shell.Windows() | ? $_.Name -eq 'Windows Explorer'
$window.quit()
Write-Output "Write file $filename to $homeDirectory" | out-file -append $destinationFile
write-output "$padding" | out-file -append $destinationFile
}
catch {
write-output "Unable to write to directory $homeDirectory" | out-file -append $destinationFile
write-output "$padding" | out-file -append $destinationFile
}
}