列出所有共享目录路径
list_share.vbs
----------------------------
Option Explicit
Dim strComputer
'Do
' strComputer = inputbox( "Please enter name of a computer (or . for local host)", "Input" )
'Loop until strComputer <> ""
strComputer = "."
ListShares( strComputer )
' WScript.Echo vbCrlf & "Ready."
Sub ListShares( strComputer )
Dim strObject
Dim colShares,objfso,objcsv
Dim objWMIService, objShare
dim strcsv
strcsv = "share_folder.txt"
Set objfso = CreateObject("scripting.filesystemobject")
Set objcsv = objfso.CreateTextFile(strcsv,True)
Set objWMIService = GetObject( "winmgmts://" & strComputer & "/root/cimv2" )
Set colShares = objWMIService.ExecQuery( "Select * from Win32_Share" )
For Each objShare In colShares
objcsv.WriteLine objShare.Name & " [" & objShare.Path & "]"
Next
End Sub
列出所有共享文件夹的共享权限:
list_share_permission.ps1
----------------------------------------------
<#
.SYNOPSIS
This script will list all shares on a computer, and list all the share permissions for each share.
.DESCRIPTION
The script will take a list all shares on a local or remote computer.
.PARAMETER Computer
Specifies the computer or array of computers to process
.INPUTS
Get-SharePermissions accepts pipeline of computer name(s)
.OUTPUTS
Produces an array object for each share found.
.EXAMPLE
C:PS> .Get-SharePermissions # Operates against local computer.
.EXAMPLE
C:PS> 'computerName' | .Get-SharePermissions
.EXAMPLE
C:PS> Get-Content 'computerlist.txt' | .Get-SharePermissions | Out-File 'SharePermissions.txt'
.EXAMPLE
Get-Help .Get-SharePermissions -Full
#>
# Written by BigTeddy November 15, 2011
# Last updated 9 September 2012
# Ver. 2.0
# Thanks to Michal Gajda for input with the ACE handling.
[cmdletbinding()]
param([Parameter(ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True)]$Computer = '.')
$shares = gwmi -Class win32_share -ComputerName $computer | select -ExpandProperty Name
foreach ($share in $shares) {
$acl = $null
Write-Host $share -ForegroundColor Green
Write-Host $('-' * $share.Length) -ForegroundColor Green
$objShareSec = Get-WMIObject -Class Win32_LogicalShareSecuritySetting -Filter "name='$Share'" -ComputerName $computer
try {
$SD = $objShareSec.GetSecurityDescriptor().Descriptor
foreach($ace in $SD.DACL){
$UserName = $ace.Trustee.Name
If ($ace.Trustee.Domain -ne $Null) {$UserName = "$($ace.Trustee.Domain)$UserName"}
If ($ace.Trustee.Name -eq $Null) {$UserName = $ace.Trustee.SIDString }
[Array]$ACL += New-Object Security.AccessControl.FileSystemAccessRule($UserName, $ace.AccessMask, $ace.AceType)
} #end foreach ACE
} # end try
catch
{ Write-Host "Unable to obtain permissions for $share" }
$ACL
Write-Host $('=' * 50)
} # end foreach $share
列出所有共享文件夹的NTFS权限
dir /s /b /ad > c:dirlist.txt for /F "delims=/" %%a in (c:dirlist.txt) do cacls "%%a*.*">>c:cacls1.txt
已excel显示所有共享文件夹共享权限
#==========================================================================
# NAME: ACL on Shared folder
# AUTHOR: Mladen
# DATE : 01/12/2010
# COMMENT: Check permissions on NTFS shared folder and send report to excel
# REQUIREMENTS: QuestAD for PowerShell (Quest ActiveRoles), Excel, Acces to share
# shares.txt is file with shares in format \servershare1
#==========================================================================
#$erroractionpreference = “SilentlyContinue”
$a = New-Object -comobject Excel.Application
$a.visible = $True
$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)
$c.Cells.Item(1,1) = “Share”
$c.Cells.Item(1,2) = “Account”
$c.Cells.Item(1,3) = “Permission”
$c.Cells.Item(1,4) = “User Name”
$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True
$intRow = 2
$colShares = get-content shares.txt
foreach ($strShare in $colShares)
{
$c.Cells.Item($intRow, 1) = $strShare
$c.Cells.Item($intRow, 1).Font.Bold = $True
$acl = Get-Acl $strShare
$perm = $acl.Access
foreach ($object in $perm)
{
$intRow = $intRow + 1
$userName = [string]$object.IdentityReference
$c.Cells.Item($intRow, 2) = $userName
$c.Cells.Item($intRow, 3) = [string]$object.FileSystemRights
$fullName = Get-QADUser $userName
$c.Cells.Item($intRow, 4) = $fullName.Name
}
$intRow = $intRow + 1
}
$d.EntireColumn.AutoFit()
列出所有安装的程序
Set wshShell = Wscript.CreateObject( "Wscript.Shell" )
strServer=wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("software_list_" & strServer & ".txt", True)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strComputer & "
ootcimv2")
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product")
For Each objSoftware in colSoftware
objTextFile.WriteLine objSoftware.name & "," & _
objSoftware.Vendor & "," & _
objSoftware.Version
Next
objTextFile.Close
列出所有的服务
'------------------------------------------------------------------
'List all services status:name,status,statup type,notes
'By: Liu
'------------------------------------------------------------------
strComputer = "."
Set wshShell = Wscript.CreateObject( "Wscript.Shell" )
strServer=wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%")
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.CreateTextFile("service_list_" & strserver & ".txt", True)
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "
ootcimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service ")
For Each objItem in colItems
Wscript.Echo objItem.displayName & "," & objItem.Startmode & "," & objItem.startname
file.WriteLine objItem.displayName & "," & objItem.Startmode & "," & objItem.startname
Next
列出所有安装的补丁
StrFile = "KB Report " & Replace(Date, "/", "_") & ".TXT"
strComputer = "."
Const HKEY_LOCAL_MACHINE = &H80000002
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(StrFile, 2, True)
Set objReg=GetObject("winmgmts:\" & strComputer & "
ootdefault:StdRegProv")
strKeyPath = "SoftwareMicrosoftWindowsCurrentVersionUninstall"
objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
strKB = "KB"
For Each subkey In arrSubKeys
strSubKeyPath = "SoftwareMicrosoftWindowsCurrentVersionUninstall" & subKey
strValueName = "DisplayName"
objReg.GetStringValue HKEY_LOCAL_MACHINE,strSubKeyPath,strValueName,strValue
If IsNull(strValue) Then
strName = subKey
Else
StrName = strValue
End If
If InStr(strName,strKB) > 0 Then
strKBName = strKBName & strName & vbCrLf
End If
Next
objFile.write strKBName
Wscript.Echo "Scan Done"
----
列出补丁
$objSession = New-Object -ComObject Microsoft.Update.Session $objSearcher = $objSession.CreateUpdateSearcher() $objResults = $objSearcher.Search("IsInstalled = 1") Foreach($Update in $objResults.Updates) { $Update.Title }