mars123
Goto Top

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.

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

Content-Key: 357088

Url: https://administrator.de/contentid/357088

Printed on: April 25, 2024 at 14:04 o'clock

Mitglied: 134464
Solution 134464 Dec 05, 2017 updated at 09:46:35 (UTC)
Goto Top
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  
Member: Clijsters
Clijsters Dec 05, 2017 updated at 10:08:40 (UTC)
Goto Top
Hallo Mars123,

Warum sollte man dafuer symlinks erstellen?!

Ich finde bierverleihs Vorschlag super.

Beste Gruesse
Dominique