PowerShell 2 - 能够获取所有共享文件夹和共享对象
PowerShell 2 - Being Able To Get All Share Folders And People Shared With
我仅限于 PowerShell 2。
我正在尝试捕获为“所有人”用户组设置完全控制的所有共享文件夹。
我找到了下面列出当前共享的 PowerShell 命令,但是,它没有列出共享对象:
Get-WmiObject -Class Win32_LogicalShareSecuritySetting
通过这项检查,我想确保没有共享文件夹选择了“所有人”用户组来完全控制。
谁能帮我解决这个问题?
编辑:
如果 everyone 用户组存在完全控制选项,则仅输出共享:
@JonathanWaring 走在正确的轨道上。 Where-Object
命令中的 comparison statement 直到 PowerShell 3.0 才存在,因此我们必须稍微调整代码以使其与 PowerShell 2.0 一起使用。我们还应该让它在路径上输出更多信息:
$Found = @()
Get-WmiObject win32_logicalsharesecuritysetting | ForEach-Object {
$Path = "\localhost\" + $_.Name
Get-Acl -Path $Path | Select-Object Path -ExpandProperty Access | ForEach-Object {
If($_.IdentityReference -eq 'Everyone' -and $_.FileSystemRights -eq 'FullControl')
{
$Found += $_.Path
}
}
}
Write-Host "Found: $($Found.Count)"
Write-Host "Share locations:"
$Found | ForEach-Object {
Write-Host $_.Replace('Microsoft.PowerShell.Core\FileSystem::\localhost\','')
}
我仅限于 PowerShell 2。
我正在尝试捕获为“所有人”用户组设置完全控制的所有共享文件夹。
我找到了下面列出当前共享的 PowerShell 命令,但是,它没有列出共享对象:
Get-WmiObject -Class Win32_LogicalShareSecuritySetting
通过这项检查,我想确保没有共享文件夹选择了“所有人”用户组来完全控制。
谁能帮我解决这个问题?
编辑:
如果 everyone 用户组存在完全控制选项,则仅输出共享:
@JonathanWaring 走在正确的轨道上。 Where-Object
命令中的 comparison statement 直到 PowerShell 3.0 才存在,因此我们必须稍微调整代码以使其与 PowerShell 2.0 一起使用。我们还应该让它在路径上输出更多信息:
$Found = @()
Get-WmiObject win32_logicalsharesecuritysetting | ForEach-Object {
$Path = "\localhost\" + $_.Name
Get-Acl -Path $Path | Select-Object Path -ExpandProperty Access | ForEach-Object {
If($_.IdentityReference -eq 'Everyone' -and $_.FileSystemRights -eq 'FullControl')
{
$Found += $_.Path
}
}
}
Write-Host "Found: $($Found.Count)"
Write-Host "Share locations:"
$Found | ForEach-Object {
Write-Host $_.Replace('Microsoft.PowerShell.Core\FileSystem::\localhost\','')
}