-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtakeown.ps1
More file actions
45 lines (36 loc) · 1.06 KB
/
takeown.ps1
File metadata and controls
45 lines (36 loc) · 1.06 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
#!/usr/bin/env pwsh
#if there is an issue with ownership of a folder use this script
param (
[string]$Target
)
if (-not $Target) {
$Target = Read-Host "Bitte Pfad zur Datei oder zum Ordner eingeben"
}
if (-not (Test-Path -LiteralPath $Target)) {
Write-Error "Pfad existiert nicht: $Target"
exit 1
}
if ($IsWindows) {
Write-Host "Windows erkannt. Übernehme Besitzrechte."
if (-not ([Security.Principal.WindowsPrincipal] `
[Security.Principal.WindowsIdentity]::GetCurrent()
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Error "Dieses Skript muss als Administrator ausgeführt werden."
exit 1
}
else {& takeown /f "$Target" /r /d J}
if ($LASTEXITCODE -ne 0) {
Write-Error "takeown ist fehlgeschlagen."
exit 1
}
}
else {
Write-Host "Unix-System erkannt. Setze Ownership auf aktuellen Benutzer."
$user = whoami
& sudo chown -R "$user" "$Target"
if ($LASTEXITCODE -ne 0) {
Write-Error "chown ist fehlgeschlagen."
exit 1
}
}
Write-Host "Vorgang abgeschlossen."