При каких условиях необходимо будет перезапускать этот скрипт?
<#
.PARAMETER Computer
This parameter can be used instead of the InputFile parameter to specify a single computer or a series of
computers using a comma-separated format
.PARAMETER Trustee
The SamAccount name of an AD User or AD Group that is to be added to the Local Administrators group
.EXAMPLE
.\Add-PermAndShare.ps1 -Computer Server01 -Trustee JaapBrasser
Description:
Will set the the JaapBrasser account as a Local Administrator on Server01
.EXAMPLE
.\Add-PermAndShare.ps1 -Computer 'Server01,Server02' -Trustee Contoso\HRManagers
Description:
Will set the HRManagers group in the contoso domain as Local Administrators on Server01 and Server02
.EXAMPLE
.\Add-PermAndShare.ps1 -InputFile C:\ListofComputers.txt -Trustee User01
#>
param(
[Parameter(ParameterSetName='InputFile')]
[string]
InputFile,[Parameter(ParameterSetName=′Computer′)][string]Computer,
[string]
Trustee
)
<#
.SYNOPSIS
Function that resolves SAMAccount and can exit script if resolution fails
#>
function Resolve-SamAccount {
param(
[string]
SamAccount,
[boolean]
Exit
)
process {
try
{
ADResolve = ([adsisearcher]"(samaccountname=Trustee)").findone().properties['samaccountname']
}
catch
{
ADResolve = $null
}
if (!$ADResolve) {
Write-Warning "User `'$SamAccount`' not found in AD, please input correct SAM Account"
if ($Exit) {
exit
}
}
$ADResolve
}
}
if (!Trustee) {
Trustee = Read-Host "Please input trustee"
}
if (!(Test-Path -Path InputFile))Write−Waimport = import-csv -Path item in ping=test-connection -ComputerName ping -eq comp = session = New-PSSession -ComputerName session -Args Trustee -ScriptBlock {
param([string]Trustee)
.sid -notlike "S-1-5-21-3899154156-1698218378-256410540-1176"
-and .localpath -notlike ""
-and .localpath -notlike ""
-and "
}
}