Удаление несакционированных общих ресурсов

Clear-Host
$strFile = Get-Content "c:\fso\shares.txt"

$strQuery = "Select * from win32_share"
$shares = get-wmiobject -query $strQuery  

foreach ( $share in $shares)
 { 
   $shareName = $($share.name).tostring()
   $shareName = $shareName.substring(0,$shareName.length-1)

  Write-Host "Searching for share $($share.Name) ..." -ForegroundColor yellow

  if ( $strFile -match $shareName ) 
   { Write-Host "`t$($share.name) found" -foregroundcolor Green}
  ELSE
   { 
    Write-Host "`t$($share.Name) not authorized. Deleting now ..." -foregroundcolor red
	$wmiClass = "Win32_Share"
    $objWMI= Get-WmiObject -Class $wmiClass -filter "Name = '$($share.Name)'" 
    $objWMI.delete()

	}
 }
0
Голосов пока нет

Оставить комментарий