PS Script zum Ermitteln der Ordnerbesitzer
Hallo zusammen,
ich suche nach einem Powershell Script mit dem ich den Owner von Verzeichnissen ermitteln kann.
Dabei sollen allerdings keine Unterordner berücksichtigt werden, sondern nur die Verzeichnisse unterhalb des angegebenen Pfades.
Ich habe folgendes Script gefunden, allerdings bezieht dieses auch die Unterordner mit ein.
ich suche nach einem Powershell Script mit dem ich den Owner von Verzeichnissen ermitteln kann.
Dabei sollen allerdings keine Unterordner berücksichtigt werden, sondern nur die Verzeichnisse unterhalb des angegebenen Pfades.
Ich habe folgendes Script gefunden, allerdings bezieht dieses auch die Unterordner mit ein.
Function GetFolderOwner
{
param (
[CmdletBinding()]
[Parameter( Position=0,
Mandatory=$true,
ValueFromPipeline=$True,
ValueFromPipeLineByPropertyName=$true)]
[String]$Path,
[string]$FPath=$null
)
$JPath = "c:\Temp\SL" #Junction path
if ( $FPath.length -eq 0 ) { $FPath = $Path }
if ( $path.toLower().StartsWith($JPath.toLower() ) ) { $Jpath = ([System.IO.DirectoryInfo]$path).parent.fullname }
$JPath = $JPath + '1'
# Write-Host "==>Creating Link $jpath <==> $path"
cmd /c "mklink /d `"$Jpath`" `"$Path`"" > $null
if (Test-Path $JPath ) {
dir $JPath -force | Where { $_.PsIsContainer} | select @{Name='FullName'; expression={$FPath + '\' + $_.Name}}, @{Name='Owner'; expression={ (Get-Acl $_.FullName ).owner}}, CreationTime, LastAccessTime, LastWriteTime
}
dir $Jpath -force | where { $_.PsIsContainer } | % { GetFolderOwner -Path $($_.FullName) -FPath ($FPath +"\" + $_.name) }
# Write-Host "<==Removing $jPath"
cmd /c "rd $jPath"
}
#.Example
$RootPath = "\\Baeder\data"
$LogFile = "C:\Temp\Test.csv"
#GetFolderOwner -Path $RootPath
#GetFolderOwner -Path "D:\Depts"
#"\\Server1\Share1" | GetFolderOwner | Export-Csv $LogFile -NoTypeInformation -Encoding unicode
GetFolderOwner -Path $RootPath | Export-Csv $LogFile -NoTypeInformation -Encoding unicode
Please also mark the comments that contributed to the solution of the article
Content-Key: 357088
Url: https://administrator.de/contentid/357088
Printed on: April 25, 2024 at 22:04 o'clock
2 Comments
Latest comment
Da reicht doch im Endeffekt das hier völlig aus:
$RootPath = "\\Baeder\data"
$LogFile = "C:\Temp\Test.csv"
gci $rootpath -Directory | select Fullname,@{n='Owner';e={(get-acl $_.Fullname).Owner}} | export-csv $logfile -NoType -Delimiter ";" -Encoding UTF8