Hallo an alle,
ich habe eine Funktion geschrieben, um bestimmten Gruppen die NTFS-Berechtigung von Laufwerken zu entziehen.
Die Funktion wird von einem Hauptskript aufgerufen, was als Tasksequenz-Schritt bei einer Serverinstallation über SCCM ausgeführt wird.
Rufe ich die Funktion manuell auf dem Server aus, werden die Berechtigungen sauber entfernt. Vom Hauptskript aufgerufen bekomme ich Fehlermeldungen, allerdings erst nach dem zweiten Laufwerk, dass es keinen Laufwerksbuchstaben mit dem Namen gibt. Anbei die
Funktion:
function Remove-GroupfromDrivesACL
{
#Define and validate parameters
[CmdletBinding()]
Param(
#Group
[parameter(Mandatory=$True,ValueFromPipeline=$False)]
[String]$Group,
[parameter(Mandatory=$True,ValueFromPipeline=$True)]
[String]$DrivePath
)
Process
{
try
{
$objUser = New-Object System.Security.Principal.NTAccount("$Group")
$colRights = [System.Security.AccessControl.FileSystemRights]'ReadAndExecute'
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::None
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::None
$objType =[System.Security.AccessControl.AccessControlType]::Allow
$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule ($objUser, $colRights, $InheritanceFlag, $PropagationFlag, $objType)
$objACL = (Get-Item $DrivePath -ErrorAction Stop).GetAccessControl('Access')
$objACL.RemoveAccessRuleAll($objACE)
Set-ACL -Path $DrivePath -AclObject $objACL -ErrorAction Stop
Write-Log -LogPath $Global:LogPath -LogString ('Remove NTFS rights for group ' + $Group + ' on path ' + $DrivePath) -Severity Success -Host $Host -EventLog
}
catch [Exception]
{
Write-Log -LogPath $Global:LogPath -LogString ('Remove NTFS rights for group ' + $Group + ' on path ' + $DrivePath + ' ' + $_.Exception.Message) -Severity Success -Host $Host -EventLog
exit}
}
}
Der Aufruf erfolgt vom Hauptskript so:
$DrivePathes = @((Get-WmiObject Win32_Volume | Where-Object {(($_.DriveLetter -ne 'C:') -and ($_.DriveType -eq '3'))}).DriveLetter | ForEach-Object {$_ + '\'})
$GroupstoRemove = @('Everyone','Creator Owner','Users')
ForEach ($DrivePath in $DrivePathes)
{
ForEach ($Group in $GroupstoRemove)
{
Remove-PwCGroupfromDrivesACL -Group $Group -DrivePath $DrivePath -ErrorAction Stop
}
}
Die Fehlermeldung im Log sieht so aus:
Remove NTFS rights for group Everyone on path D:\
Remove NTFS rights for group Everyone on path E:\ Cannot find drive. A drive with the name 'E' does not exist.
Hat jemand eine Idee? Vielen Dank im Voraus.