Сначала получим список всех компьютеров
Get-ADComputer -Filter * -Properties * |
Select -Property Name,DNSHostName,Enabled,LastLogonDate,operatingSystem |
Export-CSV "C:\Users\Public\Documents\AllComputers.csv" -Delimiter ';' -Encoding UTF8 -NoTypeInformation
Select -Property Name,DNSHostName,Enabled,LastLogonDate,operatingSystem |
Export-CSV "C:\Users\Public\Documents\AllComputers.csv" -Delimiter ';' -Encoding UTF8 -NoTypeInformation
Проходим по списку компьютеров и копируем файлы AppData\Roaming\1C\1CEStart\ibases.v8i в одну папку. Можно скрипт добавить в планировщик, он будет собирать файлы по расписанию чтобы обработать компьютеры которые в данный момент были выключены.
$port=445
$timeout=100
$VerbosePreference = "Continue"
#$VerbosePreference = "SilentlyContinue"
$dst = 'C:\Users\Public\Documents\ibases'
$csv = 'C:\Users\Public\Documents\ibases.csv'
$timeout=100
$VerbosePreference = "Continue"
#$VerbosePreference = "SilentlyContinue"
$dst = 'C:\Users\Public\Documents\ibases'
$csv = 'C:\Users\Public\Documents\ibases.csv'
$compList = Get-Content "C:\Users\Public\Documents\computerlist.txt"
foreach ($comp in $compList) {
$requestCallback = $state = $null
$client = New-Object System.Net.Sockets.TcpClient
$beginConnect = $client.BeginConnect($comp,$port,$requestCallback,$state)
Start-Sleep -milli $timeOut
$src = "\\$comp\c$\users\"
if ($client.Connected) {
#write-verbose -Message "$comp connected"
$ibasespath = '\AppData\Roaming\1C\1CEStart\ibases.v8i'
$GC = Get-ChildItem $src
# where{$_.name -notcontains 'Public' -and $_.name -notcontains 'Default'}
ForEach ($user in $GC) {
$v8i = "$($src)$($user)$($ibases_path)"
if (Test-Path -Path "$v8i") {
write-verbose -Message "Copy $v8i to $dst\$($user)_$($comp)_ibases.txt"
Copy-Item -Path $v8i -Destination "$dst\$($user)_$($comp)_ibases.txt"
Parse-Config -ConfigFilePath $v8i
} else {
Write-Verbose -Message "Not found: $($src)$($user)$($ibases_path)"
}
}
} else {
Write-Verbose -Message "$comp - connection failed"
}
$client.Close()
}
foreach ($comp in $compList) {
$requestCallback = $state = $null
$client = New-Object System.Net.Sockets.TcpClient
$beginConnect = $client.BeginConnect($comp,$port,$requestCallback,$state)
Start-Sleep -milli $timeOut
$src = "\\$comp\c$\users\"
if ($client.Connected) {
#write-verbose -Message "$comp connected"
$ibasespath = '\AppData\Roaming\1C\1CEStart\ibases.v8i'
$GC = Get-ChildItem $src
# where{$_.name -notcontains 'Public' -and $_.name -notcontains 'Default'}
ForEach ($user in $GC) {
$v8i = "$($src)$($user)$($ibases_path)"
if (Test-Path -Path "$v8i") {
write-verbose -Message "Copy $v8i to $dst\$($user)_$($comp)_ibases.txt"
Copy-Item -Path $v8i -Destination "$dst\$($user)_$($comp)_ibases.txt"
Parse-Config -ConfigFilePath $v8i
} else {
Write-Verbose -Message "Not found: $($src)$($user)$($ibases_path)"
}
}
} else {
Write-Verbose -Message "$comp - connection failed"
}
$client.Close()
}
Соберём информацию из файлов в один csv
$VerbosePreference = "Continue"
$dst = 'C:\Users\Public\Documents\ibases\'
$csv = 'C:\Users\Public\Documents\ibases2.csv'
$comp = ''
Function parse-v8i {
param (
$v8iFilePath
)
$dbfn = ''
$srv = ''
$db = ''
$ConfigContent = Get-Content $v8iFilePath -Encoding UTF8
$IBases = $ConfigContent | ForEach-Object {
if ($_ -match '(?''dbfn''^\[.+\]$)'){
$dbfn = $Matches['dbfn']
}
if ($_ -match 'Connect=Srvr="(?''Srv''[^"]+)";Ref="(?''db''[^"]+)";'){
$srv = $Matches['srv']
$db = $Matches['DB']
}
if ($db -and $dbfn -and $srv){
$content=[pscustomobject]@{
DBFN = $dbfn
SRV = $srv
IB = $db
filename = $file
}
$dbfn = ''
$srv = ''
$db = ''
$content | Export-Csv -Path $csv -Delimiter ';' -Encoding UTF8 -NoTypeInformation -Append
}
}
}
$GC = Get-ChildItem $dst
ForEach ($file in $GC) {
$v8i = "$($dst)$($file)"
write-verbose -Message "Parse $v8i"
Parse-Config -v8iFilePath $v8i
}
$dst = 'C:\Users\Public\Documents\ibases\'
$csv = 'C:\Users\Public\Documents\ibases2.csv'
$comp = ''
Function parse-v8i {
param (
$v8iFilePath
)
$dbfn = ''
$srv = ''
$db = ''
$ConfigContent = Get-Content $v8iFilePath -Encoding UTF8
$IBases = $ConfigContent | ForEach-Object {
if ($_ -match '(?''dbfn''^\[.+\]$)'){
$dbfn = $Matches['dbfn']
}
if ($_ -match 'Connect=Srvr="(?''Srv''[^"]+)";Ref="(?''db''[^"]+)";'){
$srv = $Matches['srv']
$db = $Matches['DB']
}
if ($db -and $dbfn -and $srv){
$content=[pscustomobject]@{
DBFN = $dbfn
SRV = $srv
IB = $db
filename = $file
}
$dbfn = ''
$srv = ''
$db = ''
$content | Export-Csv -Path $csv -Delimiter ';' -Encoding UTF8 -NoTypeInformation -Append
}
}
}
$GC = Get-ChildItem $dst
ForEach ($file in $GC) {
$v8i = "$($dst)$($file)"
write-verbose -Message "Parse $v8i"
Parse-Config -v8iFilePath $v8i
}
Ратнер Арсений, arsenyratner@gmail.com, 7 985 273 2090
Комментариев нет:
Отправить комментарий