Аудит общих ресурсов

Сравнение существующих ресурсов с текстовым файлом

$strFile = "c:\fso\shares.txt"
Get-Content  $strFile |
foreach-object { $strShare = $_.trimend()
$strQuery = "Select * from win32_share where name ='$strShare'"
get-wmiobject -query $strQuery | 
foreach-object `
{
 if ($_.name )
  { Write-Host $_.name "is still present" }
 ELSE
  { Write-Host -foregroundcolor RED $_.name `
    " is no longer present" }
}
}

Также интересно:

Аудит неавторизованных ресурсов

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 found" -foregroundcolor red}
 }
0
Голосов пока нет

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