117 lines
5.6 KiB
PowerShell
117 lines
5.6 KiB
PowerShell
#PowerShell 3.0 Script
|
||
#Please use the "_Settings.ini"-File for configurations.
|
||
|
||
#Digital Data
|
||
#Ludwig-Rinn-Strasse 16
|
||
#35452 Heuchelheim
|
||
#Tel.: 0641 / 202360
|
||
#E-Mail: info@didalog.de
|
||
|
||
#Version Number: 1.0.0.0
|
||
#Version Date: 08.08.2019
|
||
|
||
#Requires –Version 3.0
|
||
|
||
#-----------------------------------------------------------------------------------------------------#
|
||
############################################ set variables ############################################
|
||
#-----------------------------------------------------------------------------------------------------#
|
||
|
||
[STRING]$ScriptName=(($MyInvocation.MyCommand.Name) -split "\.")[0].ToString()
|
||
[STRING]$ScriptPath=(Split-Path ($MyInvocation.MyCommand.Path))
|
||
[STRING]$LogFile="$((Get-ItemProperty -Path 'HKLM:\SOFTWARE\A.I.S. GmbH\windream\3.6\CommonFiles' -Name AppPath).AppPath)\Reporting\WMCmd.log"
|
||
[STRING]$WMCMDEXE="$((Get-ItemProperty -Path 'HKLM:\SOFTWARE\A.I.S. GmbH\windream\3.6\CommonFiles' -Name AppPath).AppPath)\ResourceKit\WMCmd.exe"
|
||
[STRING]$WINDOWSDOMAIN=$env:USERDNSDOMAIN
|
||
|
||
[ARRAY]$WINDOWSGROUPS=@("IIMUser-Group","IIMAdmin-Group","VHM-Netz-Administration","VHM-Netz-Geschäftsführung","VHM-Netz-Geschäftsprozesse","VHM-Netz-Personal","VHM-Vertrieb-Administration","VHM-Vertrieb-Geschäftsführung","VHM-Vertrieb-Geschäftsprozesse","VHM-Vertrieb-Personal")
|
||
|
||
#-----------------------------------------------------------------------------------------------------#
|
||
############################################# main part ###############################################
|
||
#-----------------------------------------------------------------------------------------------------#
|
||
|
||
#Clear Error Variable
|
||
$Error.Clear() | Out-Null
|
||
|
||
#Clear Console Output
|
||
Clear-Host
|
||
|
||
TRY {
|
||
|
||
Write-Output " " | Out-File $LogFile -Append
|
||
Write-Output "********************************************************************************" | Out-File $LogFile -Append
|
||
Write-Output "Program Startup: $ScriptName on $env:COMPUTERNAME at $(Get-Date -Format 'dd.MM.yyyy HH:mm:ss.fff')," | Out-File $LogFile -Append
|
||
Write-Output "from Account $env:USERDOMAIN\$env:USERNAME." | Out-File $LogFile -Append
|
||
Write-Output "********************************************************************************" | Out-File $LogFile -Append
|
||
|
||
Write-Output "Set LogFile path and name: $LogFile" | Out-File $LogFile -Append
|
||
Write-Output "Set WMCMD path and name: $WMCMDEXE" | Out-File $LogFile -Append
|
||
Write-Output "Set Windows Domain (in LDAP notation): $WINDOWSDOMAIN" | Out-File $LogFile -Append
|
||
Write-Output "Set $($WINDOWSGROUPS.count) Groups for the Sync" | Out-File $LogFile -Append
|
||
|
||
Write-Output " " | Out-File $LogFile -Append
|
||
Write-Output "Start windream Sync..." | Out-File $LogFile -Append
|
||
Write-Output " " | Out-File $LogFile -Append
|
||
|
||
IF (Test-Path -Path $WMCMDEXE -PathType any) {
|
||
|
||
FOREACH ($WINDOWSGROUP in $WINDOWSGROUPS) {
|
||
|
||
TRY {
|
||
|
||
$ProcessStartInfo = New-Object System.Diagnostics.ProcessStartInfo
|
||
$ProcessStartInfo.FileName = $WMCMDEXE
|
||
$ProcessStartInfo.RedirectStandardError = $true
|
||
$ProcessStartInfo.RedirectStandardOutput = $true
|
||
$ProcessStartInfo.UseShellExecute = $false
|
||
$ProcessStartInfo.Arguments = "-command `"ADJUST GROUP \`"$WINDOWSDOMAIN\$WINDOWSGROUP\`" ASYNC`" -noprompt -logcmd"
|
||
$Process = New-Object System.Diagnostics.Process
|
||
$Process.StartInfo = $ProcessStartInfo
|
||
$Process.Start() | Out-Null
|
||
$ProcessStandardOutput = $Process.StandardOutput.ReadToEnd()
|
||
If ($ProcessStandardOutput) { $ProcessStandardOutput | Out-File $LogFile -Append }
|
||
$ProcessStandardError = $Process.StandardError.ReadToEnd()
|
||
IF ($ProcessStandardError) { $ProcessStandardError | Out-File $LogFile -Append }
|
||
$Process.WaitForExit()
|
||
|
||
} #end try
|
||
|
||
CATCH {
|
||
|
||
Write-Output "Error processing Sync!" -PipelineVariable | Out-File $LogFile -Append
|
||
Write-Output $Error | Out-File $LogFile
|
||
|
||
} #end catch
|
||
|
||
} #end foreach
|
||
|
||
} #end if
|
||
|
||
ELSE {
|
||
|
||
Write-Output "WMCMD does not exist!" | Out-File $LogFile -Append
|
||
|
||
} #end else
|
||
|
||
Write-Output " " | Out-File $LogFile -Append
|
||
Write-Output "********************************************************************************" | Out-File $LogFile -Append
|
||
Write-Output "Program Completed: $ScriptName on $env:COMPUTERNAME at $(Get-Date -Format 'dd.MM.yyyy HH:mm:ss.fff')," | Out-File $LogFile -Append
|
||
Write-Output "from Account $env:USERDOMAIN\$env:USERNAME." | Out-File $LogFile -Append
|
||
Write-Output "********************************************************************************" | Out-File $LogFile -Append
|
||
|
||
} #end try
|
||
|
||
CATCH {
|
||
|
||
Write-Warning "Cannot write LogFile!"
|
||
|
||
} #end catch
|
||
|
||
#-----------------------------------------------------------------------------------------------------#
|
||
########################################### finishing part ############################################
|
||
#-----------------------------------------------------------------------------------------------------#
|
||
|
||
Remove-Variable -Name ScriptName -Force -ErrorAction SilentlyContinue
|
||
Remove-Variable -Name ScriptPath -Force -ErrorAction SilentlyContinue
|
||
Remove-Variable -Name LogFile -Force -ErrorAction SilentlyContinue
|
||
Remove-Variable -Name WMCMDEXE -Force -ErrorAction SilentlyContinue
|
||
Remove-Variable -Name WINDOWSDOMAIN -Force -ErrorAction SilentlyContinue
|
||
Remove-Variable -Name WINDOWSGROUPS -Force -ErrorAction SilentlyContinue |