90 lines
1.7 KiB
PowerShell
90 lines
1.7 KiB
PowerShell
param(
|
|
[Parameter(Mandatory=$true)]
|
|
[string]$url,
|
|
[Parameter(Mandatory=$true)]
|
|
[string]$filePath
|
|
)
|
|
|
|
function Write-File($msg)
|
|
{
|
|
($msg) | Out-File "log-restore.txt" -Append
|
|
}
|
|
|
|
function Write-Info($msg)
|
|
{
|
|
Write-Host $msg -foregroundcolor green
|
|
Write-File $msg
|
|
}
|
|
|
|
function Write-Warn($msg)
|
|
{
|
|
Write-Host $msg -foregroundcolor yellow
|
|
Write-File $msg
|
|
}
|
|
|
|
function Add-Users-To-Group($web, $group, $usersStr)
|
|
{
|
|
if ([System.String]::IsNullOrEmpty($usersStr))
|
|
{
|
|
return
|
|
}
|
|
|
|
Write-Info ("Add users to group " + $group.Name)
|
|
|
|
$users = $usersStr.Split(";")
|
|
foreach ($u in $users)
|
|
{
|
|
if ([System.String]::IsNullOrEmpty($u))
|
|
{
|
|
continue
|
|
}
|
|
|
|
$user = $web.EnsureUser($u)
|
|
Write-Info (" " + $user.LoginName)
|
|
$group.AddUser($user)
|
|
}
|
|
}
|
|
|
|
function Check-Web($web, $lines)
|
|
{
|
|
$url = $web.Url
|
|
|
|
Write-Info ("Check users for " + $url)
|
|
$idx = -1
|
|
$i = 0
|
|
foreach ($line in $lines)
|
|
{
|
|
if ($line.ToLower() -eq $url.ToLower())
|
|
{
|
|
$idx = $i
|
|
break
|
|
}
|
|
$i = $i + 1
|
|
}
|
|
|
|
if ($idx -lt 0)
|
|
{
|
|
Write-Warn ("PMC url not found")
|
|
return
|
|
}
|
|
|
|
$groupHowzee = $lines[$idx + 1]
|
|
Write-Info ("Howzee: " + $groupHowzee)
|
|
|
|
foreach ($g in $web.Groups)
|
|
{
|
|
if ($g.Name -eq "Howzee")
|
|
{
|
|
Add-Users-To-Group $web $g $groupHowzee
|
|
}
|
|
}
|
|
}
|
|
|
|
$lines = [System.IO.File]::ReadAllLines($filePath)
|
|
$wa = Get-SPWebApplication $url
|
|
foreach ($site in $wa.Sites)
|
|
{
|
|
Check-Web $site.RootWeb $lines
|
|
}
|
|
#$site = Get-SPSite $url
|
|
#Check-Web $site.RootWeb $lines |