The complete folder structure has been changed or updated
This commit is contained in:
42
current/DD-Internal/Backup-Addison/Backup-Addison.cmd
Normal file
42
current/DD-Internal/Backup-Addison/Backup-Addison.cmd
Normal file
@@ -0,0 +1,42 @@
|
||||
@ECHO OFF
|
||||
TITLE DIGITAL DATA - %~n0
|
||||
ECHO -
|
||||
ECHO Windows Command Line Script
|
||||
ECHO CMD Version %CMDEXTVERSION% active!
|
||||
ECHO -
|
||||
ECHO Digital Data
|
||||
ECHO Ludwig-Rinn-Strasse 16
|
||||
ECHO 35452 Heuchelheim
|
||||
ECHO Tel.: 0641 / 202360
|
||||
ECHO E-Mail: info@didalog.de
|
||||
ECHO -
|
||||
ECHO Version Number: 1.0.0.0
|
||||
ECHO Version Date: 03.06.2018
|
||||
|
||||
pushd "%~dp0"
|
||||
setlocal
|
||||
|
||||
REM --------------------------------------------------------------
|
||||
REM ----------------------- set variables ------------------------
|
||||
REM --------------------------------------------------------------
|
||||
|
||||
SET AddisonDBService="FastObjects Server 12.0"
|
||||
SET FreeFileSyncExe="C:\Program Files\System\FreeFileSync\FreeFileSync.exe"
|
||||
SET FreeFileSyncJob="D:\ScriptFiles\Backup-Addison\Backup-Addison.ffs_batch"
|
||||
|
||||
REM --------------------------------------------------------------
|
||||
|
||||
REM --------------------------------------------------------------
|
||||
REM ------------------------- main part --------------------------
|
||||
REM --------------------------------------------------------------
|
||||
|
||||
ECHO .
|
||||
|
||||
net stop %AddisonDBService%
|
||||
timeout -t 5
|
||||
|
||||
%FreeFileSyncExe% %FreeFileSyncJob%
|
||||
|
||||
net start %AddisonDBService%
|
||||
|
||||
REM --------------------------------------------------------------
|
||||
45
current/DD-Internal/Backup-Addison/Backup-Addison.ffs_batch
Normal file
45
current/DD-Internal/Backup-Addison/Backup-Addison.ffs_batch
Normal file
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FreeFileSync XmlType="BATCH" XmlFormat="23">
|
||||
<Notes/>
|
||||
<Compare>
|
||||
<Variant>TimeAndSize</Variant>
|
||||
<Symlinks>Exclude</Symlinks>
|
||||
<IgnoreTimeShift/>
|
||||
</Compare>
|
||||
<Synchronize>
|
||||
<Differences LeftOnly="right" LeftNewer="right" RightNewer="right" RightOnly="right"/>
|
||||
<DeletionPolicy>RecycleBin</DeletionPolicy>
|
||||
<VersioningFolder Style="Replace"/>
|
||||
</Synchronize>
|
||||
<Filter>
|
||||
<Include>
|
||||
<Item>*</Item>
|
||||
</Include>
|
||||
<Exclude>
|
||||
<Item>\System Volume Information\</Item>
|
||||
<Item>\$Recycle.Bin\</Item>
|
||||
<Item>\RECYCLE?\</Item>
|
||||
<Item>\Recovery\</Item>
|
||||
<Item>*\thumbs.db</Item>
|
||||
</Exclude>
|
||||
<SizeMin Unit="None">0</SizeMin>
|
||||
<SizeMax Unit="None">0</SizeMax>
|
||||
<TimeSpan Type="None">0</TimeSpan>
|
||||
</Filter>
|
||||
<FolderPairs>
|
||||
<Pair>
|
||||
<Left>E:\DataFiles\ADDISON Software</Left>
|
||||
<Right>\\dd-sto01\f$\DD-STO01-A3\Backup\Computer\DD-VMP02-DB01\Addison\Backup-Addison-Daily</Right>
|
||||
</Pair>
|
||||
</FolderPairs>
|
||||
<Errors Ignore="true" Retry="0" Delay="5"/>
|
||||
<PostSyncCommand Condition="Completion"/>
|
||||
<LogFolder/>
|
||||
<EmailNotification Condition="Always"/>
|
||||
<GridViewType>Action</GridViewType>
|
||||
<Batch>
|
||||
<ProgressDialog Minimized="false" AutoClose="true"/>
|
||||
<ErrorDialog>Show</ErrorDialog>
|
||||
<PostSyncAction>None</PostSyncAction>
|
||||
</Batch>
|
||||
</FreeFileSync>
|
||||
40
current/DD-Internal/Backup-Addison/Backup-Addison.ffs_gui
Normal file
40
current/DD-Internal/Backup-Addison/Backup-Addison.ffs_gui
Normal file
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FreeFileSync XmlType="GUI" XmlFormat="23">
|
||||
<Notes/>
|
||||
<Compare>
|
||||
<Variant>TimeAndSize</Variant>
|
||||
<Symlinks>Exclude</Symlinks>
|
||||
<IgnoreTimeShift/>
|
||||
</Compare>
|
||||
<Synchronize>
|
||||
<Differences LeftOnly="right" LeftNewer="right" RightNewer="right" RightOnly="right"/>
|
||||
<DeletionPolicy>RecycleBin</DeletionPolicy>
|
||||
<VersioningFolder Style="Replace"/>
|
||||
</Synchronize>
|
||||
<Filter>
|
||||
<Include>
|
||||
<Item>*</Item>
|
||||
</Include>
|
||||
<Exclude>
|
||||
<Item>\System Volume Information\</Item>
|
||||
<Item>\$Recycle.Bin\</Item>
|
||||
<Item>\RECYCLE?\</Item>
|
||||
<Item>\Recovery\</Item>
|
||||
<Item>*\thumbs.db</Item>
|
||||
</Exclude>
|
||||
<SizeMin Unit="None">0</SizeMin>
|
||||
<SizeMax Unit="None">0</SizeMax>
|
||||
<TimeSpan Type="None">0</TimeSpan>
|
||||
</Filter>
|
||||
<FolderPairs>
|
||||
<Pair>
|
||||
<Left>E:\DataFiles\ADDISON Software</Left>
|
||||
<Right>\\dd-sto01\f$\DD-STO01-A3\Backup\Computer\DD-VMP02-DB01\Addison\Backup-Addison-Daily</Right>
|
||||
</Pair>
|
||||
</FolderPairs>
|
||||
<Errors Ignore="true" Retry="0" Delay="5"/>
|
||||
<PostSyncCommand Condition="Completion"/>
|
||||
<LogFolder/>
|
||||
<EmailNotification Condition="Always"/>
|
||||
<GridViewType>Action</GridViewType>
|
||||
</FreeFileSync>
|
||||
@@ -0,0 +1,118 @@
|
||||
cls
|
||||
#MK / 15.11.2024
|
||||
#Next task: write test to final path
|
||||
#Get dbs by SHOW DATABASES;
|
||||
|
||||
import-module SQLPS -Scope Local -Force
|
||||
Install-Module MySQLCmdlets
|
||||
|
||||
Set-Variable Servername -Value "localhost" -Scope global
|
||||
Set-Variable Username -Value "root" -Scope global
|
||||
Set-Variable Passwort -Value "123456789dd!" -Scope global
|
||||
Set-Variable SicherungsPfad -Value "E:\Sicherung\MariaDB" -Scope global
|
||||
Set-Variable holedatum -Value (get-date -Format 'yyyyMMdd_HHmm') -Scope global
|
||||
Set-Variable SicherungsPfadTemp -Value "$($SicherungsPfad)\$holedatum" -Scope global
|
||||
Set-Variable SicherungsPfadTempExists -Value $False -Scope global
|
||||
Set-Variable SicherungsPfadTempIsClean -Value $False -Scope global
|
||||
Set-Variable SicherungsPfadFinal -Value "\\dd-sto01\f$\DD-STO01-A3\Backup\Computer\DD-VMP02-DB01\MariaDB" -Scope global
|
||||
Set-Variable Datenbanken -Value @("nextcloud") -Scope global
|
||||
|
||||
# $dbs = Get-SqlDatabase -ServerInstance $Servername
|
||||
#######################################################################################################################
|
||||
Function Backup-SQLDatabases {
|
||||
|
||||
# Parameter definieren
|
||||
param(
|
||||
[parameter(mandatory=$true)]
|
||||
[validatecount(1, 10)]
|
||||
[string[]]$instanzen,
|
||||
[parameter(mandatory=$true)]
|
||||
[validatepattern("[A-Z]")]
|
||||
[validatecount(1,99)]
|
||||
[string]$dbs
|
||||
)
|
||||
|
||||
if( -not (test-path -Path $SicherungsPfadTemp)){
|
||||
try {
|
||||
new-item -path $SicherungsPfad -Name $holedatum -ItemType Directory -ErrorAction Stop | Out-Null
|
||||
$SicherungsPfadTempExists = $True
|
||||
|
||||
} catch {
|
||||
write-host "Ordner für Backup konnte nicht erstellt werden" -ForegroundColor Yellow
|
||||
$SicherungsPfadTempExists = $False
|
||||
}
|
||||
|
||||
} else{
|
||||
write-host "Backup-Ordner existiert bereits" -ForegroundColor Yellow
|
||||
$SicherungsPfadTempExists = $True
|
||||
}
|
||||
|
||||
IF ($SicherungsPfadTempExists = $True) {
|
||||
|
||||
write-host "Backup von der Datenbank $dbs wird erstellt" -ForegroundColor Yellow
|
||||
$arguments = "--host=$($Servername) --port=3306 --user=$($Username) --password=$($Passwort) --databases $($dbs) --result-file $($SicherungsPfadTemp)\$($db).sql"
|
||||
write-host "Parameter $($arguments)" -ForegroundColor Yellow
|
||||
Start-Process -FilePath "mysqldump.exe" -ArgumentList $arguments -Wait
|
||||
|
||||
}
|
||||
}
|
||||
#######################################################################################################################
|
||||
#Call backup task for every db
|
||||
|
||||
#target must be online
|
||||
if ((test-path -Path $SicherungsPfadFinal) -and (New-Item -Path $SicherungsPfadFinal -Name "AccessTest.tmp" -ItemType "file" -Force -ErrorAction Stop)) {
|
||||
|
||||
Write-Host "Final Path is reachable"
|
||||
Remove-Item -Path "$SicherungsPfadFinal\AccessTest.tmp" -Force -ErrorAction Continue
|
||||
|
||||
Write-Host "Checking for garbage in: $SicherungsPfad"
|
||||
$Items = Get-ChildItem -LiteralPath $SicherungsPfad -Recurse:$False -Force -ErrorAction SilentlyContinue | Where-Object { $_.PSIsContainer }
|
||||
If ($Items) {
|
||||
Try {
|
||||
FOREACH ($Item in $Items) {
|
||||
Write-Host "Moving '$($Item.FullName)' to '$SicherungsPfadFinal'"
|
||||
Move-Item -Path $($Item.FullName) -Destination $SicherungsPfadFinal -Force -ErrorAction Stop
|
||||
}
|
||||
$SicherungsPfadTempIsClean = $True
|
||||
|
||||
} Catch {
|
||||
Write-Host "Cannot clean up temp dir!"
|
||||
Write-Host $Error[0].ToString()
|
||||
$SicherungsPfadTempIsClean = $False
|
||||
}
|
||||
|
||||
} Else {
|
||||
$SicherungsPfadTempIsClean = $True
|
||||
}
|
||||
|
||||
If ($SicherungsPfadTempIsClean -eq $True) {
|
||||
|
||||
FOREACH ($db in $Datenbanken) {
|
||||
|
||||
[string]$db = $db
|
||||
$db = ($db.replace("[",""))
|
||||
$db = ($db.replace("]",""))
|
||||
|
||||
If ($db -ne "tempdb" -and $db -ne "master" -and $db -ne "model" -and $db -ne "msdb") {
|
||||
Write-Host "Sicherung von $db"
|
||||
Backup-SQLDatabases -instanzen $Servername -dbs $db
|
||||
}
|
||||
}
|
||||
#######################################################################################################################
|
||||
#move dir incl. backup files to sto01
|
||||
|
||||
Try {
|
||||
write-host $SicherungsPfadTemp
|
||||
Move-Item -Path $SicherungsPfadTemp -Destination $SicherungsPfadFinal -Force -ErrorAction Stop
|
||||
} Catch {
|
||||
Write-Host "Error moving files!"
|
||||
Write-Host $Error[0].ToSting()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} Else {
|
||||
|
||||
Write-Host "Target is offline!"
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
@ECHO OFF
|
||||
TITLE DIGITAL DATA - Run all files in directory with current permissions
|
||||
ECHO -
|
||||
ECHO Batch Script
|
||||
ECHO Run all files in directory with current permissions
|
||||
ECHO -
|
||||
ECHO Digital Data
|
||||
ECHO Ludwig-Rinn-Strasse 16
|
||||
ECHO 35452 Heuchelheim
|
||||
ECHO Tel.: 0641 / 202360
|
||||
ECHO E-Mail: info@didalog.de
|
||||
ECHO -
|
||||
ECHO Version 1.0.0.0
|
||||
ECHO Date: 13.08.2015
|
||||
ECHO -
|
||||
ECHO Program Startup %date% at %time:~0,8% oclock, on %computername%.
|
||||
|
||||
REM --------------------------------------------------------------
|
||||
REM ------------------------set variables-------------------------
|
||||
REM --------------------------------------------------------------
|
||||
|
||||
setlocal enableextensions
|
||||
|
||||
SET DIRECTORY="%cd%"
|
||||
SET FILEEXTENSION=*.ps1
|
||||
SET COUNT=0
|
||||
|
||||
REM --------------------------------------------------------------
|
||||
REM ---------------------Program 1 / Script 1---------------------
|
||||
REM --------------------------------------------------------------
|
||||
|
||||
FOR /F "tokens=*" %%f in ('dir /S /b %FILEEXTENSION%') do (ECHO %%f && set /a count+=1)
|
||||
ECHO -
|
||||
ECHO Found %count% File(s) with File Extension %FILEEXTENSION% in Directory:
|
||||
ECHO %DIRECTORY%.
|
||||
|
||||
ECHO -
|
||||
ECHO Running this/them now, with your permissions!
|
||||
FOR /F "tokens=*" %%f in ('dir /S /b %FILEEXTENSION%') do (PowerShell.exe -Command "& {Start-Process PowerShell.exe -WindowStyle hidden '-ExecutionPolicy Bypass -File "%%f"'}")
|
||||
|
||||
ECHO -
|
||||
ECHO This Window will close in:
|
||||
#timeout /T 10
|
||||
endlocal
|
||||
exit
|
||||
Binary file not shown.
130
current/DD-Internal/Backup-SQLDatabase/Backup-SQLDatabase.ps1
Normal file
130
current/DD-Internal/Backup-SQLDatabase/Backup-SQLDatabase.ps1
Normal file
@@ -0,0 +1,130 @@
|
||||
cls
|
||||
#MK / 15.11.2024
|
||||
|
||||
import-module SQLPS -Scope Local -Force
|
||||
|
||||
Set-Variable Servername -Value "DD-VMP02-DB01\ZEIT" -Scope global
|
||||
Set-Variable SicherungsPfad -Value "E:\Sicherung\SQL" -Scope global
|
||||
Set-Variable holedatum -Value (get-date -Format 'yyyyMMdd_HHmm') -Scope global
|
||||
Set-Variable SicherungsPfadTemp -Value "$($SicherungsPfad)\$holedatum" -Scope global
|
||||
Set-Variable SicherungsPfadTempExists -Value $False -Scope global
|
||||
Set-Variable SicherungsPfadTempIsClean -Value $False -Scope global
|
||||
Set-Variable SicherungsPfadFinal -Value "\\dd-sto01\f$\DD-STO01-A3\Backup\Computer\DD-VMP02-DB01\SQL\" -Scope global
|
||||
|
||||
$dbs = Get-SqlDatabase -ServerInstance $Servername
|
||||
#######################################################################################################################
|
||||
Function Backup-SQLDatabases {
|
||||
|
||||
# Parameter definieren
|
||||
param(
|
||||
[parameter(mandatory=$true)]
|
||||
[validatecount(1, 10)]
|
||||
[string[]]$instanzen,
|
||||
[parameter(mandatory=$true)]
|
||||
[validatepattern("[A-Z]")]
|
||||
[validatecount(1,99)]
|
||||
[string]$dbs
|
||||
)
|
||||
|
||||
if( -not (test-path -Path $SicherungsPfadTemp)){
|
||||
try {
|
||||
new-item -path $SicherungsPfad -Name $holedatum -ItemType Directory -ErrorAction Stop | Out-Null
|
||||
$SicherungsPfadTempExists = $True
|
||||
|
||||
} catch {
|
||||
write-host "Ordner für Backup konnte nicht erstellt werden" -ForegroundColor Yellow
|
||||
$SicherungsPfadTempExists = $False
|
||||
}
|
||||
|
||||
} else{
|
||||
write-host "Backup-Ordner existiert bereits" -ForegroundColor Yellow
|
||||
$SicherungsPfadTempExists = $True
|
||||
}
|
||||
|
||||
IF ($SicherungsPfadTempExists = $True) {
|
||||
|
||||
# For-Schleife für mehrere Instanzen
|
||||
for($i = 0; $instanzen.count -gt $i; $i++){
|
||||
write-host "Backup von der Datenbank $dbs auf der Instanz $($instanzen[$i]) wird erstellt" -ForegroundColor Yellow
|
||||
|
||||
# Backup für remote Instanzen
|
||||
if($instanzen[$i] -ne $Servername -and !$instanzen[$i] -eq $false){
|
||||
|
||||
Write-host $args[1].Substring(1, 15)
|
||||
Write-Host $args[0]
|
||||
Invoke-Command -ComputerName $instanzen[$i].Substring(1, 15) -ScriptBlock {
|
||||
|
||||
Backup-SqlDatabase -ServerInstance $args[1].Substring(1, 15) -Database $args[0] -BackupFile "$($args[2])\$($args[0]).bak"
|
||||
|
||||
} -ArgumentList $dbs, $instanzen[$i], $pfadzumbackup, $holedatum
|
||||
}
|
||||
# Backup für eine lokale Instanz
|
||||
elseif($instanzen[$i] -eq $Servername -and !$instanzen[$i] -eq $false){
|
||||
Backup-SqlDatabase -ServerInstance $instanzen[$i] -Database $dbs -BackupFile "$SicherungsPfadTemp\$($dbs).bak"
|
||||
|
||||
} else{
|
||||
write-host "$($instanzen[$i]) existiert nicht"
|
||||
}
|
||||
} # ende von for-schleife
|
||||
|
||||
}
|
||||
}
|
||||
#######################################################################################################################
|
||||
#Call backup task for every db
|
||||
|
||||
#target must be online
|
||||
if ((test-path -Path $SicherungsPfadFinal) -and (New-Item -Path $SicherungsPfadFinal -Name "AccessTest.tmp" -ItemType "file" -Force -ErrorAction Stop)) {
|
||||
|
||||
Write-Host "Final Path is reachable"
|
||||
Remove-Item -Path "$SicherungsPfadFinal\AccessTest.tmp" -Force -ErrorAction Continue
|
||||
|
||||
Write-Host "Checking for garbage in: $SicherungsPfad"
|
||||
$Items = Get-ChildItem -LiteralPath $SicherungsPfad -Recurse:$False -Force -ErrorAction SilentlyContinue | Where-Object { $_.PSIsContainer }
|
||||
If ($Items) {
|
||||
Try {
|
||||
FOREACH ($Item in $Items) {
|
||||
Write-Host "Moving '$($Item.FullName)' to '$SicherungsPfadFinal'"
|
||||
Move-Item -Path $($Item.FullName) -Destination $SicherungsPfadFinal -Force -ErrorAction Stop
|
||||
}
|
||||
$SicherungsPfadTempIsClean = $True
|
||||
|
||||
} Catch {
|
||||
Write-Host "Cannot clean up temp dir!"
|
||||
Write-Host $Error[0].ToString()
|
||||
$SicherungsPfadTempIsClean = $False
|
||||
}
|
||||
|
||||
} Else {
|
||||
$SicherungsPfadTempIsClean = $True
|
||||
}
|
||||
|
||||
If ($SicherungsPfadTempIsClean -eq $True) {
|
||||
|
||||
FOREACH ($db in $dbs) {
|
||||
|
||||
[string]$db = $db
|
||||
$db = ($db.replace("[",""))
|
||||
$db = ($db.replace("]",""))
|
||||
|
||||
If ($db -ne "tempdb" -and $db -ne "master" -and $db -ne "model" -and $db -ne "msdb") {
|
||||
Write-Host "Sicherung von $db"
|
||||
Backup-SQLDatabases -instanzen $Servername -dbs $db
|
||||
}
|
||||
}
|
||||
#######################################################################################################################
|
||||
#move dir incl. backup files to sto01
|
||||
|
||||
Try {
|
||||
write-host $SicherungsPfadTemp
|
||||
Move-Item -Path $SicherungsPfadTemp -Destination $SicherungsPfadFinal -Force -ErrorAction Stop
|
||||
} Catch {
|
||||
Write-Host "Error moving files!"
|
||||
Write-Host $Error[0].ToSting()
|
||||
}
|
||||
}
|
||||
|
||||
} Else {
|
||||
|
||||
Write-Host "Target is offline!"
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
@ECHO OFF
|
||||
TITLE DIGITAL DATA - Run all files in directory with current permissions
|
||||
ECHO -
|
||||
ECHO Batch Script
|
||||
ECHO Run all files in directory with current permissions
|
||||
ECHO -
|
||||
ECHO Digital Data
|
||||
ECHO Ludwig-Rinn-Strasse 16
|
||||
ECHO 35452 Heuchelheim
|
||||
ECHO Tel.: 0641 / 202360
|
||||
ECHO E-Mail: info@didalog.de
|
||||
ECHO -
|
||||
ECHO Version 1.0.0.0
|
||||
ECHO Date: 13.08.2015
|
||||
ECHO -
|
||||
ECHO Program Startup %date% at %time:~0,8% oclock, on %computername%.
|
||||
|
||||
REM --------------------------------------------------------------
|
||||
REM ------------------------set variables-------------------------
|
||||
REM --------------------------------------------------------------
|
||||
|
||||
setlocal enableextensions
|
||||
|
||||
SET DIRECTORY="%cd%"
|
||||
SET FILEEXTENSION=*.ps1
|
||||
SET COUNT=0
|
||||
|
||||
REM --------------------------------------------------------------
|
||||
REM ---------------------Program 1 / Script 1---------------------
|
||||
REM --------------------------------------------------------------
|
||||
|
||||
FOR /F "tokens=*" %%f in ('dir /S /b %FILEEXTENSION%') do (ECHO %%f && set /a count+=1)
|
||||
ECHO -
|
||||
ECHO Found %count% File(s) with File Extension %FILEEXTENSION% in Directory:
|
||||
ECHO %DIRECTORY%.
|
||||
|
||||
ECHO -
|
||||
ECHO Running this/them now, with your permissions!
|
||||
FOR /F "tokens=*" %%f in ('dir /S /b %FILEEXTENSION%') do (PowerShell.exe -Command "& {Start-Process PowerShell.exe -WindowStyle hidden '-ExecutionPolicy Bypass -File "%%f"'}")
|
||||
|
||||
ECHO -
|
||||
ECHO This Window will close in:
|
||||
#timeout /T 10
|
||||
endlocal
|
||||
exit
|
||||
Binary file not shown.
15
current/DD-Internal/DD-Internal_History.txt
Normal file
15
current/DD-Internal/DD-Internal_History.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Version 1.0.0.0 - 22.07.2025
|
||||
NEW: -
|
||||
FIX: -
|
||||
CHG: -
|
||||
REM: -
|
||||
|
||||
-------------------------------------legend------------------------------------
|
||||
NEW: = Added a new functionality
|
||||
FIX: = Fixed a Issue with existing functionality
|
||||
CHG: = Changed a existing functionality
|
||||
REM: = Removed a functionality
|
||||
-------------------------------------------------------------------------------
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,45 @@
|
||||
@ECHO OFF
|
||||
TITLE DIGITAL DATA - Run all files in directory with current permissions
|
||||
ECHO -
|
||||
ECHO Batch Script
|
||||
ECHO Run all files in directory with current permissions
|
||||
ECHO -
|
||||
ECHO Digital Data
|
||||
ECHO Ludwig-Rinn-Strasse 16
|
||||
ECHO 35452 Heuchelheim
|
||||
ECHO Tel.: 0641 / 202360
|
||||
ECHO E-Mail: info@didalog.de
|
||||
ECHO -
|
||||
ECHO Version 1.0.0.0
|
||||
ECHO Date: 13.08.2015
|
||||
ECHO -
|
||||
ECHO Program Startup %date% at %time:~0,8% oclock, on %computername%.
|
||||
|
||||
REM --------------------------------------------------------------
|
||||
REM ------------------------set variables-------------------------
|
||||
REM --------------------------------------------------------------
|
||||
|
||||
setlocal enableextensions
|
||||
|
||||
SET DIRECTORY="%cd%"
|
||||
SET FILEEXTENSION=*.ps1
|
||||
SET COUNT=0
|
||||
|
||||
REM --------------------------------------------------------------
|
||||
REM ---------------------Program 1 / Script 1---------------------
|
||||
REM --------------------------------------------------------------
|
||||
|
||||
FOR /F "tokens=*" %%f in ('dir /S /b %FILEEXTENSION%') do (ECHO %%f && set /a count+=1)
|
||||
ECHO -
|
||||
ECHO Found %count% File(s) with File Extension %FILEEXTENSION% in Directory:
|
||||
ECHO %DIRECTORY%.
|
||||
|
||||
ECHO -
|
||||
ECHO Running this/them now, with your permissions!
|
||||
FOR /F "tokens=*" %%f in ('dir /S /b %FILEEXTENSION%') do (PowerShell.exe -Command "& {Start-Process PowerShell.exe -WindowStyle hidden '-ExecutionPolicy Bypass -File "%%f"'}")
|
||||
|
||||
ECHO -
|
||||
ECHO This Window will close in:
|
||||
#timeout /T 10
|
||||
endlocal
|
||||
exit
|
||||
@@ -0,0 +1,53 @@
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Version 2.0.0.4 - 18.08.2025
|
||||
NEW: -
|
||||
FIX: -
|
||||
CHG: - Script accepts only one config file now
|
||||
REM: -
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Version 2.0.0.3 - 07.03.2024
|
||||
NEW: -
|
||||
FIX: - Error Folder will now only created if its necessary
|
||||
CHG: -
|
||||
REM: -
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Version 2.0.0.2 - 02.03.2022
|
||||
NEW: -
|
||||
FIX: -
|
||||
CHG: - Logging enhanced
|
||||
REM: -
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Version 2.0.0.1 - 25.02.2022
|
||||
NEW: -
|
||||
FIX: -
|
||||
CHG: - Bugfixing
|
||||
REM: -
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Version 2.0.0.0 - 21.02.2022
|
||||
NEW: -
|
||||
FIX: -
|
||||
CHG: - Complete rework to run as task in future
|
||||
REM: -
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Version 1.0.0.0 - 26.03.2021
|
||||
NEW: -
|
||||
FIX: -
|
||||
CHG: -
|
||||
REM: -
|
||||
|
||||
-------------------------------------legend------------------------------------
|
||||
NEW: = Added a new functionality
|
||||
FIX: = Fixed a Issue with existing functionality
|
||||
CHG: = Changed a existing functionality
|
||||
REM: = Removed a functionality
|
||||
-------------------------------------------------------------------------------
|
||||
Binary file not shown.
BIN
current/DD-Internal/Modules/DD_LIB_Standards.dll
Normal file
BIN
current/DD-Internal/Modules/DD_LIB_Standards.dll
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
current/DD-Internal/Modules/GdPicture.NET.14.filters.64.dll
Normal file
BIN
current/DD-Internal/Modules/GdPicture.NET.14.filters.64.dll
Normal file
Binary file not shown.
BIN
current/DD-Internal/Modules/GdPicture.NET.14.filters.dll
Normal file
BIN
current/DD-Internal/Modules/GdPicture.NET.14.filters.dll
Normal file
Binary file not shown.
Binary file not shown.
BIN
current/DD-Internal/Modules/GdPicture.NET.14.image.gdimgplug.dll
Normal file
BIN
current/DD-Internal/Modules/GdPicture.NET.14.image.gdimgplug.dll
Normal file
Binary file not shown.
186176
current/DD-Internal/Modules/GdPicture.NET.14.xml
Normal file
186176
current/DD-Internal/Modules/GdPicture.NET.14.xml
Normal file
File diff suppressed because it is too large
Load Diff
BIN
current/DD-Internal/Modules/GdPicture_NET_14.dll
Normal file
BIN
current/DD-Internal/Modules/GdPicture_NET_14.dll
Normal file
Binary file not shown.
BIN
current/DD-Internal/Modules/Import-CustomModule.ps1
Normal file
BIN
current/DD-Internal/Modules/Import-CustomModule.ps1
Normal file
Binary file not shown.
BIN
current/DD-Internal/Modules/Load-EMLFile-withLogging.psm1
Normal file
BIN
current/DD-Internal/Modules/Load-EMLFile-withLogging.psm1
Normal file
Binary file not shown.
BIN
current/DD-Internal/Modules/MS.PS.Lib.psd1
Normal file
BIN
current/DD-Internal/Modules/MS.PS.Lib.psd1
Normal file
Binary file not shown.
735
current/DD-Internal/Modules/MS.PS.Lib.psm1
Normal file
735
current/DD-Internal/Modules/MS.PS.Lib.psm1
Normal file
@@ -0,0 +1,735 @@
|
||||
<#------------------------------------------------------------------------
|
||||
|
||||
PowerShell Scripting Library
|
||||
for MailStore Server and MailStore Service Provider Edition
|
||||
|
||||
Requires Microsoft PowerShell 3.0 or higher
|
||||
|
||||
|
||||
|
||||
Copyright (c) 2014 - 2019 MailStore Software GmbH
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
------------------------------------------------------------------------#>
|
||||
|
||||
if ($PSVersionTable.PSVersion.Major -lt 3) {
|
||||
throw New-Object System.NotSupportedException "PowerShell V3 or higher required."
|
||||
}
|
||||
|
||||
[System.Net.SecurityProtocolType]$DefaultSecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 -bor [System.Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Scriptblock called by "InternalMSApiCall" to handle long running API processes.
|
||||
|
||||
.DESCRIPTION
|
||||
Scriptblock called by "InternalMSApiCall" to handle long running API processes.
|
||||
Optionally fires events to notify the parent session of Status changes.
|
||||
Returns the final HTTP response as JSON object.
|
||||
|
||||
.PARAMETER MSApiClient
|
||||
MS API client object created by "New-MSApiClient".
|
||||
|
||||
.PARAMETER StatusObject
|
||||
Initial HTTP answer returned by the API as JSON object.
|
||||
|
||||
.PARAMETER StatusTimeout
|
||||
Time in milliseconds until the the server stops waiting for a new Status updates to send.
|
||||
|
||||
.PARAMETER UseStatusEvents
|
||||
If set to true, an event is fired for each status change.
|
||||
|
||||
.FUNCTIONALITY
|
||||
start-job -ArgumentList <MS API client>, <Initial HTTP response object>, <Timeout>, <UseStatusEvents> -ScriptBlock $sbPullStatus
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/MailStore_Server_Administration_API#Long_Running_Processes
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/spe/Management_API_-_Using_the_API#Long_Running_Processes
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/MailStore_Server_Administration_API#Initial_HTTP_Response
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/spe/Management_API_-_Using_the_API#Initial_HTTP_Response
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/MailStore_Server_Administration_API#HTTP_Response_to_Periodic_Progress_Requests
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/spe/Management_API_-_Using_the_API#HTTP_Response_to_Periodic_Progress_Requests
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/MailStore_Server_Administration_API#Final_HTTP_Response
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/spe/Management_API_-_Using_the_API#Final_HTTP_Response
|
||||
|
||||
.OUTPUTS
|
||||
<PSCustomObject>
|
||||
JSON object that contains the final HTTP response.
|
||||
|
||||
<PSEngineEvent>
|
||||
A custom PowerShell Engine Event that is fired in case of a Status version change. with the following properties:
|
||||
|
||||
-SourceIdentifier <string>
|
||||
The initial Status token.
|
||||
|
||||
-MessageData <PSCustomObject>
|
||||
JSON object with the current Status returned by the server.
|
||||
#>
|
||||
|
||||
$sbPullStatus = [scriptblock]::Create({
|
||||
Param(
|
||||
[Parameter(Mandatory = $True, Position = 1)]
|
||||
[ValidateNotNull()]
|
||||
[PSCustomObject]$MSApiClient,
|
||||
[Parameter(Mandatory = $True, Position = 2)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[PSCustomObject]$StatusObject,
|
||||
[Parameter(Position = 3)]
|
||||
[ValidateNotNull()]
|
||||
[int]$StatusTimeout = 5000,
|
||||
[Parameter(Position = 4)]
|
||||
[bool]$UseStatusEvents = $True
|
||||
)
|
||||
[System.Uri]$StatusUri = New-Object System.Uri ("HTTPS://{0}:{1}/{2}{3}" -f $MSApiClient.Server, $MSApiClient.Port.ToString(), "api/", "get-status")
|
||||
|
||||
if ($UseStatusEvents) {
|
||||
|
||||
# The Status token returned by the initial API request identifies the server process. We use it to as event source so the parent PS session knows to which API call the Status relates.
|
||||
|
||||
Register-EngineEvent -SourceIdentifier ($StatusObject.token) -Forward
|
||||
}
|
||||
|
||||
# We need to set ServerCertificateValidationCallback and SecurityProtocol again as this is most likely a new PS session inside a job
|
||||
|
||||
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $MSApiClient.IgnoreInvalidSSLCerts }
|
||||
[System.Net.ServicePointManager]::SecurityProtocol = $MSApiClient.SecurityProtocol
|
||||
[Microsoft.PowerShell.Commands.WebRequestSession]$Session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
|
||||
$session.Credentials = $MSApiClient.Credentials
|
||||
|
||||
do {
|
||||
$StatusCode = ""
|
||||
|
||||
# We provide the status' token, last known version and a timeout value. The server will wait for that time at most for a new status, therefore it is not necessary for our client process to wait itself.
|
||||
|
||||
$Post = @{token = $StatusObject.token; lastKnownStatusVersion = $StatusObject.statusVersion; millisecondsTimeout = $StatusTimeout}
|
||||
try {
|
||||
[Microsoft.PowerShell.Commands.BasicHtmlWebResponseObject]$Response = Invoke-WebRequest -Uri $StatusUri.AbsoluteUri -Method Post -Body $Post -WebSession $Session -UseBasicParsing -MaximumRedirection 0 -ErrorAction SilentlyContinue
|
||||
}
|
||||
catch {
|
||||
$Response = $global:Error[0].Exception.Response
|
||||
if ($Response -eq $null) {
|
||||
throw $global:Error[0].Exception
|
||||
}
|
||||
}
|
||||
switch([System.Net.HttpStatusCode]$Response.StatusCode) {
|
||||
([System.Net.HttpStatusCode]::OK) {
|
||||
if ($Response.Content -eq $null) {
|
||||
$StatusObject = $null
|
||||
$StatusCode = ""
|
||||
} else {
|
||||
|
||||
# The PS commandlets do not respect the response's encoding, putting the BOM from the server's response into the content field >:-[
|
||||
# We need to remove the BOM so that ConvertFrom-Json succeeds.
|
||||
|
||||
$null = $Response.RawContentStream.Seek(0, [System.IO.SeekOrigin]::Begin) # Reset the stream
|
||||
$StatusObject = (New-Object System.IO.StreamReader $Response.RawContentStream, $Response.BaseResponse.CharacterSet).ReadToEnd() | ConvertFrom-Json
|
||||
$StatusCode = $StatusObject.StatusCode
|
||||
|
||||
# Fire a new PS Engine Event with the status token as SourceIdentifier.
|
||||
# The calling session knows the token and can thus identify to which API call the event relates, especially if there are multiple jobs in the queue.
|
||||
# MessageData contains a return object that has the current status as JSON object in its Data property.
|
||||
|
||||
if ($UseStatusEvents) {
|
||||
$null = New-Event -SourceIdentifier $StatusObject.token -MessageData $StatusObject
|
||||
}
|
||||
}
|
||||
}
|
||||
([System.Net.HttpStatusCode]::Unauthorized) {
|
||||
throw New-Object System.Net.WebException "Authentication failed. Check username and password."
|
||||
}
|
||||
([System.Net.HttpStatusCode]::NotFound) {
|
||||
throw New-Object System.Net.WebException "Session expired or wrong token."
|
||||
}
|
||||
default {
|
||||
throw New-Object System.Net.WebException ("({0}) {1}: {2}" -f [int]$Response.StatusCode, $Response.StatusDescription , $global:Error[0])
|
||||
}
|
||||
}
|
||||
} while ($StatusCode -eq "running")
|
||||
|
||||
return $StatusObject
|
||||
})
|
||||
|
||||
<#
|
||||
Sends an API call to the MailStore or SPE Management Server.
|
||||
|
||||
.DESCRIPTION
|
||||
Sends an API call to the MailStore or SPE Management Server.
|
||||
Optionally runs a call asynchronously through background jobs.
|
||||
Returns a JSON <PSCustomObject>.
|
||||
|
||||
.PARAMETER MSApiClient
|
||||
MS API client object created by "New-MSApiClient".
|
||||
|
||||
.PARAMETER ApiFunction
|
||||
A valid MS API function.
|
||||
|
||||
.PARAMETER ApiFunctionParameters
|
||||
The parameters for the API function.
|
||||
Provide as a hashtable, e.g. @{parameter1 = value1; parameter2 = value2; ...},
|
||||
or PSCustomObject with parameters mapped to properties.
|
||||
|
||||
.PARAMETER StatusTimeout
|
||||
Time in milliseconds until the the server stops waiting for a new status update to send.
|
||||
|
||||
.PARAMETER RunAsynchronously
|
||||
If provided, an API function that the server decides to run asynchronously is run as a background job.
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/MailStore_Server_Administration_API
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/spe/Management_API_-_Using_the_API
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/MailStore_Server_Administration_API_Commands
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/spe/Management_API_-_Function_Reference
|
||||
|
||||
.OUTPUTS
|
||||
A JSON <PSCustomObject> that encapsulates the HTTP response of the MS server.
|
||||
#>
|
||||
|
||||
function InternalMSApiCall {
|
||||
Param(
|
||||
[Parameter(Mandatory = $True, Position = 1)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[PSCustomObject]$MSApiClient,
|
||||
[Parameter(Mandatory = $True, Position = 2)]
|
||||
[ValidateScript({$MSApiClient.SupportedApiFunctions.name.Contains($_)})]
|
||||
[string]$ApiFunction,
|
||||
[Parameter(Position = 3)]
|
||||
[System.Object]$ApiFunctionParameters = @{},
|
||||
[Parameter(Position = 4)]
|
||||
[ValidateNotNull()]
|
||||
[int]$StatusTimeout = 5000,
|
||||
[Parameter(Position = 5)]
|
||||
[switch]$RunAsynchronously
|
||||
)
|
||||
|
||||
# If $ApiFunctionParameters is passed as null, use an empty hashtable
|
||||
|
||||
if (!$ApiFunctionParameters) {
|
||||
[Hashtable]$ApiFunctionParametersHT = @{}
|
||||
} else {
|
||||
|
||||
# If necessary, convert PSCustomObject to Hashtable for further processing
|
||||
|
||||
switch ($ApiFunctionParameters.GetType().Name) {
|
||||
|
||||
"Hashtable" {
|
||||
[Hashtable]$ApiFunctionParametersHT = $ApiFunctionParameters
|
||||
}
|
||||
|
||||
"PSCustomObject" {
|
||||
[Hashtable]$ApiFunctionParametersHT = @{}
|
||||
$ApiFunctionParameters.psobject.properties | Foreach { $ApiFunctionParametersHT[$_.Name] = $_.Value }
|
||||
}
|
||||
|
||||
default {
|
||||
throw New-Object System.ArgumentException ('API function parameters must be passed either as Hashtable or as PSCustomObject.')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Get the parameters for the API function supplied. The function itself has been checked in the Param block.
|
||||
|
||||
$MSApiFunctionWithParameters = $MSApiClient.SupportedApiFunctions | Where-Object {$_.name -eq $ApiFunction}
|
||||
|
||||
# Check whether the API function requires any parameters at all
|
||||
|
||||
if ($MSApiFunctionWithParameters.args.name) {
|
||||
[Array]$ParameterNames = $MSApiFunctionWithParameters.args.name
|
||||
} else {
|
||||
[Array]$ParameterNames = @()
|
||||
}
|
||||
|
||||
# Check whether parameters have been supplied that the API function does not support
|
||||
|
||||
[Array]$IllegalParams = Compare-Object -ReferenceObject $ParameterNames -DifferenceObject ([Array]$ApiFunctionParametersHT.Keys) -PassThru | Where-Object {$_.SideIndicator -EQ "=>"}
|
||||
|
||||
if ($IllegalParams.Count -gt 0) {
|
||||
throw New-Object System.ArgumentException ('Illegal Arguments: {0}' -f ($IllegalParams -join ", "))
|
||||
} else {
|
||||
|
||||
# Parameters which have their NULLABLE property set to false are mandatory
|
||||
|
||||
$MSApiFunctionMandatoryParameters = [Array]($MSApiFunctionWithParameters.args | Where-Object {$_.nullable -EQ $false})
|
||||
|
||||
# Check whether any parameters are mandatory at all
|
||||
|
||||
if ($MSApiFunctionMandatoryParameters.name) {
|
||||
[Array]$ParameterNames = $MSApiFunctionMandatoryParameters.name
|
||||
} else {
|
||||
[Array]$ParameterNames = @()
|
||||
}
|
||||
|
||||
# Check whether mandatory parameters are missing
|
||||
|
||||
[Array]$MissingParams = Compare-Object -ReferenceObject $ParameterNames -DifferenceObject ([Array]$ApiFunctionParametersHT.Keys) -PassThru | Where-Object {$_.SideIndicator -EQ "<="}
|
||||
if ($MissingParams.Count -gt 0) {
|
||||
throw New-Object System.ArgumentException ('Missing Arguments: {0}' -f ($MissingParams -join ", "))
|
||||
} else {
|
||||
|
||||
#Place Argument Type Check Here. We let the server sort out most of it ;-)
|
||||
|
||||
#Except for Booleans where the server supports only lower case values in compliance with JSON specs
|
||||
|
||||
[Array]$BoolParams = $MSApiFunctionWithParameters.args | Where-Object {$_.type.ToLowerInvariant() -eq "bool"}
|
||||
if ($BoolParams.Count -gt 0) {
|
||||
[Array]$SuppliedBoolParams = Compare-Object -ReferenceObject $BoolParams.Name -DifferenceObject ([Array]$ApiFunctionParametersHT.Keys) -IncludeEqual -ExcludeDifferent -PassThru
|
||||
foreach ($SuppliedBoolParam in $SuppliedBoolParams) {
|
||||
$ApiFunctionParametersHT[$SuppliedBoolParam] = $ApiFunctionParametersHT[$SuppliedBoolParam].ToString().ToLowerInvariant()
|
||||
}
|
||||
}
|
||||
|
||||
#JSON parameters need to be converted to string if they are supplied as any other type
|
||||
|
||||
[Array]$JSONParams = $MSApiFunctionWithParameters.args | Where-Object {$_.type.ToLowerInvariant() -eq "json"}
|
||||
if ($JSONParams.Count -gt 0) {
|
||||
[Array]$SuppliedJSONParams = Compare-Object -ReferenceObject $JSONParams.Name -DifferenceObject ([Array]$ApiFunctionParametersHT.Keys) -IncludeEqual -ExcludeDifferent -PassThru
|
||||
foreach ($SuppliedJSONParam in $SuppliedJSONParams) {
|
||||
if ($ApiFunctionParametersHT[$SuppliedJSONParam].GetType().Name.ToLowerInvariant() -ne "string") {
|
||||
$ApiFunctionParametersHT[$SuppliedJSONParam] = $ApiFunctionParametersHT[$SuppliedJSONParam] | ConvertTo-Json -Depth 10
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
# If a URI path is defined for the API function, use it, otherwise use the default path
|
||||
|
||||
$functionPath = if ($MSApiFunctionWithParameters | Get-Member "path") { $MSApiFunctionWithParameters.path } else { "api/invoke/" }
|
||||
|
||||
[System.Uri]$Uri = New-Object System.Uri ("HTTPS://{0}:{1}/{2}{3}" -f $MSApiClient.Server, $MSApiClient.Port.ToString(), $functionPath, $ApiFunction)
|
||||
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $MSApiClient.IgnoreInvalidSSLCerts }
|
||||
[System.Net.ServicePointManager]::SecurityProtocol = $MSApiClient.SecurityProtocol
|
||||
[Microsoft.PowerShell.Commands.WebRequestSession]$Session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
|
||||
$Session.Credentials = $MSApiClient.Credentials
|
||||
|
||||
# MS includes a BOM in most of its answers (especially the serialized JSON) which the PS commandlets cannot handle.
|
||||
# Therefore we have to use Invoke-WebRequest instead of Invoke-RestMethod and do the parsing ourselves.
|
||||
# Redirection and non terminating exceptions are suppressed.
|
||||
|
||||
try {
|
||||
[Microsoft.PowerShell.Commands.BasicHtmlWebResponseObject]$Response = Invoke-WebRequest -Uri $Uri.AbsoluteUri -Method Post -Body $ApiFunctionParametersHT -WebSession $Session -UseBasicParsing -MaximumRedirection 0 -ErrorAction SilentlyContinue
|
||||
}
|
||||
catch {
|
||||
$Response = $global:Error[0].Exception.Response
|
||||
if ($Response -eq $null) {
|
||||
throw $global:Error[0].Exception
|
||||
}
|
||||
}
|
||||
|
||||
# If the web request itself has been successful, we get a StatusCode.
|
||||
|
||||
switch([System.Net.HttpStatusCode]$Response.StatusCode) {
|
||||
([System.Net.HttpStatusCode]::OK) {
|
||||
|
||||
# Respect the response's encoding and thus get rid of the BOM if necessary (see above) so that ConvertFrom-Json succeeds.
|
||||
|
||||
$null = $Response.RawContentStream.Seek(0, [System.IO.SeekOrigin]::Begin) # Reset the stream
|
||||
$ResponseObject = (New-Object System.IO.StreamReader $Response.RawContentStream, $Response.BaseResponse.CharacterSet).ReadToEnd() | ConvertFrom-Json
|
||||
|
||||
if ($ResponseObject.StatusCode -eq "running") {
|
||||
|
||||
if ($RunAsynchronously.IsPresent) {
|
||||
# For a long running server process, create a background job encapsuled in $sbPullStatus that does the Status handling.
|
||||
|
||||
$null = Start-Job -ArgumentList $MSApiClient, $ResponseObject, $StatusTimeout, $True -ScriptBlock $sbPullStatus
|
||||
} else {
|
||||
$ResponseObject = Invoke-Command -ArgumentList $MSApiClient, $ResponseObject, $StatusTimeout, $False -ScriptBlock $sbPullStatus -NoNewScope
|
||||
}
|
||||
}
|
||||
|
||||
# Return the JSON response object.
|
||||
|
||||
return $ResponseObject
|
||||
}
|
||||
([System.Net.HttpStatusCode]::Unauthorized) {
|
||||
throw New-Object System.Net.WebException "Authentication failed. Check username and password."
|
||||
}
|
||||
default {
|
||||
throw New-Object System.Net.WebException ("({0}) {1}: {2}" -f [int]$Response.StatusCode, $Response.StatusDescription , $global:Error[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Creates a new MS API client object.
|
||||
|
||||
.DESCRIPTION
|
||||
Creates a new MS API client object.
|
||||
Returns an MS API client object.
|
||||
|
||||
.PARAMETER Username
|
||||
Username of a MailStore Server or SPE administrator.
|
||||
|
||||
.PARAMETER Password
|
||||
Password of that MailStore Server or SPE administrator.
|
||||
|
||||
.PARAMETER Credentials
|
||||
Credentials of a MailStore Server or SPE administrator.
|
||||
Alternative to providing <Username> and <Password>.
|
||||
|
||||
.PARAMETER MailStoreServer
|
||||
DNS name or IP address of the MailStore Server.
|
||||
|
||||
.PARAMETER ManagementServer
|
||||
DNS name or IP address of the SPE Management Server.
|
||||
|
||||
.PARAMETER Port
|
||||
Port that the MailStore or SPE Management Server listens to for API calls.
|
||||
|
||||
.PARAMETER IgnoreInvalidSSLCerts
|
||||
If included, errors due to invalid SSL certificates are ignored.
|
||||
If omitted, only certificates that can be validated can be used.
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/MailStore_Server_Administration_API_Commands
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/spe/Management_API_-_Function_Reference
|
||||
|
||||
.OUTPUTS
|
||||
<PSCustomObject>
|
||||
Object that encapsulates an MS API client instance with the following properties:
|
||||
|
||||
-Server <string>
|
||||
Same as MailStoreServer or ManagementServer parameter, see above.
|
||||
|
||||
-Port <string>
|
||||
Same as input parameter, see above.
|
||||
|
||||
-IgnoreInvalidSSLCerts <bool>
|
||||
Same as input parameter, see above.
|
||||
|
||||
-SupportedApiFunctions <PSCustomObject>
|
||||
A JSON object that contains all functions the MS Management Server supports.
|
||||
Data fields are:
|
||||
|
||||
-Name <string[]>
|
||||
Name of the API function.
|
||||
|
||||
-Args <string[]>
|
||||
List of arguments that the API function expects.
|
||||
|
||||
-Path [<string[]>]
|
||||
The URI path that a request should use for this function.
|
||||
If empty the default path "/invoke/<function>" is used.
|
||||
|
||||
Please refer to http://en.help.mailstore.com/MailStore_Server_Administration_API_Commands
|
||||
or http://en.help.mailstore.com/spe/Management_API_-_Function_Reference for futher details.
|
||||
#>
|
||||
|
||||
function New-MSApiClient {
|
||||
[CmdletBinding(DefaultParameterSetName="MSSCredentialsAsStringsParameterSet")]
|
||||
Param(
|
||||
[Parameter(ParameterSetName = "MSSCredentialsAsStringsParameterSet", Position = 1, Mandatory = $true)]
|
||||
[Parameter(ParameterSetName = "SPECredentialsAsStringsParameterSet", Position = 1, Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$Username = "admin",
|
||||
[Parameter(ParameterSetName = "MSSCredentialsAsPSCredentialObjectParameterSet", Position = 1, Mandatory = $true)]
|
||||
[Parameter(ParameterSetName = "SPECredentialsAsPSCredentialObjectParameterSet", Position = 1, Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[pscredential]$Credentials,
|
||||
[Parameter(ParameterSetName = "MSSCredentialsAsStringsParameterSet", Position = 2, Mandatory = $true)]
|
||||
[Parameter(ParameterSetName = "SPECredentialsAsStringsParameterSet", Position = 2, Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$Password,
|
||||
[Parameter(ParameterSetName = "MSSCredentialsAsStringsParameterSet", Position = 3, Mandatory = $true)]
|
||||
[Parameter(ParameterSetName = "MSSCredentialsAsPSCredentialObjectParameterSet", Position = 2, Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[Alias("Server")]
|
||||
[string]$MailStoreServer = "localhost",
|
||||
[Parameter(ParameterSetName = "SPECredentialsAsStringsParameterSet", Position = 3, Mandatory = $true)]
|
||||
[Parameter(ParameterSetName = "SPECredentialsAsPSCredentialObjectParameterSet", Position = 2, Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$ManagementServer = "localhost",
|
||||
[Parameter(ParameterSetName = "MSSCredentialsAsStringsParameterSet", Position = 4)]
|
||||
[Parameter(ParameterSetName = "SPECredentialsAsStringsParameterSet", Position = 4)]
|
||||
[Parameter(ParameterSetName = "MSSCredentialsAsPSCredentialObjectParameterSet", Position = 3)]
|
||||
[Parameter(ParameterSetName = "SPECredentialsAsPSCredentialObjectParameterSet", Position = 3)]
|
||||
[ValidateRange(1024,65535)]
|
||||
[int]$Port,
|
||||
[Net.SecurityProtocolType]$SecurityProtocol = $DefaultSecurityProtocol,
|
||||
[switch]$IgnoreInvalidSSLCerts
|
||||
)
|
||||
|
||||
# If username and password have been provided, store them in a PSCredential object.
|
||||
|
||||
if ($PSBoundParameters.ContainsKey("Password")) {
|
||||
$Credentials = New-Object System.Management.Automation.PSCredential($Username,(ConvertTo-SecureString $Password -AsPlainText -Force))
|
||||
}
|
||||
|
||||
# Get the server name based on the parameter set used.
|
||||
|
||||
switch -wildcard ($PSCmdlet.ParameterSetName) {
|
||||
"MSS*" {
|
||||
$Server = $MailStoreServer
|
||||
}
|
||||
"SPE*" {
|
||||
$Server = $ManagementServer
|
||||
}
|
||||
}
|
||||
|
||||
# If no port has been provided, make a best guess based on the server parameter name.
|
||||
|
||||
if (!($PSBoundParameters.ContainsKey("Port"))) {
|
||||
switch -wildcard ($PSCmdlet.ParameterSetName) {
|
||||
"MSS*" {
|
||||
$Port = 8463
|
||||
}
|
||||
"SPE*" {
|
||||
$Port = 8474
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# We provide a basic set of supported API functions to be able to login and initialize the MS API client object. The full set of functions will be retrieved later through "get-metadata" (see below).
|
||||
|
||||
$API_SUPPORTEDFUNCTIONS = '[{"name": "get-status","args": [{"name": "token","type": "string","nullable": false},{"name": "lastKnownStatusVersion","type": "number","nullable": false},{"name": "millisecondsTimeout","type": "number","nullable": false}],"path": "api/"},{"name": "get-metadata","args": [],"path": "api/"},{"name": "cancel-async","args": [{"name": "token","type": "string","nullable": false}],"path": "api/"}]'
|
||||
|
||||
[PSCustomObject]$MSApiClient = @{Credentials = $Credentials; Server = $Server; Port = $Port; SecurityProtocol = $SecurityProtocol; IgnoreInvalidSSLCerts = $IgnoreInvalidSSLCerts.IsPresent; SupportedApiFunctions = $API_SUPPORTEDFUNCTIONS | ConvertFrom-Json}
|
||||
|
||||
# Retrieve a list of all API functions that this installation of MS supports and convert it into a JSON object. Use a parsing depth of 10 levels just be sure and the default of 2 (!) is a bit ... insufficient.
|
||||
|
||||
$SupportedApiFunctions = InternalMSApiCall -MSApiClient $MSApiClient -ApiFunction "get-metadata" | ConvertTo-Json -Depth 10
|
||||
|
||||
# Join our basic set with the retrieved set because "get-metadata" omits some base API functions.
|
||||
|
||||
$MSApiClient.SupportedApiFunctions = ($API_SUPPORTEDFUNCTIONS.Substring(0,$API_SUPPORTEDFUNCTIONS.Length-1) + "," + $SupportedApiFunctions.Substring(1) ) | ConvertFrom-Json
|
||||
|
||||
return $MSApiClient
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Sends an API call to the MailStore or SPE Management Server.
|
||||
|
||||
.DESCRIPTION
|
||||
Sends an API call to the MailStore or SPE Management Server.
|
||||
If the server decides to run the called function asynchronously, this commandlet waits for the final result.
|
||||
Use <Start-MSApiCall> for asynchronous function handling.
|
||||
Returns a JSON <PSCustomObject>.
|
||||
|
||||
.PARAMETER MSApiClient
|
||||
MS API client object created by "New-MSApiClient".
|
||||
|
||||
.PARAMETER ApiFunction
|
||||
A valid MS API function.
|
||||
|
||||
.PARAMETER ApiFunctionParameters
|
||||
The parameters for the API function.
|
||||
Provide as a hashtable, e.g. @{parameter1 = value1; parameter2 = value2; ...},
|
||||
or PSCustomObject with parameters mapped to properties.
|
||||
|
||||
.PARAMETER StatusTimeout
|
||||
Time in milliseconds until the the server stops waiting for a new status update to send.
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/MailStore_Server_Administration_API
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/spe/Management_API_-_Using_the_API
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/MailStore_Server_Administration_API_Commands
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/spe/Management_API_-_Function_Reference
|
||||
|
||||
.OUTPUTS
|
||||
A JSON <PSCustomObject> that encapsulates the HTTP response of the MS server.
|
||||
#>
|
||||
|
||||
function Invoke-MSApiCall {
|
||||
Param(
|
||||
[Parameter(Mandatory = $True, Position = 1)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[PSCustomObject]$MSApiClient,
|
||||
[Parameter(Mandatory = $True, Position = 2)]
|
||||
[ValidateScript({$MSApiClient.SupportedApiFunctions.name.Contains($_)})]
|
||||
[string]$ApiFunction,
|
||||
[Parameter(Position = 3)]
|
||||
[System.Object]$ApiFunctionParameters = @{},
|
||||
[Parameter(Position = 4)]
|
||||
[ValidateNotNull()]
|
||||
[int]$StatusTimeout = 5000
|
||||
)
|
||||
|
||||
return InternalMSApiCall -MSApiClient $MSApiClient -ApiFunction $ApiFunction -ApiFunctionParameters $ApiFunctionParameters -StatusTimeout $StatusTimeout
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Sends an API call to the MailStore or SPE Management Server.
|
||||
|
||||
.DESCRIPTION
|
||||
Sends an API call to the MailStore or SPE Management Server.
|
||||
If the server decides to run the called function asynchronously, this commandlet runs the call as a background job.
|
||||
Use <Invoke-MSApiCall> for synchronous function handling.
|
||||
Returns an object that contains information about the result (see Output).
|
||||
|
||||
.PARAMETER MSApiClient
|
||||
MS API client object created by "New-MSApiClient".
|
||||
|
||||
.PARAMETER ApiFunction
|
||||
A valid MS API function.
|
||||
|
||||
.PARAMETER ApiFunctionParameters
|
||||
The parameters for the API function.
|
||||
Provide as a hashtable, e.g. @{parameter1 = value1; parameter2 = value2; ...},
|
||||
or PSCustomObject with parameters mapped to properties.
|
||||
|
||||
.PARAMETER StatusTimeout
|
||||
Time in milliseconds until the the server stops waiting for a new status update to send.
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/MailStore_Server_Administration_API
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/spe/Management_API_-_Using_the_API
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/MailStore_Server_Administration_API_Commands
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/spe/Management_API_-_Function_Reference
|
||||
|
||||
.OUTPUTS
|
||||
A JSON <PSCustomObject> that encapsulates the HTTP response of the MS server.
|
||||
If that object's <statusCode> property is "running", a Windows PowerShell background job handles the Status of the server process.
|
||||
The job fires PSEngineEvents with the status token as SourceIdentifier and the current status in MessageData as a JSON <PSCustomObject>.
|
||||
Once the job is finished, it returns the final Status as a JSON <PSCustomObject>.
|
||||
#>
|
||||
|
||||
function Start-MSApiCall {
|
||||
Param(
|
||||
[Parameter(Mandatory = $True, Position = 1)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[PSCustomObject]$MSApiClient,
|
||||
[Parameter(Mandatory = $True, Position = 2)]
|
||||
[ValidateScript({$MSApiClient.SupportedApiFunctions.name.Contains($_)})]
|
||||
[string]$ApiFunction,
|
||||
[Parameter(Position = 3)]
|
||||
[System.Object]$ApiFunctionParameters = @{},
|
||||
[Parameter(Position = 4)]
|
||||
[ValidateNotNull()]
|
||||
[int]$StatusTimeout = 5000
|
||||
)
|
||||
|
||||
return InternalMSApiCall -MSApiClient $MSApiClient -ApiFunction $ApiFunction -ApiFunctionParameters $ApiFunctionParameters -StatusTimeout $StatusTimeout -RunAsynchronously
|
||||
|
||||
}
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Cancels a long running MS server process.
|
||||
|
||||
.DESCRIPTION
|
||||
Cancels a long running MS server process.
|
||||
Returns an object that contains the Status.
|
||||
|
||||
.PARAMETER MSApiClient
|
||||
MS API client object created by "New-MSApiClient".
|
||||
|
||||
.PARAMETER AsyncReturnObject
|
||||
JSON <PSCustomObject> that encapsulates the initial Status returned by the server in answer to the original API request.
|
||||
|
||||
.PARAMETER Token
|
||||
The Status token returned by the initial API request.
|
||||
Alternative to AsyncReturnObject.
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/MailStore_Server_Administration_API#Long_Running_Processes
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/spe/Management_API_-_Using_the_API#Long_Running_Processes
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/MailStore_Server_Administration_API#Initial_HTTP_Response
|
||||
|
||||
.LINK
|
||||
http://en.help.mailstore.com/spe/Management_API_-_Using_the_API#Initial_HTTP_Response
|
||||
|
||||
.OUTPUTS
|
||||
JSON <PSCustomObject> that encapsulates the Status returned by the server.
|
||||
|
||||
.NOTES
|
||||
This function sends an API call to the MailStore or SPE Management Server to request a specific long running process to be cancelled.
|
||||
The server decides if and when the cancellation occurs; it does not necessarily cancel the process immediately.
|
||||
The background job that does the Status handling continues to run until it receives the server's cancellation signal.
|
||||
#>
|
||||
|
||||
function Stop-MSApiCall {
|
||||
Param(
|
||||
[Parameter(Mandatory = $True, Position = 1)]
|
||||
[ValidateNotNullorEmpty()]
|
||||
[PSCustomObject]$MSApiClient,
|
||||
[Parameter(ParameterSetName = "JobByObject", Mandatory = $True, Position = 2)]
|
||||
[ValidateNotNullorEmpty()]
|
||||
[PSCustomObject]$AsyncReturnObject,
|
||||
[Parameter(ParameterSetName = "JobByToken", Mandatory = $True, Position = 2)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$Token
|
||||
)
|
||||
if ($PSCmdlet.ParameterSetName -eq "JobByObject") {
|
||||
$Token = $AsyncReturnObject.token
|
||||
}
|
||||
if ($Token -ne "") {
|
||||
return Invoke-MSApiCall $MSApiClient "cancel-async" @{token = $Token}
|
||||
}
|
||||
}
|
||||
|
||||
# Aliases to support MailStore SPE 8.5 scripts
|
||||
# Start-MSSPEApiCall is mapped to Invoke-MSApiCall to assure the correct behavior
|
||||
|
||||
Set-Alias -Name New-MSSPEApiClient -Value New-MSApiClient
|
||||
Set-Alias -Name Invoke-MSSPEApiCall -Value Invoke-MSApiCall
|
||||
Set-Alias -Name Start-MSSPEApiCall -Value Invoke-MSApiCall
|
||||
Set-Alias -Name Stop-MSSPEApiCall -Value Stop-MSApiCall
|
||||
|
||||
# Aliases to support MailStore Server 7/8 scripts
|
||||
# Start-MSSApiCall is mapped to Invoke-MSApiCall to assure the correct behavior
|
||||
|
||||
Set-Alias -Name New-MSSApiClient -Value New-MSApiClient
|
||||
Set-Alias -Name Invoke-MSSApiCall -Value Invoke-MSApiCall
|
||||
Set-Alias -Name Start-MSSApiCall -Value Invoke-MSApiCall
|
||||
|
||||
# Public members that should be visible through Import-Module
|
||||
|
||||
Export-ModuleMember -Function New-MSApiClient, Invoke-MSApiCall, Start-MSApiCall, Stop-MSApiCall -Alias New-MSSPEApiClient, Invoke-MSSPEApiCall, Start-MSSPEApiCall, Stop-MSSPEApiCall, New-MSSApiClient, Invoke-MSSApiCall, Start-MSSApiCall
|
||||
292
current/DD-Internal/Modules/MoveOrCopy-Item-withLogging.psm1
Normal file
292
current/DD-Internal/Modules/MoveOrCopy-Item-withLogging.psm1
Normal file
@@ -0,0 +1,292 @@
|
||||
Function MoveOrCopy-Item-withLogging {
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Function will copy or move File(s).
|
||||
|
||||
.DESCRIPTION
|
||||
If File already exists in target Path new File will get a Version ~2.
|
||||
|
||||
.REQUIREMENT General
|
||||
PowerShell V2
|
||||
|
||||
.REQUIREMENT Assembly
|
||||
<NONE>
|
||||
|
||||
.REQUIREMENT Variables
|
||||
Datei, Datei1, DateiName, DateiEndung, DateiTest, DateiVersion,ZielPath, MoveorCopy, SourcePath
|
||||
|
||||
.REQUIREMENT Variables preSet
|
||||
VersionSeperator
|
||||
|
||||
.REQUIREMENT Functions
|
||||
Write-Logfile
|
||||
|
||||
.VERSION
|
||||
1.2.1.2 / 23.02.2024
|
||||
|
||||
.PARAMETER SourceFile
|
||||
Give the full Path and Filename to one File.
|
||||
|
||||
.PARAMETER DestinationPath
|
||||
Give the Target Path you want to move or copy the specified File.
|
||||
|
||||
.PARAMETER Action
|
||||
Determine which Action you want to perform <Copy|Move>. Default Value is "Copy".
|
||||
|
||||
.PARAMETER NewFileName
|
||||
Give a String, which get the new Name of the File you are moving.
|
||||
|
||||
.PARAMETER NewFileName_prefix
|
||||
Give a String, which get the new prefix Name of the File you are moving.
|
||||
|
||||
.PARAMETER NewFileName_suffix
|
||||
Give a String, which get the new suffix Name of the File you are moving.
|
||||
|
||||
.EXAMPLE
|
||||
MoveOrCopy-Item-withLogging -SourceFile "E:\Quellpfad\Test.txt" -DestinationPath "E:\Zielpfad" -move_or_copy move
|
||||
|
||||
.EXAMPLE
|
||||
MoveOrCopy-Item-withLogging -SourceFile "E:\Quellpfad\Test.txt" -DestinationPath "E:\Zielpfad" -move_or_copy copy
|
||||
#>
|
||||
|
||||
Param (
|
||||
|
||||
[Parameter(Position=0,Mandatory=$True,HelpMessage='Give the full Path and Filename to one File.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$SourceFile,
|
||||
|
||||
[Parameter(Mandatory=$True,HelpMessage='Give the Target Path you want to move or copy the specified File.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$DestinationPath,
|
||||
|
||||
[Parameter(Mandatory=$True,HelpMessage='Determine which Action you want to perform <Copy|Move>. Default Value is "Copy".')]
|
||||
[ValidateSet("copy","move")]
|
||||
[String]$Action="copy",
|
||||
|
||||
[Parameter(Mandatory=$False,HelpMessage='Give a String, which get the new Name of the File you are moving.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$NewFileName,
|
||||
|
||||
[Parameter(Mandatory=$False,HelpMessage='Give a String, which get the new prefix Name of the File you are moving.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$NewFileName_prefix,
|
||||
|
||||
[Parameter(Mandatory=$False,HelpMessage='Give a String, which get the new suffix Name of the File you are moving.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$NewFileName_suffix
|
||||
|
||||
) #end param
|
||||
|
||||
#Clear Error Variable
|
||||
$error.clear()
|
||||
|
||||
#Checking if "Write-LogFile" Module was loaded
|
||||
IF (Get-Module -Name "Write-LogFile") {
|
||||
|
||||
IF ((Test-Path $SourceFile -PathType Leaf) -eq $True) {
|
||||
|
||||
Write-Logfile -LogLine ""
|
||||
$SourcePath = ([System.IO.Path]::GetDirectoryName($SourceFile).ToString())
|
||||
$FileName = ([System.IO.Path]::GetFileName($SourceFile).ToString())
|
||||
$FileName_noExt = ([System.IO.Path]::GetFileNameWithoutExtension($SourceFile).ToString())
|
||||
$FileExtension = ([System.IO.Path]::GetExtension($SourceFile).ToString())
|
||||
|
||||
IF (!$VersionSeperator) {
|
||||
|
||||
Write-Logfile -LogLine "ERROR: Wrong Function call."
|
||||
Write-Logfile -LogLine "INFO: Variable VersionSeperator is not valid."
|
||||
Write-Logfile -LogLine "Application was unplannd terminated."
|
||||
EXIT
|
||||
|
||||
} #end if
|
||||
|
||||
IF ($newfilename) {
|
||||
|
||||
Write-Logfile -LogLine "New Filename ($newfilename) will replace the old one."
|
||||
Set-Variable -Name Filename -Value ($newfilename+$FileExtension)
|
||||
Set-Variable -Name Filename_noExt -Value ($newfilename)
|
||||
|
||||
} #end if
|
||||
|
||||
IF ($newfilename_prefix) {
|
||||
|
||||
Write-Logfile -LogLine "New prefix ($newfilename_prefix) has been set for file."
|
||||
Set-Variable -Name Filename -Value (($newfilename_prefix+$FileSeperator+$Filename) -replace "$FileSeperator$FileSeperator","$FileSeperator")
|
||||
Set-Variable -Name Filename_noExt -Value (($newfilename_prefix+$FileSeperator+$Filename_noExt) -replace "$FileSeperator$FileSeperator","$FileSeperator")
|
||||
|
||||
} #end if
|
||||
|
||||
IF ($newfilename_suffix) {
|
||||
|
||||
Write-Logfile -LogLine "New suffix ($newfilename_suffix) has been set for file."
|
||||
Set-Variable -Name FileName -Value (($Filename -split "$VersionSeperator")[0])
|
||||
Set-Variable -Name FileName_noExt -Value (($Filename_noExt -split "$VersionSeperator")[0])
|
||||
Set-Variable -Name Filename -Value (($Filename_noExt+$FileSeperator+$newfilename_suffix+$FileExtension) -replace "$FileSeperator$FileSeperator","$FileSeperator")
|
||||
Set-Variable -Name Filename_noExt -Value (($Filename_noExt+$FileSeperator+$newfilename_suffix) -replace "$FileSeperator$FileSeperator","$FileSeperator")
|
||||
|
||||
} #end if
|
||||
|
||||
# Does file already exist in the target directory?
|
||||
$FileTest = Test-Path "$DestinationPath\$FileName" -PathType Leaf
|
||||
|
||||
IF ($Filetest -eq $True) {
|
||||
|
||||
Write-Logfile -LogLine "The File ($Filename) already exists in the target directory, starting Version Check."
|
||||
|
||||
[String]$FileNameSplit = ($Filename_noExt -split $VersionSeperator)
|
||||
[Int]$FileVersion = 0
|
||||
|
||||
IF ($FileNameSplit[1] -is [Int]) {
|
||||
[Int]$FileVersion = $FileNameSplit[1]
|
||||
} #end if
|
||||
|
||||
# Has the new file already a Version tag?
|
||||
IF ($FileVersion -eq 0) {
|
||||
|
||||
Write-Host "DEBUG Info: Sourcefile includes no VersionSeperator."
|
||||
# To skip Version ~1.
|
||||
$FileVersion++
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host "DEBUG Info: Sourcefile includes VersionSeperator."
|
||||
$FileName_noExt = $FilenameSplit[0]
|
||||
|
||||
} #end else
|
||||
|
||||
DO {
|
||||
|
||||
Write-Host "DEBUG Info: Count file version:" $FileVersion; $FileVersion++
|
||||
}
|
||||
|
||||
WHILE (($Filetest = Test-Path -Path "$DestinationPath\$FileName_noExt$VersionSeperator$FileVersion$FileExtension") -eq 'True')
|
||||
|
||||
# code block for the copy or move process
|
||||
Try {
|
||||
|
||||
Set-Variable -Name FileHash_befor -Value (Get-FileHash -Path "$SourceFile" -Algorithm SHA512 | Select-Object Hash | Foreach-Object {$_ -replace "@{Hash=", ""} | Foreach-Object {$_ -replace "}", ""})
|
||||
Set-Variable -Name FileTemp -Value (Copy-Item -Path "$SourceFile" -Destination "$DestinationPath\$Timestamp3`_$FileName" -PassThru -Force)
|
||||
Write-Logfile -LogLine "The $Action command has been completed."
|
||||
Set-Variable -Name FileFinal -Value (Rename-Item -Path "$FileTemp" -NewName "$FileName_noExt$VersionSeperator$FileVersion$FileExtension" -PassThru -Force )
|
||||
Write-Logfile -LogLine "File was renamed to: $FileName_noExt$VersionSeperator$FileVersion$FileExtension, and is now transferd to: $DestinationPath."
|
||||
Set-Variable -Name FileHash_after -Value (Get-FileHash -Path "$FileFinal" -Algorithm SHA512 | Select-Object Hash | Foreach-Object {$_ -replace "@{Hash=", ""} | Foreach-Object {$_ -replace "}", ""})
|
||||
Write-Host "DEBUG Info: Hash Value before: $FileHash_befor"
|
||||
Write-Host "DEBUG Info: Hash Value after: $FileHash_after"
|
||||
|
||||
IF ($Action -eq 'move') {
|
||||
|
||||
Write-Host "DEBUG Info: Moving action was choosen, will delete source file."
|
||||
|
||||
IF ($FileHash_befor -eq $FileHash_after) {
|
||||
|
||||
Try {
|
||||
|
||||
Remove-Item -Path "$SourceFile" -Force
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Error removing the source file."
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine "HASH Value does mismatch!"
|
||||
Write-Logfile -LogLine "Aborting delete operation!"
|
||||
|
||||
} #end else
|
||||
|
||||
} #end if
|
||||
|
||||
Return $FileFinal.Fullname
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Error at $Action command, processing file: $SourceFile"
|
||||
Write-Logfile -LogLine "Please check your privileges"
|
||||
exit
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Set-Variable -Name FileHash_befor -Value (Get-FileHash -Path "$SourceFile" -Algorithm SHA512 | Select-Object Hash | Foreach-Object {$_ -replace "@{Hash=", ""} | Foreach-Object {$_ -replace "}", ""})
|
||||
Set-Variable -Name FileFinal -Value (Copy-Item -Path "$SourceFile" -Destination "$DestinationPath\$FileName" -PassThru -Force)
|
||||
Set-Variable -Name FileHash_after -Value (Get-FileHash -Path "$FileFinal" -Algorithm SHA512 | Select-Object Hash | Foreach-Object {$_ -replace "@{Hash=", ""} | Foreach-Object {$_ -replace "}", ""})
|
||||
Write-Logfile -LogLine "The $Action command has been completed for file: $SourceFile"
|
||||
Write-Logfile -LogLine "And is now transferd to: $DestinationPath"
|
||||
Write-Host "DEBUG Info: Hash Value before: $FileHash_befor"
|
||||
Write-Host "DEBUG Info: Hash Value after: $FileHash_after"
|
||||
|
||||
IF ($Action -eq 'move') {
|
||||
|
||||
Write-Host "DEBUG Info: Moving action was choosen, will delete source file."
|
||||
|
||||
IF ($FileHash_befor -eq $FileHash_after) {
|
||||
|
||||
Try {
|
||||
|
||||
Remove-Item -Path "$SourceFile" -Force
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Error removing the source file."
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine "HASH Value does mismatch!"
|
||||
Write-Logfile -LogLine "Aborting delete operation!"
|
||||
|
||||
} #end else
|
||||
|
||||
} #end if
|
||||
|
||||
ELSEIF ($Action -eq 'copy') {
|
||||
|
||||
Write-Host "DEBUG Info: Coping action was choosen, will not delete original file."
|
||||
|
||||
} #end elseif
|
||||
|
||||
Return $FileFinal.Fullname
|
||||
|
||||
} #end else
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-LogFile -LogLine "Cannot find Source File!"
|
||||
Return $False
|
||||
|
||||
} #end else
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info: Write-LogFile - Module does not exist!"
|
||||
Write-Host "DEBUG Info: Please load the Module and try again, running this Function/Module!"
|
||||
Write-Host "DEBUG Info: Exiting, because of this Issue."
|
||||
EXIT
|
||||
|
||||
} #end else
|
||||
|
||||
} #end function
|
||||
BIN
current/DD-Internal/Modules/New-ComplexPassword-withLogging.psm1
Normal file
BIN
current/DD-Internal/Modules/New-ComplexPassword-withLogging.psm1
Normal file
Binary file not shown.
BIN
current/DD-Internal/Modules/Read-ConfigFile.psm1
Normal file
BIN
current/DD-Internal/Modules/Read-ConfigFile.psm1
Normal file
Binary file not shown.
BIN
current/DD-Internal/Modules/Read-ConfigFile2.psm1
Normal file
BIN
current/DD-Internal/Modules/Read-ConfigFile2.psm1
Normal file
Binary file not shown.
114
current/DD-Internal/Modules/Remove-Item-withLogging.psm1
Normal file
114
current/DD-Internal/Modules/Remove-Item-withLogging.psm1
Normal file
@@ -0,0 +1,114 @@
|
||||
Function Remove-Item-withLogging {
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Function will delete Items selected by Path, Name and Age.
|
||||
|
||||
.DESCRIPTION
|
||||
Function will delete Items selected by Path, Name and Age, with logging this.
|
||||
For a successful performed deletion, Function will Return $True, for unccessful $False.
|
||||
|
||||
.REQUIREMENT General
|
||||
PowerShell V2
|
||||
|
||||
.REQUIREMENT Variables
|
||||
Path, FileKeepTime, FileBaseName, Item, Items
|
||||
|
||||
.REQUIREMENT Assembly
|
||||
<NONE>
|
||||
|
||||
.REQUIREMENT Functions
|
||||
Write-LogFile
|
||||
|
||||
.VERSION
|
||||
Number: 1.2.0.0 / Date: 25.06.2025
|
||||
|
||||
.PARAMETER Path
|
||||
Give the Full Path, where the Item(s) located, which should be deleted.
|
||||
|
||||
.PARAMETER FileKeepTime
|
||||
Give the time in Days, which Items should be deleted, which are older than...
|
||||
|
||||
.PARAMETER FileBaseName
|
||||
Give the <Filename> which will be selected, the Item(s) to delete. Given <Filename> will be set with Wildcards: *<Filename>*.
|
||||
|
||||
.PARAMETER FileExtension
|
||||
Give the FileExtension which Files will be selected for deletion (Default: log).
|
||||
|
||||
.EXAMPLE
|
||||
Remove-Item-withLogging -Path "E:\LogFiles" -FileKeepTime 5 -FileBaseName Filename
|
||||
#>
|
||||
|
||||
[cmdletbinding()]
|
||||
|
||||
Param (
|
||||
|
||||
[Parameter(Mandatory=$True,HelpMessage='Give the Full Path, where the Item(s) located, which should be deleted.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$Path=$NULL,
|
||||
|
||||
[Parameter(Mandatory=$True,HelpMessage='Give the time in Days, which Item(s) should be deleted, which are older than...')]
|
||||
[ValidateRange(0,1000)]
|
||||
[Int]$FileKeepTime=$NULL,
|
||||
|
||||
[Parameter(Mandatory=$True,HelpMessage='Give the Filename which will be selected, the Item(s) to delete. Given <Filename> will be set with Wildcards: *<Filename>*.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$FileBaseName=$NULL,
|
||||
|
||||
[Parameter(Mandatory=$False,HelpMessage='Give the FileExtension which Files will be selected for deletion (Default: log).')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$FileExtension="log"
|
||||
|
||||
) #end param
|
||||
|
||||
#Checking if "Write-LogFile" Module was loaded
|
||||
IF (Get-Module -Name "Write-LogFile") {
|
||||
|
||||
IF ($FileKeepTime -gt 0) {
|
||||
|
||||
Write-Logfile -LogLine "Files should be removed which are older than $FileKeepTime Day(s)."
|
||||
[Array]$Items = (Get-ChildItem -Path "$Path\*" -Filter *.$FileExtension | where {$_.Name -like "*$FileBaseName*" -and $_.lastwritetime -lt $((Get-Date).AddDays(-$FileKeepTime)) -and -not $_.psiscontainer})
|
||||
|
||||
IF ($Items.count -le 0) {
|
||||
|
||||
Write-Logfile -LogLine "Found no old Files."
|
||||
Return $False
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Logfile -LogLine "Deleting old Files (Found: $($Items.count)) :"
|
||||
|
||||
Try {
|
||||
|
||||
$Items | Remove-Item -Force -Verbose -ErrorAction Stop
|
||||
Write-Logfile -LogLine "Files were removed!"
|
||||
Return $True
|
||||
|
||||
} Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot remove Files!"
|
||||
Write-Logfile -LogLine "Please check your privileges!"
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end else
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Logfile -LogLine "You disabled File deletion, they all will be kept."
|
||||
Return $False
|
||||
|
||||
} #end else
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info: Write-LogFile - Module does not exist!"
|
||||
Write-Host "DEBUG Info: Please load the Module and try again, running this Function/Module!"
|
||||
Write-Host "DEBUG Info: Exiting, because of this Issue."
|
||||
EXIT
|
||||
|
||||
} #end else
|
||||
|
||||
} #end function
|
||||
Binary file not shown.
@@ -0,0 +1,367 @@
|
||||
Function Restart-windreamClient-withLogging {
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Restart windream Client Components via COM Interface
|
||||
|
||||
.DESCRIPTION
|
||||
If Connection to the windream Server gets interrupted (network loss, eg.), it is neccessery to restart the Client Components.
|
||||
Otherwise you can Stop or Start Client Components with this Function.
|
||||
For a successful performed Action, Function will Return $True, for unccessful $False.
|
||||
|
||||
.REQUIREMENT General
|
||||
PowerShell V3, windream Client Connectivity (>=V3.6)
|
||||
|
||||
.REQUIREMENT Assembly
|
||||
<NONE>
|
||||
|
||||
.REQUIREMENT Variables
|
||||
windreamControlCenter, windreamIndexService, ServiceTest, Action
|
||||
|
||||
.REQUIREMENT Variables preSet
|
||||
<NONE>
|
||||
|
||||
.REQUIREMENT Functions
|
||||
Write-LogFile
|
||||
|
||||
.VERSION
|
||||
1.2.0.0 / 28.09.2018
|
||||
|
||||
.PARAMETER Action
|
||||
Determine which Action you want to perform <Stop|Restart|Start>. Default Value is <Restart>.
|
||||
|
||||
.PARAMETER ServiceTest
|
||||
Set on $True, if Function should check for a running windream vfs Client Service. If it is and Service is stopped, Function will try to start Service. Default Value is $True.
|
||||
|
||||
.PARAMETER StartTimeout
|
||||
|
||||
.EXAMPLE
|
||||
Restart-windreamClient
|
||||
|
||||
.EXAMPLE
|
||||
Restart-windreamClient -Action Start
|
||||
|
||||
.EXAMPLE
|
||||
Restart-windreamClient -Action Start -ServiceTest $False
|
||||
#>
|
||||
|
||||
Param (
|
||||
|
||||
[Parameter(Position=0,Mandatory=$False,HelpMessage='Determine which Action you want to perform <Stop|Restart|Start>. Default Value is "Restart".')]
|
||||
[ValidateSet("Stop","Restart","Start")]
|
||||
[String]$Action="Restart",
|
||||
|
||||
[Parameter(Position=1,Mandatory=$False,HelpMessage='Set on $True, if Function should check for a running windream vfs Client Service. If it is and Service is stopped, Function will try to start Service. Default Value is $True.')]
|
||||
[ValidateSet($True,$False)]
|
||||
[Switch]$ServiceTest=$True,
|
||||
|
||||
[Parameter(Position=2,Mandatory=$False,HelpMessage='Give the Timeout limit in Seconds for the windream Start/Restart procedure, ValidateRange(1 - 300). Default Value is "10".')]
|
||||
[ValidateRange(1,300)]
|
||||
[INT]$StartTimeout=10
|
||||
|
||||
) #end param
|
||||
|
||||
#Clear Error Variable
|
||||
$error.clear()
|
||||
|
||||
#Checking if "Write-LogFile" Module was loaded
|
||||
IF (Get-Module -Name "Write-LogFile") {
|
||||
|
||||
Write-Host "DEBUG Info: Write-LogFile - Module exists."
|
||||
|
||||
#If Servie Test was enabled (by default true) check if windream vfs Service is running
|
||||
IF ($ServiceTest -eq $True) {
|
||||
|
||||
Write-LogFile -LogLine " "
|
||||
Write-LogFile -LogLine "Service Test is enabled!"
|
||||
|
||||
#Check if windream vfs Service is installed
|
||||
Try {
|
||||
|
||||
[Object]$ServiceTest = $NULL
|
||||
[Object]$ServiceTest = Get-Service -Name vfssvc -ErrorAction Stop
|
||||
Write-LogFile -LogLine "Found Service: vfssvc"
|
||||
Write-LogFile -LogLine "Service is currently: $((Get-Service -Name vfssvc).Status)"
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-LogFile -LogLine "WARNING: windream Client seems not to be installed completely."
|
||||
Write-LogFile -LogLine "Missing Service: vfssvc"
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
#If Servie Test is disabled
|
||||
ELSE {
|
||||
|
||||
Write-LogFile -LogLine " "
|
||||
Write-LogFile -LogLine "Service Test is disabled!"
|
||||
|
||||
} #end else
|
||||
|
||||
#Try to create windream Objects
|
||||
Try {
|
||||
|
||||
[Object]$windreamControlCenter = New-Object -ComObject "Wmcc.ControlCenter" -ErrorAction Stop
|
||||
[Object]$windreamIndexService = New-Object -ComObject "WMIndexServer.WMIdxSvControl" -ErrorAction Stop
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot create Object from windream Class Wmcc.ControlCenter or WMIndexServer.WMIdxSvControl!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
#If Function was called to Stop windream Client Components
|
||||
IF ($Action -like "Stop") {
|
||||
|
||||
Write-LogFile -LogLine "Stop windream Client Components."
|
||||
|
||||
#Try to stop windream Client Components
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Stopping windream Client Components!"
|
||||
$windreamControlCenter.StartVFSService(0) | Out-Null
|
||||
$windreamIndexService.Shutdown() | Out-Null
|
||||
$windreamControlCenter.ExitCC(0) | Out-Null
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot stop windream Client Components!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
Return $True
|
||||
|
||||
} #end if
|
||||
|
||||
#If Function was called to Restart windream Client Components and Service Test was enabled
|
||||
ELSEIF (($Action -like "Restart") -and ($ServiceTest -is [Object])) {
|
||||
|
||||
#Checking if windream vfs Service is running
|
||||
IF ((Get-Service -Name vfssvc).Status -ne 'running') {
|
||||
|
||||
Write-LogFile -LogLine "Warning: windream vfs Service is not running!"
|
||||
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Trying to Start/Restart the windream vfs Service!"
|
||||
Stop-Service -Name vfssvc -ErrorAction SilentlyContinue
|
||||
Start-Service -Name vfssvc -ErrorAction Stop
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot Start/Restart windream vfs Service!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine " "
|
||||
Write-LogFile -LogLine "windream vfs Service is running!"
|
||||
|
||||
} #end else
|
||||
|
||||
Write-LogFile -LogLine "Restart windream Client Components."
|
||||
|
||||
#Try to stop windream Client Components
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Stopping windream Client Components!"
|
||||
$windreamControlCenter.StartVFSService(0) | Out-Null
|
||||
$windreamIndexService.Shutdown() | Out-Null
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot stop windream Client Components!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
#Try to start windream Client Components
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Starting windream Client Components!"
|
||||
$windreamControlCenter.StartVFSService(1) | Wait-Process -Timeout $StartTimeout | Out-Null
|
||||
$windreamIndexService.Start() | Out-Null
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot start windream Client Components!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
Return $True
|
||||
|
||||
} #end elseif
|
||||
|
||||
#If Function was called to Restart windream Client Components and Service Test was disabled
|
||||
ELSEIF (($Action -like "Restart") -and ($ServiceTest -is [Switch])) {
|
||||
|
||||
Write-LogFile -LogLine "Restart windream Client Components."
|
||||
|
||||
#Try to stop windream Client Components
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Stopping windream Client Components!"
|
||||
$windreamControlCenter.StartVFSService(0) | Out-Null
|
||||
$windreamIndexService.Shutdown() | Out-Null
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot stop windream Client Components!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
#Try to start windream Client Components
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Starting windream Client Components!"
|
||||
$windreamControlCenter.StartVFSService(1) | Wait-Process -Timeout $StartTimeout | Out-Null
|
||||
$windreamIndexService.Start() | Out-Null
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot start windream Client Components!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
Return $True
|
||||
|
||||
} #end elseif
|
||||
|
||||
#If Function was called to Start windream Client Components and Service Test was enabled
|
||||
ELSEIF (($Action -like "Start") -and ($ServiceTest -is [Object])) {
|
||||
|
||||
#Checking if windream vfs Service is running
|
||||
IF ((Get-Service -Name vfssvc).Status -ne 'running') {
|
||||
|
||||
Write-LogFile -LogLine "Warning: windream vfs Service is not running!"
|
||||
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Trying to Start/Restart the windream vfs Service!"
|
||||
Stop-Service -Name vfssvc -ErrorAction SilentlyContinue
|
||||
Start-Service -Name vfssvc -ErrorAction Stop
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot Start/Restart windream vfs Service!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine " "
|
||||
Write-LogFile -LogLine "windream vfs Service is running!"
|
||||
|
||||
} #end else
|
||||
|
||||
Write-LogFile -LogLine "Start windream Client Components."
|
||||
|
||||
#Try to start windream Client Components
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Starting windream Client Components!"
|
||||
$windreamControlCenter.StartVFSService(1) | Wait-Process -Timeout $StartTimeout | Out-Null
|
||||
$windreamIndexService.Start() | Out-Null
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot start windream Client Components!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
Return $True
|
||||
|
||||
} #end elseif
|
||||
|
||||
#If Function was called to Start windream Client Components and Service Test was disabled
|
||||
ELSEIF (($Action -like "Start") -and ($ServiceTest -is [Switch])) {
|
||||
|
||||
Write-LogFile -LogLine "Start windream Client Components."
|
||||
|
||||
#Try to start windream Client Components
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Starting windream Client Components!"
|
||||
$windreamControlCenter.StartVFSService(1) | Wait-Process -Timeout $StartTimeout | Out-Null
|
||||
$windreamIndexService.Start() | Out-Null
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot start windream Client Components!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
Return $True
|
||||
|
||||
} #end elseif
|
||||
|
||||
#If Function was called invalid Values, which should be not possible be the ValidateSet of the Function Parameters
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine "Function Call went wrong, please check the ValidateSet"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end else
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info: Write-LogFile - Module does not exist!"
|
||||
Write-Host "DEBUG Info: Please load the Module and try again, running this Function/Module!"
|
||||
Write-Host "DEBUG Info: Exiting, because of this Issue."
|
||||
EXIT
|
||||
|
||||
} #end else
|
||||
|
||||
} #end function
|
||||
367
current/DD-Internal/Modules/Start-ErrorEscalation.psm1
Normal file
367
current/DD-Internal/Modules/Start-ErrorEscalation.psm1
Normal file
@@ -0,0 +1,367 @@
|
||||
Function Restart-windreamClient-withLogging {
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Restart windream Client Components via COM Interface
|
||||
|
||||
.DESCRIPTION
|
||||
If Connection to the windream Server gets interrupted (network loss, eg.), it is neccessery to restart the Client Components.
|
||||
Otherwise you can Stop or Start Client Components with this Function.
|
||||
For a successful performed Action, Function will Return $True, for unccessful $False.
|
||||
|
||||
.REQUIREMENT General
|
||||
PowerShell V3, windream Client Connectivity (>=V3.6)
|
||||
|
||||
.REQUIREMENT Assembly
|
||||
<NONE>
|
||||
|
||||
.REQUIREMENT Variables
|
||||
windreamControlCenter, windreamIndexService, ServiceTest, Action
|
||||
|
||||
.REQUIREMENT Variables preSet
|
||||
<NONE>
|
||||
|
||||
.REQUIREMENT Functions
|
||||
Write-LogFile
|
||||
|
||||
.VERSION
|
||||
1.2.0.0 / 28.09.2018
|
||||
|
||||
.PARAMETER Action
|
||||
Determine which Action you want to perform <Stop|Restart|Start>. Default Value is <Restart>.
|
||||
|
||||
.PARAMETER ServiceTest
|
||||
Set on $True, if Function should check for a running windream vfs Client Service. If it is and Service is stopped, Function will try to start Service. Default Value is $True.
|
||||
|
||||
.PARAMETER StartTimeout
|
||||
|
||||
.EXAMPLE
|
||||
Restart-windreamClient
|
||||
|
||||
.EXAMPLE
|
||||
Restart-windreamClient -Action Start
|
||||
|
||||
.EXAMPLE
|
||||
Restart-windreamClient -Action Start -ServiceTest $False
|
||||
#>
|
||||
|
||||
Param (
|
||||
|
||||
[Parameter(Position=0,Mandatory=$False,HelpMessage='Determine which Action you want to perform <Stop|Restart|Start>. Default Value is "Restart".')]
|
||||
[ValidateSet("Stop","Restart","Start")]
|
||||
[String]$Action="Restart",
|
||||
|
||||
[Parameter(Position=1,Mandatory=$False,HelpMessage='Set on $True, if Function should check for a running windream vfs Client Service. If it is and Service is stopped, Function will try to start Service. Default Value is $True.')]
|
||||
[ValidateSet($True,$False)]
|
||||
[Switch]$ServiceTest=$True,
|
||||
|
||||
[Parameter(Position=2,Mandatory=$False,HelpMessage='Give the Timeout limit in Seconds for the windream Start/Restart procedure, ValidateRange(1 - 300). Default Value is "10".')]
|
||||
[ValidateRange(1,300)]
|
||||
[INT]$StartTimeout=10
|
||||
|
||||
) #end param
|
||||
|
||||
#Clear Error Variable
|
||||
$error.clear()
|
||||
|
||||
#Checking if "Write-LogFile" Module was loaded
|
||||
IF (Get-Module -Name "Write-LogFile") {
|
||||
|
||||
Write-Host "DEBUG Info: Write-LogFile - Module exists."
|
||||
|
||||
#If Servie Test was enabled (by default true) check if windream vfs Service is running
|
||||
IF ($ServiceTest -eq $True) {
|
||||
|
||||
Write-LogFile -LogLine " "
|
||||
Write-LogFile -LogLine "Service Test is enabled!"
|
||||
|
||||
#Check if windream vfs Service is installed
|
||||
Try {
|
||||
|
||||
[Object]$ServiceTest = $NULL
|
||||
[Object]$ServiceTest = Get-Service -Name vfssvc -ErrorAction Stop
|
||||
Write-LogFile -LogLine "Found Service: vfssvc"
|
||||
Write-LogFile -LogLine "Service is currently: $((Get-Service -Name vfssvc).Status)"
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-LogFile -LogLine "WARNING: windream Client seems not to be installed completely."
|
||||
Write-LogFile -LogLine "Missing Service: vfssvc"
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
#If Servie Test is disabled
|
||||
ELSE {
|
||||
|
||||
Write-LogFile -LogLine " "
|
||||
Write-LogFile -LogLine "Service Test is disabled!"
|
||||
|
||||
} #end else
|
||||
|
||||
#Try to create windream Objects
|
||||
Try {
|
||||
|
||||
[Object]$windreamControlCenter = New-Object -ComObject "Wmcc.ControlCenter" -ErrorAction Stop
|
||||
[Object]$windreamIndexService = New-Object -ComObject "WMIndexServer.WMIdxSvControl" -ErrorAction Stop
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot create Object from windream Class Wmcc.ControlCenter or WMIndexServer.WMIdxSvControl!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
#If Function was called to Stop windream Client Components
|
||||
IF ($Action -like "Stop") {
|
||||
|
||||
Write-LogFile -LogLine "Stop windream Client Components."
|
||||
|
||||
#Try to stop windream Client Components
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Stopping windream Client Components!"
|
||||
$windreamControlCenter.StartVFSService(0) | Out-Null
|
||||
$windreamIndexService.Shutdown() | Out-Null
|
||||
$windreamControlCenter.ExitCC(0) | Out-Null
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot stop windream Client Components!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
Return $True
|
||||
|
||||
} #end if
|
||||
|
||||
#If Function was called to Restart windream Client Components and Service Test was enabled
|
||||
ELSEIF (($Action -like "Restart") -and ($ServiceTest -is [Object])) {
|
||||
|
||||
#Checking if windream vfs Service is running
|
||||
IF ((Get-Service -Name vfssvc).Status -ne 'running') {
|
||||
|
||||
Write-LogFile -LogLine "Warning: windream vfs Service is not running!"
|
||||
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Trying to Start/Restart the windream vfs Service!"
|
||||
Stop-Service -Name vfssvc -ErrorAction SilentlyContinue
|
||||
Start-Service -Name vfssvc -ErrorAction Stop
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot Start/Restart windream vfs Service!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine " "
|
||||
Write-LogFile -LogLine "windream vfs Service is running!"
|
||||
|
||||
} #end else
|
||||
|
||||
Write-LogFile -LogLine "Restart windream Client Components."
|
||||
|
||||
#Try to stop windream Client Components
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Stopping windream Client Components!"
|
||||
$windreamControlCenter.StartVFSService(0) | Out-Null
|
||||
$windreamIndexService.Shutdown() | Out-Null
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot stop windream Client Components!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
#Try to start windream Client Components
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Starting windream Client Components!"
|
||||
$windreamControlCenter.StartVFSService(1) | Wait-Process -Timeout $StartTimeout | Out-Null
|
||||
$windreamIndexService.Start() | Out-Null
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot start windream Client Components!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
Return $True
|
||||
|
||||
} #end elseif
|
||||
|
||||
#If Function was called to Restart windream Client Components and Service Test was disabled
|
||||
ELSEIF (($Action -like "Restart") -and ($ServiceTest -is [Switch])) {
|
||||
|
||||
Write-LogFile -LogLine "Restart windream Client Components."
|
||||
|
||||
#Try to stop windream Client Components
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Stopping windream Client Components!"
|
||||
$windreamControlCenter.StartVFSService(0) | Out-Null
|
||||
$windreamIndexService.Shutdown() | Out-Null
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot stop windream Client Components!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
#Try to start windream Client Components
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Starting windream Client Components!"
|
||||
$windreamControlCenter.StartVFSService(1) | Wait-Process -Timeout $StartTimeout | Out-Null
|
||||
$windreamIndexService.Start() | Out-Null
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot start windream Client Components!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
Return $True
|
||||
|
||||
} #end elseif
|
||||
|
||||
#If Function was called to Start windream Client Components and Service Test was enabled
|
||||
ELSEIF (($Action -like "Start") -and ($ServiceTest -is [Object])) {
|
||||
|
||||
#Checking if windream vfs Service is running
|
||||
IF ((Get-Service -Name vfssvc).Status -ne 'running') {
|
||||
|
||||
Write-LogFile -LogLine "Warning: windream vfs Service is not running!"
|
||||
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Trying to Start/Restart the windream vfs Service!"
|
||||
Stop-Service -Name vfssvc -ErrorAction SilentlyContinue
|
||||
Start-Service -Name vfssvc -ErrorAction Stop
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot Start/Restart windream vfs Service!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine " "
|
||||
Write-LogFile -LogLine "windream vfs Service is running!"
|
||||
|
||||
} #end else
|
||||
|
||||
Write-LogFile -LogLine "Start windream Client Components."
|
||||
|
||||
#Try to start windream Client Components
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Starting windream Client Components!"
|
||||
$windreamControlCenter.StartVFSService(1) | Wait-Process -Timeout $StartTimeout | Out-Null
|
||||
$windreamIndexService.Start() | Out-Null
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot start windream Client Components!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
Return $True
|
||||
|
||||
} #end elseif
|
||||
|
||||
#If Function was called to Start windream Client Components and Service Test was disabled
|
||||
ELSEIF (($Action -like "Start") -and ($ServiceTest -is [Switch])) {
|
||||
|
||||
Write-LogFile -LogLine "Start windream Client Components."
|
||||
|
||||
#Try to start windream Client Components
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Starting windream Client Components!"
|
||||
$windreamControlCenter.StartVFSService(1) | Wait-Process -Timeout $StartTimeout | Out-Null
|
||||
$windreamIndexService.Start() | Out-Null
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot start windream Client Components!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
Return $True
|
||||
|
||||
} #end elseif
|
||||
|
||||
#If Function was called invalid Values, which should be not possible be the ValidateSet of the Function Parameters
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine "Function Call went wrong, please check the ValidateSet"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end else
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info: Write-LogFile - Module does not exist!"
|
||||
Write-Host "DEBUG Info: Please load the Module and try again, running this Function/Module!"
|
||||
Write-Host "DEBUG Info: Exiting, because of this Issue."
|
||||
EXIT
|
||||
|
||||
} #end else
|
||||
|
||||
} #end function
|
||||
211
current/DD-Internal/Modules/Start-SQLDB-Query-withLogging.psm1
Normal file
211
current/DD-Internal/Modules/Start-SQLDB-Query-withLogging.psm1
Normal file
@@ -0,0 +1,211 @@
|
||||
Function Start-SQLDB-Query-withLogging {
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Function will send a SQL Query to a SQL DB.
|
||||
|
||||
.DESCRIPTION
|
||||
Function will send a SQL Query to a SQL DB. If you set a read command (SELECT ...), function will return a dataset.
|
||||
|
||||
.REQUIREMENT General
|
||||
PowerShell V2 and Function "Write-Logfile".
|
||||
|
||||
.REQUIREMENT Variables
|
||||
DBSQLQuery, DBSQLQueryType, DBSQLConnectServer, DBSQLConnectUser, DBSQLConnectPassword, DBSQLConnectDatabase, DBSQLConnectIntegratedSecurity, DBSQLCommand, DBSQLAdapter, DBSQLConnection
|
||||
|
||||
.REQUIREMENT Functions
|
||||
Write-Logfile
|
||||
|
||||
.VERSION
|
||||
Number: 1.0.1.0 / Date: 24.09.2017
|
||||
|
||||
.PARAMETER DBSQLQuery
|
||||
Give a Standard T-SQL Query
|
||||
|
||||
.PARAMETER DBSQLQueryType
|
||||
Give read or write, depends on your planned action ("select" is only read, "insert" and "update" are write)
|
||||
|
||||
.EXAMPLE
|
||||
Func-DB-SQL-Query -DBSQLQueryType read -DBSQLQuery "SELECT * from TABLE;"
|
||||
|
||||
.EXAMPLE
|
||||
Func-DB-SQL-Query -DBSQLQueryType write -DBSQLQuery "INSERT INTO TABLE (column1,column2,column3) VALUES ('Text1', Zahl1, Zahl2) WHERE column4 = 'Text2';"
|
||||
|
||||
.EXAMPLE
|
||||
Func-DB-SQL-Query -DBSQLQueryType write -DBSQLQuery "UPDATE TABLE SET column1='Text1',column2=Zahl1,column3=Zahl2 WHERE column4 = 'Text2';"
|
||||
#>
|
||||
|
||||
Param (
|
||||
|
||||
[Parameter(Position=0,Mandatory=$False,HelpMessage='Give the SQL Servername or Server name incl. Instance name')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[STRING]$DBSQLConnectServer=(Get-Variable -Name DBSQLConnectServer -Scope Global -ValueOnly -ErrorAction SilentlyContinue),
|
||||
|
||||
[Parameter(Position=1,Mandatory=$False,HelpMessage='Give the database user name')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[STRING]$DBSQLConnectUser=(Get-Variable -Name DBSQLConnectUser -Scope Global -ValueOnly -ErrorAction SilentlyContinue),
|
||||
|
||||
[Parameter(Position=2,Mandatory=$False,HelpMessage='Give the database user password')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[STRING]$DBSQLConnectPassword=(Get-Variable -Name DBSQLConnectPassword -Scope Global -ValueOnly -ErrorAction SilentlyContinue),
|
||||
|
||||
[Parameter(Position=3,Mandatory=$False,HelpMessage='Give the database name')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[STRING]$DBSQLConnectDatabase=(Get-Variable -Name DBSQLConnectDatabase -Scope Global -ValueOnly -ErrorAction SilentlyContinue),
|
||||
|
||||
[Parameter(Position=4,Mandatory=$False,HelpMessage='Determ if current login credentials should be used for database login ()')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[STRING]$DBSQLConnectIntegratedSecurity=(Get-Variable -Name DBSQLConnectIntegratedSecurity -Scope Global -ValueOnly -ErrorAction SilentlyContinue),
|
||||
|
||||
[Parameter(Position=5,Mandatory=$True,HelpMessage='Specify the SQL Query')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[STRING]$DBSQLQuery,
|
||||
|
||||
[Parameter(Position=6,Mandatory=$False,HelpMessage='Determ if Query was for read or write operations')]
|
||||
[ValidateSet("read","write")]
|
||||
[STRING]$DBSQLQueryType='read',
|
||||
|
||||
[Parameter(Position=7,Mandatory=$False,HelpMessage=')')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[STRING]$DBSQLErrorAction='continue'
|
||||
|
||||
) #end param ValueFromPipeline=$True
|
||||
|
||||
|
||||
IF (Get-Module -Name "Write-LogFile") {
|
||||
|
||||
Write-Logfile -LogLine ""
|
||||
Write-Logfile -LogLine "Connecting with DB:"
|
||||
Write-Logfile -LogLine "Server = $DBSQLConnectServer, uid=$DBSQLConnectUser, pwd=<set in ConfigFile>, Database = $DBSQLConnectDatabase, Integrated Security = $DBSQLConnectIntegratedSecurity"
|
||||
|
||||
Try {
|
||||
|
||||
$DBSQLConnection = New-Object System.Data.SqlClient.SqlConnection
|
||||
$DBSQLConnection.ConnectionString = "Server = $DBSQLConnectServer; uid=$DBSQLConnectUser; pwd=$DBSQLConnectPassword; Database = $DBSQLConnectDatabase; Integrated Security = $DBSQLConnectIntegratedSecurity"
|
||||
|
||||
Write-Logfile -LogLine "Processing SQL Query:"
|
||||
Write-Logfile -LogLine $DBSQLQuery
|
||||
|
||||
IF ($DBSQLQueryType -eq 'read') {
|
||||
|
||||
Try {
|
||||
|
||||
$DBSQLCommand = New-Object System.Data.SqlClient.SqlCommand
|
||||
$DBSQLCommand.CommandText = $DBSQLQuery
|
||||
$DBSQLCommand.Connection = $DBSQLConnection
|
||||
|
||||
$DBSQLAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
|
||||
$DBSQLAdapter.SelectCommand = $DBSQLCommand
|
||||
|
||||
$DBSQLDataSet = New-Object System.Data.DataSet
|
||||
|
||||
$DBSQLConnection.Open()
|
||||
$DBSQLAdapter.Fill($DBSQLDataSet)
|
||||
$DBSQLConnection.Close()
|
||||
|
||||
Write-Logfile -Logline "SQL Query result with $($DBSQLDataSet.Tables[0].Rows.Count) row(s)."
|
||||
#$DBSQLDataSet.Tables[0].Rows | Out-GridView
|
||||
|
||||
Return $DBSQLDataSet
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "ERROR: Unable to process SQL Query (read)!"
|
||||
|
||||
IF ($ErrorAction -eq 'continue') {
|
||||
|
||||
Write-Logfile -LogLine "Program will continue, anyway."
|
||||
|
||||
} #end if
|
||||
|
||||
ELSEIF ($ErrorAction -eq 'stop') {
|
||||
|
||||
Write-Logfile -LogLine "Program will stop."
|
||||
exit
|
||||
|
||||
} #end elseif
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine "Invalid Value for Parameter DBSQLErrorAction detected."
|
||||
Write-Logfile -LogLine "Allowed Values are 'continue' or 'stop'."
|
||||
Write-Logfile -LogLine "Program will continue, anyway."
|
||||
|
||||
} #end else
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
ELSEIF ($DBSQLQueryType -eq 'write') {
|
||||
|
||||
Try {
|
||||
|
||||
$DBSQLCommand = New-Object System.Data.SqlClient.SqlCommand
|
||||
$DBSQLCommand.CommandText = $DBSQLQuery
|
||||
$DBSQLCommand.Connection = $DBSQLConnection
|
||||
|
||||
$DBSQLConnection.Open()
|
||||
$DBSQLCommand.ExecuteNonQuery()
|
||||
$DBSQLConnection.Close()
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "ERROR: Unable to process SQL Query (write)!"
|
||||
|
||||
IF ($ErrorAction -eq 'continue') {
|
||||
|
||||
Write-Logfile -LogLine "Program will continue, anyway."
|
||||
|
||||
} #end if
|
||||
|
||||
ELSEIF ($ErrorAction -eq 'stop') {
|
||||
|
||||
Write-Logfile -LogLine "Program will stop."
|
||||
exit
|
||||
|
||||
} #end elseif
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine "Invalid Value for parameter DBSQLErrorAction detected."
|
||||
Write-Logfile -LogLine "Allowed Values are 'continue' or 'stop'."
|
||||
Write-Logfile -LogLine "Program will continue, anyway."
|
||||
|
||||
} #end else
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end elseif
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine "ERROR: Invalid parameter for function!"
|
||||
|
||||
} #end else
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "ERROR: Unable to etablish a DB Connection!"
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info: Write-LogFile - Module does not exist!"
|
||||
Write-Host "DEBUG Info: Please load the Module and try again, running this Function/Module!"
|
||||
Write-Host "DEBUG Info: Exiting, because of this Issue."
|
||||
EXIT
|
||||
|
||||
} #end else
|
||||
|
||||
} #end function
|
||||
@@ -0,0 +1,351 @@
|
||||
Function Start-windreamSession-withLogging {
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Start a connection / Session with a windream Server.
|
||||
|
||||
.DESCRIPTION
|
||||
To work in or with windream, you need to start a Session with a windream Server, to access its files, folders and indices.
|
||||
The windream Drive letter which was retrived by running this module, will be set for the whole Script.
|
||||
For Impersonation Login Methode, all these Parameters must be set: windreamServer, windreamDomain, windreamUserName and windreamUserPassword.
|
||||
Function returns with the whole windreamSession Object if connection was successfully established, otherwise with a $False.
|
||||
|
||||
.REQUIREMENT General
|
||||
PowerShell V3, windream Client Connectivity (>=V3.6)
|
||||
|
||||
.REQUIREMENT Assembly
|
||||
<NONE>
|
||||
|
||||
.REQUIREMENT Variables
|
||||
windreamServer, windreamVersion, windreamServerBrowser, windreamConnect, windreamSession, windreamDriveLetter, windreamDriveLetterMapping, PathTest
|
||||
|
||||
.REQUIREMENT Variables preSet
|
||||
<NONE>
|
||||
|
||||
.REQUIREMENT Functions
|
||||
Write-LogFile
|
||||
|
||||
.VERSION
|
||||
1.2.0.0 / 02.12.2016
|
||||
|
||||
.PARAMETER windreamServer
|
||||
Optional Parameter. Give Server Name of a specific windream Server, you want to connect with. Otherwise default will be choosen.
|
||||
|
||||
.PARAMETER windreamDomain
|
||||
Optional Parameter. Give a Windows Domain (which is windream autorisiered) for Impersonation Login Methode. Otherwise current domain will be choosen.
|
||||
|
||||
.PARAMETER windreamUserName
|
||||
Optional Parameter. Give a Windows User Name (who is windream autorisiered) for Impersonation Login Methode. Otherwise current User Name will be choosen.
|
||||
|
||||
.PARAMETER windreamUserPassword
|
||||
Optional Parameter. Give the Password for the User name you set bevor in $windreamUserName for Impersonation Login Methode.
|
||||
|
||||
.PARAMETER windreamVersion
|
||||
Optional Parameter. Give the minimum Version of windream, to make sure later function calls will work (Example 3.6, 4.0, ...).
|
||||
|
||||
.PARAMETER windream64Bit
|
||||
Optional Parameter. Available since windream 6.0. Necessary, if following functions need 64Bit Integer Support (eg. GetWMObjectByIdEx64(WMEntity aWMEntity, int64 aWMObjectId)).
|
||||
|
||||
.PARAMETER windreamDriveLetterMapping
|
||||
Optional Parameter. If windream Drive Letter was set in the windream Client config, call this Parameter using $true, to check the Mapping in the Windows Explorer. Default Value is "$True".
|
||||
|
||||
.EXAMPLE
|
||||
Start-windreamSession
|
||||
|
||||
.EXAMPLE
|
||||
Start-windreamSession -windreamVersion "3.6" -windream64Bit <$True|$False>
|
||||
|
||||
.EXAMPLE
|
||||
Start-windreamSession -windreamServer <ServerName> -windreamDomain <domain.local> -windreamUserName <UserName> -windreamUserPassword <UserPassword>
|
||||
|
||||
.EXAMPLE
|
||||
Start-windreamSession -windreamVersion "3.6" -windream64Bit <$True|$False> -windreamServer <ServerName> -windreamDomain <domain.local> -windreamUserName <UserName> -windreamUserPassword <UserPassword>
|
||||
#>
|
||||
|
||||
[cmdletbinding()]
|
||||
|
||||
Param (
|
||||
|
||||
[Parameter(Mandatory=$False,HelpMessage='Optional Parameter. Give Server Name of a specific windream Server, you want to connect with. Otherwise default will be choosen.')]
|
||||
[AllowEmptyString()]
|
||||
[String]$windreamServer=$NULL,
|
||||
|
||||
[Parameter(Mandatory=$False,HelpMessage='Optional Parameter. Give a Windows Domain (which is windream autorisiered) for Impersonation Login Methode. Otherwise current domain will be choosen.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$windreamDomain=$NULL,
|
||||
|
||||
[Parameter(Mandatory=$False,HelpMessage='Optional Parameter. Give a Windows User Name (who is windream autorisiered) for Impersonation Login Methode. Otherwise current User Name will be choosen.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$windreamUserName=$NULL,
|
||||
|
||||
[Parameter(Mandatory=$False,HelpMessage='Optional Parameter. Give the Password for the User name you set bevor in $windreamUserName for Impersonation Login Methode.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$windreamUserPassword=$NULL,
|
||||
|
||||
[Parameter(Mandatory=$False,HelpMessage='Optional Parameter. Give the minimum Version of windream, to make sure later function calls will work (Example 3.6, 4.0, ...). Default Value is 4.0.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$windreamVersion="4.0",
|
||||
|
||||
[Parameter(Mandatory=$False,HelpMessage='Optional Parameter. Available since windream 6.0. Necessary, if following functions need 64Bit Integer Support (eg. GetWMObjectByIdEx64(WMEntity aWMEntity, int64 aWMObjectId)). Default Value is $False')]
|
||||
[ValidateSet($True,$False)]
|
||||
[Switch]$windream64Bit=$False,
|
||||
|
||||
[Parameter(Mandatory=$False,HelpMessage='Optional Parameter. If windream Drive Letter was set in the windream Client config, call this Parameter using $true, to check the Mapping in the Windows Explorer. Default Value is "$True".')]
|
||||
[ValidateSet($True,$False)]
|
||||
[Switch]$windreamDriveLetterMapping=$True
|
||||
|
||||
) #end param
|
||||
|
||||
#Clear Error Variable
|
||||
$error.clear()
|
||||
|
||||
#Checking if "Write-LogFile" Module was loaded
|
||||
IF (Get-Module -Name "Write-LogFile") {
|
||||
|
||||
Write-Host "DEBUG Info: Write-LogFile - Module exists."
|
||||
|
||||
#If Function was called without an explicite windream Server, try to get the default
|
||||
IF (!$windreamServer) {
|
||||
|
||||
Write-Logfile -LogLine " "
|
||||
Write-Logfile -LogLine "Function was called without a specific windream Server,"
|
||||
Write-Logfile -LogLine "trying to find the default windream Server."
|
||||
|
||||
Try {
|
||||
|
||||
$windreamServerBrowser = New-Object -ComObject "WMOBrws.ServerBrowser" -ErrorAction Stop
|
||||
$windreamServer = $windreamServerBrowser.GetCurrentServer()
|
||||
Write-Logfile -LogLine "windream Server is: $windreamServer"
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot create Object from windream Class WMOBrws.ServerBrowser!"
|
||||
Write-Logfile -LogLine "And/Or unable the retrieve default windream Server!"
|
||||
$windreamServer = $NULL
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
#If Function was called with an explicite windream Server
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine " "
|
||||
Write-Logfile -LogLine "Function was called with specific windream Server, trying to connect to $windreamServer"
|
||||
Write-Logfile -LogLine "Remember: Since windream 4.0, this will only work if you are using Impersonation Login Methode."
|
||||
Write-LogFile -Logline "windreamServer, windreamDomain, windreamUserName and windreamUserPassword"
|
||||
|
||||
Try {
|
||||
|
||||
$windreamServerBrowser = New-Object -ComObject "WMOBrws.ServerBrowser" -ErrorAction Stop
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot create Object from windream Class WMOBrws.ServerBrowser!"
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end else
|
||||
|
||||
#Go ahead if windreamServer is not null and is reachable via network ping
|
||||
IF (($windreamServer) -and (Test-Connection -ComputerName $windreamServer -Count 1 -ErrorAction SilentlyContinue)) {
|
||||
|
||||
Try {
|
||||
|
||||
$windreamConnect = New-Object -ComObject "Windream.WMConnect" -ErrorAction Stop
|
||||
$windreamConnect.MinReqVersion = $windreamVersion
|
||||
$windreamConnect.ClientSupports64BitID = $windream64Bit
|
||||
Write-Logfile -LogLine "windream Connect created!"
|
||||
|
||||
} # end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot create Object from windream Class Windream.WMSession!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
Try {
|
||||
|
||||
$windreamSession = New-Object -ComObject "Windream.WMSession" #-ErrorAction Stop
|
||||
Write-Logfile -LogLine "windream Session created!"
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot create Object from windream Class Windream.WMSession!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
#Use Impersonation Login methode, if these three Parameters are set (-gt $NULL).
|
||||
IF (($windreamUserName) -and ($windreamUserPassword) -and ($windreamDomain)) {
|
||||
|
||||
Try {
|
||||
|
||||
$windreamConnect.ModuleId = 9
|
||||
|
||||
$windreamImpersonation = New-Object -ComObject "WMOTool.WMUserIdentity" -ErrorAction Stop
|
||||
$windreamImpersonation.aDomain = $windreamDomain
|
||||
$windreamImpersonation.aPassword = $windreamUserPassword
|
||||
$windreamImpersonation.aServerName = $windreamServer
|
||||
$windreamImpersonation.aUserName = $windreamUserName
|
||||
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Try to Login Impersonation"
|
||||
$windreamSession = $windreamConnect.Login($windreamImpersonation)
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot Login into windream Session!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot create Object from windream Class WMOTool.WMUserIdentity!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
#If Impersonation Login methode was not set, try to login with current username, domain and password
|
||||
ELSE {
|
||||
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Try to Login with current credentials."
|
||||
$windreamConnect.LoginSession($windreamSession)
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot Login into windream Session!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end else
|
||||
|
||||
IF ($windreamSession.aLoggedin -eq $True) {
|
||||
|
||||
Write-Logfile -LogLine " "
|
||||
Write-Logfile -LogLine "Connection established"
|
||||
Write-Logfile -LogLine "You are connected with $($windreamConnect.ServerName) as $($windreamSession.aUser.aName)"
|
||||
Write-Host "DEBUG Info: Do not forget to Logout Session after finished work."
|
||||
|
||||
$windreamDriveLetter = $windreamServerBrowser.GetServerValue($windreamServer, "DriveLetter", 0)
|
||||
|
||||
IF ($windreamDriveLetter) {
|
||||
|
||||
Write-Logfile -LogLine "The configured windream Drive Letter is: $windreamDriveLetter"
|
||||
Set-Variable -Name windreamDriveLetter -Value $windreamDriveLetter -Scope Global -ErrorAction SilentlyContinue
|
||||
|
||||
$PathTest = Test-Path -Path "$windreamDriveLetter`:\" -PathType Container
|
||||
|
||||
IF ($PathTest -eq $True) {
|
||||
|
||||
Write-Logfile -LogLine "The configured windream Drive Letter seems to be connected, as well!"
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine "The configured windream Drive Letter seems not to be connected!"
|
||||
|
||||
IF ($windreamDriveLetterMapping -eq $True) {
|
||||
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Try to connect the windream Drive ..."
|
||||
Remove-PSDrive -Name "$windreamDriveLetter" -Force -Scope Global -ErrorAction SilentlyContinue
|
||||
$PathTest = New-PSDrive -Name "$windreamDriveLetter" -PSProvider FileSystem -Root "\\windream\objects" -Persist -Scope Global -ErrorAction Stop
|
||||
Write-Logfile -LogLine "windream Drive Letter $PathTest should be connected, now!"
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "Cannot map the windream Drive!"
|
||||
Set-Variable -Name windreamDriveLetter -Value $NULL -Scope Global -ErrorAction SilentlyContinue
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine "Will not try to map the windream Drive..."
|
||||
|
||||
} #end else
|
||||
|
||||
} #end else
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine "WARNING: There is no windream Drive Letter configured."
|
||||
Write-Logfile -LogLine "This could cause access problems!"
|
||||
Write-Logfile -LogLine "Please check your windream Alias Settings!"
|
||||
|
||||
} #end else
|
||||
|
||||
Return $windreamSession
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine " "
|
||||
Write-Logfile -LogLine "Connection refused"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end else
|
||||
|
||||
} #end if
|
||||
|
||||
#Stop if windream Server was unavailable
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine "Cannot retrieve windream Server to connect with or test connection failed!"
|
||||
Write-Logfile -LogLine $Error
|
||||
Return $False
|
||||
|
||||
} #end else
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info: Write-LogFile - Module does not exist!"
|
||||
Write-Host "DEBUG Info: Please load the Module and try again, running this Function/Module!"
|
||||
Write-Host "DEBUG Info: Exiting, because of this Issue."
|
||||
EXIT
|
||||
|
||||
} #end else
|
||||
|
||||
} #end function
|
||||
|
||||
167
current/DD-Internal/Modules/Test-FileState-withLogging.psm1
Normal file
167
current/DD-Internal/Modules/Test-FileState-withLogging.psm1
Normal file
@@ -0,0 +1,167 @@
|
||||
Function Test-FileState-withLogging {
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Function will check if given File is accessible.
|
||||
|
||||
.DESCRIPTION
|
||||
This Function will check the accessibility of a File.
|
||||
If the given File was readable, Function will Return "readable"
|
||||
Additional Function can be called with the Parameter "-Action writetest",
|
||||
then after a successful readtest, there will be a writetest.
|
||||
On Success Return Value will be "writeable".
|
||||
If File doesn exist Function will return $NULL.
|
||||
If File Attribute was not editable (by resetting them),
|
||||
Function will return "noteditable".
|
||||
|
||||
.REQUIREMENT General
|
||||
PowerShell V3
|
||||
|
||||
.REQUIREMENT Assembly
|
||||
<NONE>
|
||||
|
||||
.REQUIREMENT Variables
|
||||
SourceFile, SourceFileAttributeReset, Action, FileInfo, FileCheckResult, FileStream
|
||||
|
||||
.REQUIREMENT Variables preSet
|
||||
<NONE>
|
||||
|
||||
.REQUIREMENT Functions
|
||||
Write-Logfile
|
||||
|
||||
.VERSION
|
||||
Number: 1.1.0.0 / Date: 21.03.2017
|
||||
|
||||
.PARAMETER SourceFile
|
||||
Give the full Path and Filename you want to check.
|
||||
|
||||
.PARAMETER SourceFileAttributeReset
|
||||
Set on $True, if Function should reset the File Attributes (if ReadOnly was set). Default Value is $True.
|
||||
|
||||
.PARAMETER Action
|
||||
Determine which Action you want to perform <readtest|writetest>. Default Value is "readtest".
|
||||
|
||||
.EXAMPLE
|
||||
Test-FileState-withLogging -SourceFile "E:\Path\file_to_check.txt"
|
||||
|
||||
.EXAMPLE
|
||||
Test-FileState-withLogging -SourceFile "E:\Path\file_to_check.txt" -Action writetest
|
||||
#>
|
||||
|
||||
Param (
|
||||
|
||||
[Parameter(Mandatory=$True,HelpMessage='Give the full Path and Filename you want to check.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$SourceFile,
|
||||
|
||||
[Parameter(Mandatory=$False,HelpMessage='Set on $True, if Function should reset the File Attributes (if ReadOnly was set). Default Value is $True.')]
|
||||
[ValidateSet($True,$False)]
|
||||
[Switch]$SourceFileAttributeReset=$True,
|
||||
|
||||
[Parameter(Mandatory=$False,HelpMessage='Determine which Action you want to perform <readtest|writetest>. Default Value is "readtest".')]
|
||||
[ValidateSet("readtest","writetest")]
|
||||
[String]$Action="readtest"
|
||||
|
||||
) #end param
|
||||
|
||||
#Checking if "Write-LogFile" Module was loaded
|
||||
IF (Get-Module -Name "Write-LogFile") {
|
||||
|
||||
IF ((Test-Path -Path $SourceFile) -eq 'True') {
|
||||
|
||||
$FileInfo = (New-Object System.IO.FileInfo $SourceFile)
|
||||
$FileCheckResult = "unknown"
|
||||
|
||||
Write-Logfile -LogLine " "
|
||||
Write-Logfile -LogLine "Checking if file: $SourceFile is locked/readonly..."
|
||||
|
||||
IF (($FileInfo.Attributes -match "ReadOnly") -and ($SourceFileAttributeReset -eq $True)) {
|
||||
|
||||
Write-Host "DEBUG Info: ReadOnly Attribute found, removing if possible"
|
||||
|
||||
Try {
|
||||
|
||||
$FileInfo.Attributes="Archive","Temporary"
|
||||
Write-Host "DEBUG Info: File Attributes has been recessed!"
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "WARNING: Cannot recessed File Attributes!"
|
||||
Return "noteditable"
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
Write-Logfile -LogLine "Checking if file: $SourceFile is readable."
|
||||
|
||||
# Check if file is readable
|
||||
Try {
|
||||
|
||||
$FileStream = $FileInfo.Open([System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::Read)
|
||||
Write-Host "DEBUG Info: Is file readable?" $FileStream.CanRead
|
||||
$FileStream.Close()
|
||||
$FileCheckResult = "readable"
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "File: $SourceFile is not even readable."
|
||||
Write-Host "DEBUG Info: Is file readable?" $FileStream.CanRead
|
||||
$FileCheckResult = "notreadable"
|
||||
|
||||
} #end catch
|
||||
|
||||
# Check if file is writeable
|
||||
IF (($FileCheckResult -eq "readable") -and ($Action -eq 'writetest')) {
|
||||
|
||||
Write-Logfile -LogLine "Checking if file: $SourceFile is writeable."
|
||||
|
||||
Try {
|
||||
|
||||
$FileStream = $FileInfo.Open([System.IO.FileMode]::Open, [System.IO.FileAccess]::Write, [System.IO.FileShare]::Write)
|
||||
Write-Host "DEBUG Info: Is file writeable?" $FileStream.CanWrite
|
||||
$FileStream.Close()
|
||||
$FileCheckResult = "writeable"
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "File: $SourceFile is not writeable."
|
||||
Write-Host "DEBUG Info: Is file writeable?" $FileStream.CanWrite
|
||||
$FileCheckResult = "notwriteable"
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
Write-Logfile -LogLine "File $SourceFile checked with result: $FileCheckResult"
|
||||
Return $FileCheckResult
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine " "
|
||||
Write-Logfile -LogLine "Given file: $SourceFile seems not to exist, or access is denied."
|
||||
Return $NULL
|
||||
|
||||
} #end else
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host " "
|
||||
Write-Host "DEBUG Info: Write-LogFile - Module does not exist!"
|
||||
Write-Host "DEBUG Info: Please load the Module and try again, running this Function/Module!"
|
||||
Write-Host "DEBUG Info: Exiting, because of this Issue."
|
||||
EXIT
|
||||
|
||||
} #end else
|
||||
|
||||
} #end function
|
||||
114
current/DD-Internal/Modules/Test-Path-withLogging.psm1
Normal file
114
current/DD-Internal/Modules/Test-Path-withLogging.psm1
Normal file
@@ -0,0 +1,114 @@
|
||||
Function Test-Path-withLogging {
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Function will check the given Path for existence.
|
||||
|
||||
.DESCRIPTION
|
||||
If Path doesn´t exist, Function will try to create it.
|
||||
You can disable the create Function by calling with "-Action "ignore"".
|
||||
|
||||
.REQUIREMENT General
|
||||
PowerShell V2
|
||||
|
||||
.REQUIREMENT Assembly
|
||||
<NONE>
|
||||
|
||||
.REQUIREMENT Variables
|
||||
Path, PathTest
|
||||
|
||||
.REQUIREMENT Variables preSet
|
||||
<NONE>
|
||||
|
||||
.REQUIREMENT Functions
|
||||
Write-Logfile
|
||||
|
||||
.VERSION
|
||||
Number: 1.0.1.0 / Date: 17.12.2016
|
||||
|
||||
.PARAMETER Path
|
||||
Give the full Path you want to check or create.
|
||||
|
||||
.PARAMETER Action
|
||||
Determine which Action you want to perform <create|ignore". Default Value is "create".
|
||||
|
||||
.EXAMPLE
|
||||
Test-Path-withLogging -Path "E:\Path\to\create"
|
||||
|
||||
.EXAMPLE
|
||||
Test-Path-withLogging -Path "E:\Path\to\check" -Action "ignore"
|
||||
#>
|
||||
|
||||
Param (
|
||||
|
||||
[Parameter(Mandatory=$True,HelpMessage='Give the full Path you want to check.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$Path,
|
||||
|
||||
[Parameter(Mandatory=$False,HelpMessage='Determine which Action you want to perform <create|ignore". Default Value is "create".')]
|
||||
[ValidateSet("create","ignore")]
|
||||
[String]$Action="create"
|
||||
|
||||
) #end param
|
||||
|
||||
#Checking if "Write-LogFile" Module was loaded
|
||||
IF (Get-Module -Name "Write-LogFile") {
|
||||
|
||||
Write-Logfile -LogLine " "
|
||||
Write-Logfile -LogLine "Checking Path $Path for existence."
|
||||
$PathTest = Test-Path -PathType Container $Path
|
||||
|
||||
#If given Path already exists
|
||||
IF ($PathTest -eq "True") {
|
||||
|
||||
Write-Logfile -LogLine "Path $Path already exists and can be used."
|
||||
Return $True
|
||||
|
||||
} #end if
|
||||
|
||||
#If given Path does not exist
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine "Path $Path does not exist."
|
||||
|
||||
IF ($Action -eq "create") {
|
||||
|
||||
Try {
|
||||
|
||||
Write-Logfile -LogLine "Path $Path has to been created."
|
||||
New-Item -Path $Path -ItemType directory -Force -ErrorAction Stop
|
||||
Return $True
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "ERROR: Unable to create Path."
|
||||
Write-Logfile -LogLine "INFO: Maybe there is an access or rights Problem."
|
||||
Return $False
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Return $False
|
||||
|
||||
} #end else
|
||||
|
||||
} #end else
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host " "
|
||||
Write-Host "DEBUG Info: Write-LogFile - Module does not exist!"
|
||||
Write-Host "DEBUG Info: Please load the Module and try again, running this Function/Module!"
|
||||
Write-Host "DEBUG Info: Exiting, because of this Issue."
|
||||
EXIT
|
||||
|
||||
} #end else
|
||||
|
||||
} #end function
|
||||
Binary file not shown.
232
current/DD-Internal/Modules/Write-LogFile.psm1
Normal file
232
current/DD-Internal/Modules/Write-LogFile.psm1
Normal file
@@ -0,0 +1,232 @@
|
||||
Function Write-LogFile {
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Function will write a given String to a Logfile.
|
||||
|
||||
.DESCRIPTION
|
||||
Just like the cmdlet Write-Host, this Function will display Output on the Console.
|
||||
Parallel Output will be written into a designated LogFile.
|
||||
It is recommended to init the LogPath Variable with $Null and the LogPaths Variable with a possible Path,
|
||||
which has to be checked for accessible.
|
||||
This is important, because if given Path was inaccessible (-> Access Test failed), Function will try some other Paths for accessible.
|
||||
These are: The ScriptPath (\Logs) from, which triggerd this Function and $env:temp\Digital Data\$ScriptName\Logs.
|
||||
After a successful Access Test, Function will set the Variable LogPath, with the first accessible Path tested.
|
||||
Function will not give any Return Values, because if it is impossible to write a LogFile, Function will force the whole Script to exit.
|
||||
|
||||
.REQUIREMENT General
|
||||
PowerShell V2
|
||||
|
||||
.REQUIREMENT Assembly
|
||||
<NONE>
|
||||
|
||||
.REQUIREMENT Variables
|
||||
PathTest, FileTest, LogPaths, Counter1, LogLine
|
||||
|
||||
.REQUIREMENT Variables preSet
|
||||
LogFile, LogPath, ScriptName, ScriptPath
|
||||
|
||||
.REQUIREMENT Functions
|
||||
<NONE>
|
||||
|
||||
.VERSION
|
||||
Number: 2.1.0.1 / Date: 23.09.2017
|
||||
|
||||
.PARAMETER LogLine
|
||||
Give the String you want to be written into the Logfile.
|
||||
|
||||
.EXAMPLE
|
||||
Write-LogFile -LogLine "Write this in my Log, please."
|
||||
|
||||
.EXAMPLE
|
||||
Write-LogFile -LogLine "Write this Variabel $Variable in my Log, please."
|
||||
#>
|
||||
|
||||
Param (
|
||||
|
||||
[Parameter(Position=0,Mandatory=$True,HelpMessage='Give the String you want to be written into the Logfile.')]
|
||||
[AllowEmptyString()]
|
||||
[STRING]$LogLine,
|
||||
|
||||
[Parameter(Position=1,Mandatory=$False,HelpMessage='Give the String you want to be written into the Logfile.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[STRING]$LogFile=(Get-Variable -Name LogFile -Scope Global -ValueOnly -ErrorAction SilentlyContinue),
|
||||
|
||||
[Parameter(Position=2,Mandatory=$False,HelpMessage='Give the String you want to be written into the Logfile.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[STRING]$LogPath=(Get-Variable -Name LogPath -Scope Global -ValueOnly -ErrorAction SilentlyContinue),
|
||||
|
||||
[Parameter(Position=3,Mandatory=$False,HelpMessage='Give the String you want to be written into the Logfile.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[STRING]$ScriptName=(Get-Variable -Name ScriptName -Scope Global -ValueOnly -ErrorAction SilentlyContinue),
|
||||
|
||||
[Parameter(Position=4,Mandatory=$False,HelpMessage='Give the String you want to be written into the Logfile.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[STRING]$ScriptPath=(Get-Variable -Name ScriptPath -Scope Global -ValueOnly -ErrorAction SilentlyContinue)
|
||||
|
||||
) #end param
|
||||
|
||||
#Clear Error Variable
|
||||
$error.clear()
|
||||
|
||||
IF (!$LogFile) {
|
||||
|
||||
$LogFile = ((($MyInvocation.MyCommand.Name) -split "\.")[0].ToString())+".log"
|
||||
Write-Host "DEBUG Info - Write-LogFile: FailSafe Setting for LogFile, was set to: $LogFile"
|
||||
|
||||
} #end if
|
||||
|
||||
IF (!$LogPath) {
|
||||
|
||||
$LogPath = $PSScriptRoot+"\Logs"
|
||||
Write-Host "DEBUG Info - Write-LogFile: FailSafe Setting for LogPath, was set to: $LogPath"
|
||||
|
||||
} #end if
|
||||
|
||||
IF (!$ScriptName) {
|
||||
|
||||
$ScriptName = ((($MyInvocation.MyCommand.Name) -split "\.")[0].ToString())
|
||||
Write-Host "DEBUG Info - Write-LogFile: FailSafe Setting for ScriptName, was set to: $ScriptName"
|
||||
|
||||
} #end if
|
||||
|
||||
IF (!$ScriptPath) {
|
||||
|
||||
$ScriptPath = $PSScriptRoot
|
||||
Write-Host "DEBUG Info - Write-LogFile: FailSafe Setting for ScriptPath, was set to: $ScriptPath"
|
||||
|
||||
} #end if
|
||||
|
||||
# This if / else block is only for determine the LogPath
|
||||
IF ((!$LogPath) -or ($LogPath -eq $PSScriptRoot+"\Logs")) {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info - Write-LogFile: LogPath is currently not set!"
|
||||
[Array]$LogPaths = $LogPaths
|
||||
[Array]$LogPaths = ($LogPaths += "$ScriptPath\Logs","$env:temp\Digital Data\$ScriptName\Logs")
|
||||
[int]$Counter1 = 0
|
||||
|
||||
DO {
|
||||
|
||||
#Determine the current Array object
|
||||
[String]$LogPath = [Array]$($LogPaths[$Counter1])
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info - Write-LogFile: Testing LogPath: $LogPath"
|
||||
$PathTest = Test-Path -PathType Container "$LogPath"
|
||||
|
||||
#Check if Path already exists
|
||||
IF ($PathTest -eq $True) {
|
||||
|
||||
Write-Host "DEBUG Info - Write-LogFile: LogPath seems already to exists: $LogPath"
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
#If Path doesnt exist, try to create it!
|
||||
Try {
|
||||
|
||||
Write-Host "DEBUG Info - Write-LogFile: Trying to create LogPath: $LogPath"
|
||||
New-Item -ItemType Directory -Path "$LogPath" -Force -ErrorAction Stop | Out-Null
|
||||
Write-Host "DEBUG Info - Write-LogFile: Trying seems to be successful!"
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Host "DEBUG Info - Write-LogFile: Cannot create LogPath or access denied!"
|
||||
Write-Host $Error
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end else
|
||||
|
||||
#Check again if path exists
|
||||
$PathTest = Test-Path -PathType Container "$LogPath"
|
||||
|
||||
IF ($PathTest -eq $True) {
|
||||
|
||||
Try {
|
||||
|
||||
Write-Host "DEBUG Info - Write-LogFile: Trying to write a TestFile into the LogPath."
|
||||
New-Item -ItemType File -Path "$LogPath\AccessTest.txt" -Force -ErrorAction Stop | Out-Null
|
||||
Add-content "$LogPath\AccessTest.txt" -Value "This is a Test!" -Force -ErrorAction Stop | Out-Null
|
||||
$FileTest = Test-Path -Path "$LogPath\AccessTest.txt" -PathType Leaf -ErrorAction Stop
|
||||
Remove-Item -Path "$LogPath\AccessTest.txt" -Force -ErrorAction Stop | Out-Null
|
||||
Write-Host "DEBUG Info - Write-LogFile: Write Test seems to be successful."
|
||||
Set-Variable -Name LogPath -Value $LogPath -Scope Global -Force
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Host "DEBUG Info - Write-LogFile: Cannot write into LogPath or access denied!"
|
||||
Write-Host $Error
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Write-LogFile: Cannot create LogPath or access denied!"
|
||||
Write-Host $Error
|
||||
|
||||
} #end else
|
||||
|
||||
[int]$Counter1++ | Out-Null
|
||||
|
||||
} #end do
|
||||
|
||||
UNTIL ((($PathTest -eq $True) -and ($FileTest -eq $True)) -or ($Counter1 -eq $($LogPaths.count)) )
|
||||
|
||||
} #end if
|
||||
|
||||
ELSEIF ($LogPath) {
|
||||
|
||||
#Write-Host "DEBUG Info - Write-LogFile: LogPath was already been set!"
|
||||
#Write-Host "DEBUG Info - Write-LogFile: LogPath is $LogPath"
|
||||
|
||||
} #end elseif
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host "Unexpected Error!"
|
||||
Write-Host $Error
|
||||
Return $False
|
||||
|
||||
} #end else
|
||||
|
||||
IF ($LogPath) {
|
||||
|
||||
#After LogPath determination - try to log the string
|
||||
Try {
|
||||
|
||||
Write-Host "$LogLine"
|
||||
Add-content $LogPath\$LogFile -value "$(Get-Date -Format 'dd.MM.yyyy')-$(Get-Date -Format 'HH:mm:ss'): $LogLine" -ErrorAction Stop
|
||||
#Return $True
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Host "DEBUG Info - Write-LogFile: Cannot write to LogFile!"
|
||||
Write-Host "DEBUG Info - Write-LogFile: Exiting, because of this Issue."
|
||||
Write-Host $Error
|
||||
EXIT
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Write-LogFile: Cannot write to LogFile!"
|
||||
Write-Host "DEBUG Info - Write-LogFile: Exiting, because of this Issue."
|
||||
Write-Host $Error
|
||||
EXIT
|
||||
|
||||
} #end else
|
||||
|
||||
} #end function
|
||||
@@ -0,0 +1,51 @@
|
||||
@ECHO OFF
|
||||
REM ----------------------------------------------------------------------------
|
||||
REM Copyright (c) 2024 by Digital Data GmbH
|
||||
REM
|
||||
REM Digital Data GmbH • Ludwig-Rinn-Strasse 16 • D-35452 Heuchelheim
|
||||
REM Tel.: 0641/202360 • E-Mail: info-flow@digitaldata.works
|
||||
REM ----------------------------------------------------------------------------
|
||||
REM Creation Date / Author: 06.01.2024 / MK
|
||||
REM Version Date / Editor: 18.10.2024 / MK
|
||||
REM Version Number: 1.2.1.0
|
||||
|
||||
pushd "%~dp0"
|
||||
|
||||
SET DFSSERVER_PRIMARY=172.24.11.92
|
||||
SET DFSSERVER_SECONDARY=172.24.11.1
|
||||
SET DFSSERVERPATH_PRIMARY=\\DD-VMP09-STO01\DD-VMP09-STO01-A3-ZFS$
|
||||
SET DFSSERVERPATH_SECONDARY=\\DD-STO01\DD-STO01-A2$
|
||||
SET DFSROOTPATH=\\dd-gan.local.digitaldata.works\dd-DFS01
|
||||
|
||||
ping -n 1 %DFSSERVER_PRIMARY% >nul
|
||||
IF %errorlevel% equ 0 (
|
||||
ECHO Der primäre Server %DFSSERVER_PRIMARY%, ist erreichbar!
|
||||
SET DFSSERVERPATH=%DFSSERVERPATH_PRIMARY%
|
||||
GOTO :SetDFS
|
||||
|
||||
) else (
|
||||
ECHO Der primäre Server %DFSSERVER_PRIMARY%, ist nicht erreichbar!
|
||||
SET DFSSERVERPATH=%DFSSERVERPATH_SECONDARY%
|
||||
SET DFSSERVER=%DFSSERVER_SECONDARY%
|
||||
)
|
||||
|
||||
ping -n 1 %DFSSERVER_SECONDARY% >nul
|
||||
IF %errorlevel% equ 0 (
|
||||
ECHO Der sekundäre Server %DFSSERVER_SECONDARY%, ist erreichbar!
|
||||
GOTO :SetDFS
|
||||
|
||||
) else (
|
||||
ECHO Der sekundäre Server %DFSSERVER_SECONDARY%, ist nicht erreichbar!
|
||||
ECHO DFS Server kann nicht gesetzt werden!
|
||||
GOTO :EOF
|
||||
)
|
||||
|
||||
:SetDFS
|
||||
dfsutil.exe client property state active %DFSROOTPATH%\ArchivedObjects %DFSSERVERPATH%\ArchivedObjects
|
||||
dfsutil.exe client property state active %DFSROOTPATH%\ServerObjects %DFSSERVERPATH%\ServerObjects
|
||||
dfsutil.exe client property state active %DFSROOTPATH%\SharedObjects %DFSSERVERPATH%\SharedObjects
|
||||
dfsutil.exe client property state active %DFSROOTPATH%\UserObjects %DFSSERVERPATH%\UserObjects
|
||||
|
||||
:EOF
|
||||
timeout /t 10
|
||||
exit
|
||||
Binary file not shown.
@@ -0,0 +1,120 @@
|
||||
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
|
||||
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
|
||||
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
|
||||
|
||||
$folder = $null
|
||||
|
||||
Function Select-FolderDialog
|
||||
{
|
||||
param([string]$Description="Select Folder",[string]$RootFolder="Desktop")
|
||||
|
||||
$objForm = New-Object System.Windows.Forms.FolderBrowserDialog
|
||||
$objForm.Rootfolder = $RootFolder
|
||||
$objForm.Description = $Description
|
||||
$Show = $objForm.ShowDialog()
|
||||
If ($Show -eq "OK")
|
||||
{
|
||||
Return $objForm.SelectedPath
|
||||
}
|
||||
Else
|
||||
{
|
||||
Write-Error "Operation cancelled by user."
|
||||
}
|
||||
}
|
||||
|
||||
# the variable contains user folder selection
|
||||
$folder = Select-FolderDialog -Description "Bitte Pfad angeben!"
|
||||
|
||||
IF ($folder -eq $Null) {
|
||||
|
||||
[System.Windows.Forms.MessageBox]::Show("Vorgang abgerochen. Programm/Script wird geschlossen.")
|
||||
exit
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Get-ItemProperty -Path $folder | Format-list -Property * -Force
|
||||
New-Item -Path $folder -Name Desktop.ini -Itemtype "File" -Force
|
||||
|
||||
$text1 = [Microsoft.VisualBasic.Interaction]::InputBox("Wenn der Ordner im Windows Explorer mit abweichendem Namen angezeigt werden soll, bitte diese Eingabe tätigen!", "Angezeigter Name (LocalizedResourceName)")
|
||||
$text2 = [Microsoft.VisualBasic.Interaction]::InputBox("Wenn beim Mouse-Over über diesen Ordner ein Text erscheien soll, bitte diese Eingabe nun tätigen!", "Infotext zu diesem Ordner - (InfoTip)")
|
||||
$text3 = [Microsoft.VisualBasic.Interaction]::InputBox("Bitte geben Sie Titel ein!", "Titel")
|
||||
$text4 = [Microsoft.VisualBasic.Interaction]::InputBox("Bitte geben Sie Betreff ein!", "Subject")
|
||||
$text5 = [Microsoft.VisualBasic.Interaction]::InputBox("Bitte geben Sie Autor ein!", "Author")
|
||||
#$text6 = [Microsoft.VisualBasic.Interaction]::InputBox("Bitte geben Sie Markierungen ein!", "Tags")
|
||||
|
||||
# Set the size of your form
|
||||
$Form = New-Object System.Windows.Forms.Form
|
||||
$Form.width = 500
|
||||
$Form.height = 300
|
||||
$Form.Text = ”Bitte wählen Sie die Markierungen ein! (Tags)”
|
||||
|
||||
# Set the font of the text to be used within the form
|
||||
$Font = New-Object System.Drawing.Font("Times New Roman",12)
|
||||
$Form.Font = $Font
|
||||
|
||||
# create checkbox1
|
||||
$checkbox1 = new-object System.Windows.Forms.checkbox
|
||||
$checkbox1.Location = new-object System.Drawing.Size(30,30)
|
||||
$checkbox1.Size = new-object System.Drawing.Size(250,50)
|
||||
$checkbox1.Text = "Enable/Disable OK button"
|
||||
$checkbox1.Checked = $true
|
||||
$checkbox1.AutoSize
|
||||
$Form.Controls.Add($checkbox1)
|
||||
|
||||
# create checkbox2
|
||||
$checkbox2 = new-object System.Windows.Forms.checkbox
|
||||
$checkbox2.Location = new-object System.Drawing.Size(30,60)
|
||||
$checkbox2.Size = new-object System.Drawing.Size(250,50)
|
||||
$checkbox2.Text = "Enable/Disable OK button"
|
||||
$checkbox2.Checked = $true
|
||||
$Form.Controls.Add($checkbox2)
|
||||
|
||||
# Add an OK button
|
||||
$OKButton = new-object System.Windows.Forms.Button
|
||||
$OKButton.Location = new-object System.Drawing.Size(130,100)
|
||||
$OKButton.Size = new-object System.Drawing.Size(100,40)
|
||||
$OKButton.Text = "OK"
|
||||
$OKButton.Add_Click({$Form.Close()})
|
||||
$form.Controls.Add($OKButton)
|
||||
|
||||
#Add a cancel button
|
||||
$CancelButton = new-object System.Windows.Forms.Button
|
||||
$CancelButton.Location = new-object System.Drawing.Size(255,100)
|
||||
$CancelButton.Size = new-object System.Drawing.Size(100,40)
|
||||
$CancelButton.Text = "Cancel"
|
||||
$CancelButton.Add_Click({$Form.Close()})
|
||||
$form.Controls.Add($CancelButton)
|
||||
|
||||
########### This is the important piece ##############
|
||||
# #
|
||||
# Do something when the state of the checkbox changes #
|
||||
#######################################################
|
||||
$checkbox1.Add_CheckStateChanged({
|
||||
$OKButton.Enabled = $checkbox1.Checked })
|
||||
|
||||
|
||||
# Activate the form
|
||||
$Form.Add_Shown({$Form.Activate()})
|
||||
[void] $Form.ShowDialog()
|
||||
|
||||
|
||||
$text7 = [Microsoft.VisualBasic.Interaction]::InputBox("Bitte geben Sie Kommentar ein!", "Comment")
|
||||
|
||||
Add-Content $folder\Desktop.ini -Value "[.ShellClassInfo]"
|
||||
Add-Content $folder\Desktop.ini -Value "LocalizedResourceName=$text1"
|
||||
Add-Content $folder\Desktop.ini -Value "InfoTip=$text2"
|
||||
Add-Content $folder\Desktop.ini -Value "[{F29F85E0-4FF9-1068-AB91-08002B27B3D9}]"
|
||||
Add-Content $folder\Desktop.ini -Value "Prop2=31,$text3"
|
||||
Add-Content $folder\Desktop.ini -Value "Prop3=31,$text4"
|
||||
Add-Content $folder\Desktop.ini -Value "Prop4=31,$text5"
|
||||
Add-Content $folder\Desktop.ini -Value "Prop5=31,$text6"
|
||||
Add-Content $folder\Desktop.ini -Value "Prop6=31,$text7"
|
||||
|
||||
attrib +h +s $folder\Desktop.ini
|
||||
attrib +r $folder
|
||||
|
||||
} #end else
|
||||
|
||||
exit
|
||||
@@ -0,0 +1,45 @@
|
||||
@ECHO OFF
|
||||
TITLE DIGITAL DATA - Run all files in directory with current permissions
|
||||
ECHO -
|
||||
ECHO Batch Script
|
||||
ECHO Run all files in directory with current permissions
|
||||
ECHO -
|
||||
ECHO Digital Data
|
||||
ECHO Ludwig-Rinn-Strasse 16
|
||||
ECHO 35452 Heuchelheim
|
||||
ECHO Tel.: 0641 / 202360
|
||||
ECHO E-Mail: info@didalog.de
|
||||
ECHO -
|
||||
ECHO Version 1.0.0.0
|
||||
ECHO Date: 13.08.2015
|
||||
ECHO -
|
||||
ECHO Program Startup %date% at %time:~0,8% oclock, on %computername%.
|
||||
|
||||
REM --------------------------------------------------------------
|
||||
REM ------------------------set variables-------------------------
|
||||
REM --------------------------------------------------------------
|
||||
|
||||
setlocal enableextensions
|
||||
|
||||
SET DIRECTORY="%cd%"
|
||||
SET FILEEXTENSION=*.ps1
|
||||
SET COUNT=0
|
||||
|
||||
REM --------------------------------------------------------------
|
||||
REM ---------------------Program 1 / Script 1---------------------
|
||||
REM --------------------------------------------------------------
|
||||
|
||||
FOR /F "tokens=*" %%f in ('dir /S /b %FILEEXTENSION%') do (ECHO %%f && set /a count+=1)
|
||||
ECHO -
|
||||
ECHO Found %count% File(s) with File Extension %FILEEXTENSION% in Directory:
|
||||
ECHO %DIRECTORY%.
|
||||
|
||||
ECHO -
|
||||
ECHO Running this/them now, with your permissions!
|
||||
FOR /F "tokens=*" %%f in ('dir /S /b %FILEEXTENSION%') do (PowerShell.exe -Command "& {Start-Process PowerShell.exe -WindowStyle hidden '-ExecutionPolicy Bypass -File "%%f"'}")
|
||||
|
||||
ECHO -
|
||||
ECHO This Window will close in:
|
||||
#timeout /T 10
|
||||
endlocal
|
||||
exit
|
||||
@@ -0,0 +1,24 @@
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Version 1.1.0.0 - 18.04.2019
|
||||
NEW: -
|
||||
FIX: -
|
||||
CHG: -
|
||||
REM: -
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Version 1.0.0.0 - 07.03.2016
|
||||
NEW: -
|
||||
FIX: -
|
||||
CHG: -
|
||||
REM: -
|
||||
|
||||
-------------------------------------legend------------------------------------
|
||||
NEW: = Added a new functionality
|
||||
FIX: = Fixed a Issue with existing functionality
|
||||
CHG: = Changed a existing functionality
|
||||
REM: = Removed a functionality
|
||||
-------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,83 @@
|
||||
|
||||
# PowerShell-Skript: Visual Studio-Ausnahmen mit Logging und Fehlerprüfung
|
||||
# Autor: Copilot 🛠️
|
||||
# Datum: $(Get-Date -Format "yyyy-MM-dd")
|
||||
|
||||
# Log-Datei definieren
|
||||
$logPath = "$Env:USERPROFILE\Add-VS-Defender-Ausnahmen.log"
|
||||
|
||||
# Funktion zum Loggen
|
||||
function Write-Log {
|
||||
param (
|
||||
[string]$Message,
|
||||
[string]$Level = "INFO"
|
||||
)
|
||||
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
||||
$entry = "$timestamp [$Level] $Message"
|
||||
Add-Content -Path $logPath -Value $entry
|
||||
Write-Host $entry
|
||||
}
|
||||
|
||||
# Funktion zum Hinzufügen einer Prozess-Ausnahme mit Prüfung
|
||||
function Add-ProcessExclusion {
|
||||
param (
|
||||
[string]$ProcessPath
|
||||
)
|
||||
if (Test-Path $ProcessPath) {
|
||||
try {
|
||||
Add-MpPreference -ExclusionProcess $ProcessPath
|
||||
Write-Log "Prozess-Ausnahme hinzugefügt: $ProcessPath"
|
||||
} catch {
|
||||
Write-Log "Fehler beim Hinzufügen der Ausnahme für: $ProcessPath - $_" "ERROR"
|
||||
}
|
||||
} else {
|
||||
Write-Log "Pfad nicht gefunden: $ProcessPath" "WARNING"
|
||||
}
|
||||
}
|
||||
|
||||
# Funktion zum Hinzufügen einer Pfad-Ausnahme mit Prüfung
|
||||
function Add-PathExclusion {
|
||||
param (
|
||||
[string]$FolderPath
|
||||
)
|
||||
if (Test-Path $FolderPath) {
|
||||
try {
|
||||
Add-MpPreference -ExclusionPath $FolderPath
|
||||
Write-Log "Pfad-Ausnahme hinzugefügt: $FolderPath"
|
||||
} catch {
|
||||
Write-Log "Fehler beim Hinzufügen der Ausnahme für: $FolderPath - $_" "ERROR"
|
||||
}
|
||||
} else {
|
||||
Write-Log "Pfad nicht gefunden: $FolderPath" "WARNING"
|
||||
}
|
||||
}
|
||||
|
||||
# Ausnahmen definieren
|
||||
$processes = @(
|
||||
"D:\ProgramFiles\Microsoft Visual Studio 2022\Common7\IDE\devenv.exe",
|
||||
"D:\ProgramFiles\dotnet\dotnet.exe",
|
||||
"D:\ProgramFiles\Microsoft Visual Studio 2022\MSBuild\Current\Bin\MSBuild.exe",
|
||||
"D:\ProgramFiles\Microsoft Visual Studio 2022\Common7\IDE\Extensions\TestPlatform\vstest.console.exe"
|
||||
)
|
||||
|
||||
$paths = @(
|
||||
"$Env:USERPROFILE\source\repos",
|
||||
"$Env:USERPROFILE\.nuget\packages",
|
||||
"$Env:USERPROFILE\source\repos\*\bin",
|
||||
"$Env:USERPROFILE\source\repos\*\obj"
|
||||
)
|
||||
|
||||
# Ausnahmen hinzufügen
|
||||
Write-Log "=== Start: Hinzufügen von Defender-Ausnahmen für Visual Studio ==="
|
||||
|
||||
foreach ($proc in $processes) {
|
||||
Add-ProcessExclusion -ProcessPath $proc
|
||||
}
|
||||
|
||||
foreach ($path in $paths) {
|
||||
Add-PathExclusion -FolderPath $path
|
||||
}
|
||||
|
||||
Write-Log "=== Ende: Alle Ausnahmen verarbeitet ==="
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
|
||||
# PowerShell-Skript: Visual Studio-Ausnahmen mit Logging und Fehlerprüfung
|
||||
# Autor: Copilot 🛠️
|
||||
# Datum: $(Get-Date -Format "yyyy-MM-dd")
|
||||
|
||||
# Log-Datei definieren
|
||||
$logPath = "$Env:USERPROFILE\Add-VS-Defender-Ausnahmen.log"
|
||||
|
||||
# Funktion zum Loggen
|
||||
function Write-Log {
|
||||
param (
|
||||
[string]$Message,
|
||||
[string]$Level = "INFO"
|
||||
)
|
||||
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
||||
$entry = "$timestamp [$Level] $Message"
|
||||
Add-Content -Path $logPath -Value $entry
|
||||
Write-Host $entry
|
||||
}
|
||||
|
||||
# Funktion zum Hinzufügen einer Prozess-Ausnahme mit Prüfung
|
||||
function Add-ProcessExclusion {
|
||||
param (
|
||||
[string]$ProcessPath
|
||||
)
|
||||
if (Test-Path $ProcessPath) {
|
||||
try {
|
||||
Add-MpPreference -ExclusionProcess $ProcessPath
|
||||
Write-Log "Prozess-Ausnahme hinzugefügt: $ProcessPath"
|
||||
} catch {
|
||||
Write-Log "Fehler beim Hinzufügen der Ausnahme für: $ProcessPath - $_" "ERROR"
|
||||
}
|
||||
} else {
|
||||
Write-Log "Pfad nicht gefunden: $ProcessPath" "WARNING"
|
||||
}
|
||||
}
|
||||
|
||||
# Funktion zum Hinzufügen einer Pfad-Ausnahme mit Prüfung
|
||||
function Add-PathExclusion {
|
||||
param (
|
||||
[string]$FolderPath
|
||||
)
|
||||
if (Test-Path $FolderPath) {
|
||||
try {
|
||||
Add-MpPreference -ExclusionPath $FolderPath
|
||||
Write-Log "Pfad-Ausnahme hinzugefügt: $FolderPath"
|
||||
} catch {
|
||||
Write-Log "Fehler beim Hinzufügen der Ausnahme für: $FolderPath - $_" "ERROR"
|
||||
}
|
||||
} else {
|
||||
Write-Log "Pfad nicht gefunden: $FolderPath" "WARNING"
|
||||
}
|
||||
}
|
||||
|
||||
# Ausnahmen definieren
|
||||
$processes = @(
|
||||
"<Path.exe eintragen wenn ich Prozess nicht gescannt werden soll>",
|
||||
|
||||
)
|
||||
|
||||
$paths = @(
|
||||
"Path eintragen wenn dieser ausgeschlossen werden soll",
|
||||
|
||||
)
|
||||
|
||||
# Ausnahmen hinzufügen
|
||||
Write-Log "=== Start: Hinzufügen von Defender-Ausnahmen für Visual Studio ==="
|
||||
|
||||
foreach ($proc in $processes) {
|
||||
Add-ProcessExclusion -ProcessPath $proc
|
||||
}
|
||||
|
||||
foreach ($path in $paths) {
|
||||
Add-PathExclusion -FolderPath $path
|
||||
}
|
||||
|
||||
Write-Log "=== Ende: Alle Ausnahmen verarbeitet ==="
|
||||
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
####################################################################################################
|
||||
# Digital Data Configuration File (Template Date: 30.07.2016) #
|
||||
# UTF-8 Coding required! #
|
||||
# incl. FailSafe functions that are active when information is missing. #
|
||||
####################################################################################################
|
||||
|
||||
#==================================================================================================#
|
||||
########################################## General Setup ###########################################
|
||||
#==================================================================================================#
|
||||
|
||||
####################################################################################################
|
||||
# Path in which the log files will be stored. #
|
||||
# Example: E:\LogFiles\<ScriptName> #
|
||||
# FailSafe Setting is: <ScriptPath>\Logs #
|
||||
####################################################################################################
|
||||
LogPath =
|
||||
|
||||
####################################################################################################
|
||||
# Numerical value how long (in days) log files will be kept. ValidateRange is 0 - 1000 #
|
||||
# Setting the Value to 0 disables this Function. #
|
||||
# FailSafe Setting is: 60 #
|
||||
####################################################################################################
|
||||
LogFileKeepTime = 30
|
||||
|
||||
#==================================================================================================#
|
||||
########################################## Firefox Setup ###########################################
|
||||
#==================================================================================================#
|
||||
|
||||
####################################################################################################
|
||||
# FirefoxAction #
|
||||
# Set the action to be performed! #
|
||||
# Example: InstallAndUpdate #
|
||||
# Example: UpdateOnly #
|
||||
####################################################################################################
|
||||
FirefoxAction = InstallAndUpdate
|
||||
|
||||
####################################################################################################
|
||||
# FirefoxVersionURL #
|
||||
# Set the URL with the info about current version distibution. #
|
||||
# Result file should be JSON #
|
||||
####################################################################################################
|
||||
FirefoxVersionURL = https://product-details.mozilla.org/1.0/firefox_versions.json
|
||||
|
||||
####################################################################################################
|
||||
# FirefoxDownloadURL #
|
||||
# Set the URL where to download the new software version. #
|
||||
# The URL can be case sensitive! #
|
||||
# Use "%NewVersion%" as placeholder for the new version number, got from the VersionURL. #
|
||||
####################################################################################################
|
||||
FirefoxDownloadURL = https://download-installer.cdn.mozilla.net/pub/firefox/releases/%NewVersion%/win64/de/Firefox%20Setup%20%NewVersion%.msi
|
||||
|
||||
####################################################################################################
|
||||
# FirefoxInstallPath #
|
||||
# Set the local installation path. #
|
||||
####################################################################################################
|
||||
FirefoxInstallPath = D:\ProgramFiles\Mozilla Firefox
|
||||
|
||||
#==================================================================================================#
|
||||
######################################## Thunderbird Setup #########################################
|
||||
#==================================================================================================#
|
||||
|
||||
####################################################################################################
|
||||
# ThunderbirdAction #
|
||||
# Set the action to be performed! #
|
||||
# Example: InstallAndUpdate #
|
||||
# Example: UpdateOnly #
|
||||
####################################################################################################
|
||||
ThunderbirdAction = InstallAndUpdate
|
||||
|
||||
####################################################################################################
|
||||
# ThunderbirdVersionURL #
|
||||
# Set the URL with the info about current version distibution. #
|
||||
# Result file should be JSON #
|
||||
####################################################################################################
|
||||
ThunderbirdVersionURL = https://product-details.mozilla.org/1.0/thunderbird_versions.json
|
||||
|
||||
####################################################################################################
|
||||
# ThunderbirdDownloadURL #
|
||||
# Set the URL where to download the new software version. #
|
||||
# The URL can be case sensitive! #
|
||||
# Use "%NewVersion%" as placeholder for the new version number, got from the VersionURL. #
|
||||
####################################################################################################
|
||||
ThunderbirdDownloadURL = https://download-installer.cdn.mozilla.net/pub/thunderbird/releases/%NewVersion%/win64/de/Thunderbird%20Setup%20%NewVersion%.msi
|
||||
|
||||
####################################################################################################
|
||||
# ThunderbirdInstallPath #
|
||||
# Set the local installation path. #
|
||||
####################################################################################################
|
||||
ThunderbirdInstallPath = D:\ProgramFiles\Mozilla Thunderbird
|
||||
|
||||
####################################################################################################
|
||||
|
||||
# Sources:
|
||||
# https://stackoverflow.com/questions/36480534/is-there-an-api-to-retrieve-latest-versions-of-firefox-release-numbers-for-all-r
|
||||
# https://github.com/ScoopInstaller/Extras/blob/master/bucket/thunderbird.json
|
||||
@@ -0,0 +1,939 @@
|
||||
# Update-MozillaSoftware
|
||||
# ----------------------------------------------------------------------------
|
||||
# This Script installs the newest Firefox and/or Thunderbird versions
|
||||
#
|
||||
# Returns: -
|
||||
# ----------------------------------------------------------------------------
|
||||
# Copyright (c) 2024 by Digital Data GmbH
|
||||
#
|
||||
# Digital Data GmbH • Ludwig-Rinn-Strasse 16 • D-35452 Heuchelheim
|
||||
# Tel.: 0641/202360 • E-Mail: info-flow@digitaldata.works
|
||||
# ----------------------------------------------------------------------------
|
||||
# Creation Date / Author: 04.11.2024 / MK
|
||||
# Version Date / Editor: 13.08.2025 / MK
|
||||
# Version Number: 1.2.0.1
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------#
|
||||
######################################## check for arguments ##########################################
|
||||
#-----------------------------------------------------------------------------------------------------#
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------#
|
||||
################################## add additional buildin assemblys ###################################
|
||||
#-----------------------------------------------------------------------------------------------------#
|
||||
|
||||
#Add-Type -AssemblyName System.Windows.Forms -ErrorAction Stop
|
||||
#Add-Type -AssemblyName PresentationCore -ErrorAction Stop
|
||||
#Add-Type -AssemblyName PresentationFramework -ErrorAction Stop
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------#
|
||||
############################################ set variables ############################################
|
||||
#-----------------------------------------------------------------------------------------------------#
|
||||
|
||||
Set-Variable -Scope Global -Name ScriptName -Value (($MyInvocation.MyCommand.Name) -split "\.")[0].ToString()
|
||||
Set-Variable -Scope Global -Name ScriptPath -Value (Split-Path ($MyInvocation.MyCommand.Path))
|
||||
Set-Variable -Scope Global -Name ConfigFile -Value (Get-ChildItem -Path "$ScriptPath" -Recurse:$false -Filter "$ScriptName`_Settings.ini" -File -Force).FullName | Select-Object -First 1
|
||||
Set-Variable -Scope Global -Name ConfigFileContent -Value $NULL
|
||||
Set-Variable -Scope Global -Name Timestamp1 -Value $(Get-Date -Format 'ddMMyyyy')
|
||||
Set-Variable -Scope Global -Name Timestamp2 -Value $(Get-Date -Format 'ddMMyyyy_HHmmss')
|
||||
Set-Variable -Scope Global -Name Timestamp3 -Value $(Get-Date -Format 'ddMMyyyy_HHmmssffff')
|
||||
Set-Variable -Scope Global -Name Timestamp4 -Value $(Get-Date -Format 'yyyyMMdd HH:mm:ss.fff')
|
||||
Set-Variable -Scope Global -Name LogFile -Value "$ScriptName`_$Timestamp2.log"
|
||||
Set-Variable -Scope Global -Name LogFileKeepTime -Value 60
|
||||
Set-Variable -Scope Global -Name LogPath -Value $NULL
|
||||
Set-Variable -Scope Global -Name Module -Value $NULL
|
||||
Set-Variable -Scope Global -Name Modules -Value ("Read-ConfigFile2","Write-LogFile","Remove-Item-withLogging")
|
||||
Set-Variable -Scope Global -Name ModuleOverrideSourcePath -Value $NULL
|
||||
Set-Variable -Scope Global -Name ModuleDefaultSourcePath -Value "P:\Skriptentwickung\current\Modules"
|
||||
Set-Variable -Scope Global -Name ModuleHKLMRegistryPath -Value "HKLM:\SOFTWARE\Digital Data\Modules"
|
||||
Set-Variable -Scope Global -Name ModuleHKCURegistryPath -Value "HKCU:\SOFTWARE\Digital Data\Modules"
|
||||
|
||||
Set-Variable -Scope Global -Name Firefox -Value $NULL
|
||||
Set-Variable -Scope Global -Name Thunderbird -Value $NULL
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------#
|
||||
############################################ set functions ############################################
|
||||
#-----------------------------------------------------------------------------------------------------#
|
||||
|
||||
Function Import-CustomModule {
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Function will load external - additional - PowerShell Modules into current PSSession.
|
||||
|
||||
.DESCRIPTION
|
||||
By working with Modules, this Function is necessary to load external Modul Functions into the current PowerShell Session.
|
||||
In a productive Enviroment it is recommanded to let this Function set the Registry Key in HKLM for the ModuleSourcePath.
|
||||
In develepment and Test Enviroment it is possible, to work with distributed Folders with different Modules. Therefor the Parameter
|
||||
"ModuleOverrideSourcePath" and the preset Variable "ModuleDefaultSourcePath" are made for.
|
||||
After a successful Import of a Module, Function will Return $True, otherwise a $False.
|
||||
|
||||
.REQUIREMENT General
|
||||
PowerShell V3
|
||||
|
||||
.REQUIREMENT Assembly
|
||||
System.Windows.Forms, PresentationCore, PresentationFramework
|
||||
|
||||
.REQUIREMENT Variables
|
||||
ModuleOverrideSourcePath, ModuleName, Path, Paths, PathTest, FileTest, Result
|
||||
|
||||
.REQUIREMENT Variables preSet
|
||||
ScriptName, ScriptPath, ModuleDefaultSourcePath (optional)
|
||||
|
||||
.REQUIREMENT Functions
|
||||
<NONE>
|
||||
|
||||
.VERSION
|
||||
1.2.0.0 / 09.11.2024
|
||||
|
||||
.PARAMETER ModuleName
|
||||
Give the Module Name, you want to load into the current PSSession (without File-Extension).
|
||||
|
||||
.PARAMETER ModuleOverrideSourcePath
|
||||
Optional Parameter. By giving the ModuleOverrideSourcePath, Function will not check other Paths for the Function you want to load.
|
||||
|
||||
.PARAMETER ModuleFileExtensions
|
||||
Optional Parameter. Give the Module File-Extension (regular: "psm1" or "dll") without a dot ("."), this is just for the checking routine, not the Import itself.')]
|
||||
|
||||
.PARAMETER Force
|
||||
Optional Parameter. By using the Force Parameter, Module will be unload and reload.
|
||||
|
||||
.EXAMPLE
|
||||
Import-CustomModule -ModuleName Write-LogFile -ModuleFileExtensions psm1
|
||||
|
||||
.EXAMPLE
|
||||
Import-CustomModule -ModuleName Write-LogFile -Force
|
||||
|
||||
.EXAMPLE
|
||||
Import-CustomModule -ModuleName Write-LogFile -ModuleFileExtensions psm1 -ModuleOverrideSourcePath D:\ScriptFiles\Modules
|
||||
#>
|
||||
|
||||
Param (
|
||||
|
||||
[Parameter(Position=0,Mandatory=$True,ValueFromPipeline=$True,HelpMessage='Give the ModuleName, you want to load into the current PSSession (without File-Extension)')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$ModuleName,
|
||||
|
||||
[Parameter(Position=1,Mandatory=$False,HelpMessage='Optional Parameter. By giving the ModuleOverrideSourcePath, Function will not check other Paths for the Function you want to load.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$ModuleOverrideSourcePath,
|
||||
|
||||
[Parameter(Position=2,Mandatory=$False,HelpMessage='Optional Parameter. Give the Module File-Extension (regular: "psm1" or "dll") without a dot ("."), this is just for the checking routine, not the Import itself.')]
|
||||
[ValidateSet("psm1","dll")]
|
||||
[Array]$ModuleFileExtensions = @("psm1","dll"),
|
||||
|
||||
[Parameter(Position=3,Mandatory=$False,HelpMessage='Optional Parameter. By using the Force Parameter, Module will be unload and reload.')]
|
||||
[Switch]$Force
|
||||
|
||||
) #end param
|
||||
|
||||
Process {
|
||||
|
||||
#Clear Error Variable
|
||||
$error.clear()
|
||||
|
||||
#Loop for every possible File Extension (eg. psm1 and dll)
|
||||
FOREACH ($ModuleFileExtension in $ModuleFileExtensions) {
|
||||
|
||||
#If FileExtension was given, remove it! Because otherwise "Import-Module" Function will have trouble importing.
|
||||
$ModuleName = $ModuleName -Replace("\.(\w{3}|\w{4})$","")
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info - Import-CustomModule: You want to load Module $ModuleName.$ModuleFileExtension"
|
||||
|
||||
IF ((([String]::IsNullOrWhiteSpace($ScriptName) -ne $True) -and ([String]::IsNullOrEmpty($ScriptName) -ne $True)) -and (([String]::IsNullOrWhiteSpace($ScriptPath) -ne $True) -and ([String]::IsNullOrEmpty($ScriptPath) -ne $True))) {
|
||||
|
||||
#Try this if $ModuleOverrideSourcePath was given by calling the function
|
||||
IF ((([String]::IsNullOrWhiteSpace($ModuleOverrideSourcePath)) -ne $True) -and (([String]::IsNullOrEmpty($ModuleOverrideSourcePath)) -ne $True)) {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Function has been called with 'ModuleOverrideSourcePath' Parameter input!"
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Testing for existence: $ModuleOverrideSourcePath\$ModuleName.$ModuleFileExtension"
|
||||
$FileTest = Test-Path -Path "$ModuleOverrideSourcePath\$ModuleName.$ModuleFileExtension" -PathType Leaf
|
||||
|
||||
IF ($FileTest -eq $True) {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: $ModuleOverrideSourcePath and ModuleName seems to exist."
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Trying to import Module: $ModuleName.$ModuleFileExtension"
|
||||
|
||||
Try {
|
||||
|
||||
$Result = Import-Module $ModuleOverrideSourcePath\$ModuleName -Verbose -DisableNameChecking -Scope Global -Force:$Force -PassThru -ErrorAction SilentlyContinue
|
||||
|
||||
IF ("$Result" -eq "$ModuleName") {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Successfully loaded Module: $ModuleName.$ModuleFileExtension"
|
||||
Return $True
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Error "DEBUG Info - Import-CustomModule: Unsuccessfully loaded Module: $ModuleName.$ModuleFileExtension"
|
||||
Return $False
|
||||
|
||||
} #end if/else
|
||||
|
||||
} Catch {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Error while importing the Module:"
|
||||
Write-Host "DEBUG Info - Import-CustomModule: $ModuleName"
|
||||
Write-Host $Error
|
||||
Return $False
|
||||
|
||||
} #end try/catch
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: ModuleOverrideSourcePath and/or ModuleName seems not to exist."
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Cannot load Module, please check your input!"
|
||||
Return $False
|
||||
|
||||
} #end if/else
|
||||
|
||||
} ELSE { #If $ModuleOverrideSourcePath was not given, try to find a matching folder
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Function has been called without 'ModuleOverrideSourcePath' Parameter input!"
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Trying to find Module Files on some Places of this Computer."
|
||||
|
||||
#Set dynamic Array for locations Modul Path could be, even for some testing.
|
||||
#The first value of the array is just a dummy and will never be used -but keep it for the array value starting with 0!
|
||||
[System.Collections.ArrayList]$Paths = @()
|
||||
Write-Host ""
|
||||
$Paths.Add("$env:systemroot\") | Out-Null
|
||||
|
||||
IF (([String]::IsNullOrEmpty($ModuleDefaultSourcePath)) -or ([String]::IsNullOrWhiteSpace($ModuleDefaultSourcePath))) {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: ModuleDefaultSourcePath was not set! That could be a normal behavior in productive enviroment!"
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Possible Path (1): $ModuleDefaultSourcePath" -ErrorAction SilentlyContinue
|
||||
$Paths.Add("$ModuleDefaultSourcePath") | Out-Null
|
||||
|
||||
} #end if/else
|
||||
|
||||
IF ([String]::IsNullOrEmpty($ScriptPath) -or ([String]::IsNullOrWhiteSpace($ScriptPath))) {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: ScriptPath is invalid! That is terrifying! How could that be???"
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Possible Path (2): $ScriptPath" -ErrorAction SilentlyContinue
|
||||
$Paths.Add("$ScriptPath") | Out-Null
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Possible Path (3): $($ScriptPath+"\Module")" -ErrorAction SilentlyContinue
|
||||
$Paths.Add("$($ScriptPath+"\Module")") | Out-Null
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Possible Path (4): $($ScriptPath+"\Modules")" -ErrorAction SilentlyContinue
|
||||
$Paths.Add("$($ScriptPath+"\Modules")") | Out-Null
|
||||
|
||||
} #end if/else
|
||||
|
||||
IF (([String]::IsNullOrEmpty((Get-Item $ScriptPath).Parent.FullName)) -or ([String]::IsNullOrWhiteSpace((Get-Item $ScriptPath).Parent.FullName))) {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: ScriptPath has no Parent Folders!"
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Possible Path (5): $((Get-Item $ScriptPath).Parent.FullName)" -ErrorAction SilentlyContinue
|
||||
$Paths.Add("$((Get-Item $ScriptPath).Parent.FullName)") | Out-Null
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Possible Path (6): $(((Get-Item $ScriptPath).Parent.FullName)+"\Module")" -ErrorAction SilentlyContinue
|
||||
$Paths.Add("$(((Get-Item $ScriptPath).Parent.FullName)+"\Module")") | Out-Null
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Possible Path (7): $(((Get-Item $ScriptPath).Parent.FullName)+"\Modules")" -ErrorAction SilentlyContinue
|
||||
$Paths.Add("$(((Get-Item $ScriptPath).Parent.FullName)+"\Modules")") | Out-Null
|
||||
|
||||
} #end if/else
|
||||
|
||||
IF (([String]::IsNullOrEmpty($((Get-ItemProperty -Path "$ModuleHKLMRegistryPath" -Name ModuleSourcePath -ErrorAction SilentlyContinue).ModuleSourcePath))) -or ([String]::IsNullOrWhiteSpace($((Get-ItemProperty -Path "$ModuleHKLMRegistryPath" -Name ModuleSourcePath -ErrorAction SilentlyContinue).ModuleSourcePath)))) {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: ModuleSourcePath was not set to Windows Registry (HKLM)!"
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Possible Path (8): $((Get-ItemProperty -Path "$ModuleHKLMRegistryPath" -Name ModuleSourcePath -ErrorAction SilentlyContinue).ModuleSourcePath)" -ErrorAction SilentlyContinue
|
||||
$Paths.Add("$((Get-ItemProperty -Path "$ModuleHKLMRegistryPath" -Name ModuleSourcePath -ErrorAction SilentlyContinue).ModuleSourcePath)") | Out-Null
|
||||
|
||||
} #end if/else
|
||||
|
||||
IF (([String]::IsNullOrEmpty($((Get-ItemProperty -Path "$ModuleHKCURegistryPath" -Name ModuleSourcePath -ErrorAction SilentlyContinue).ModuleSourcePath))) -or ([String]::IsNullOrWhiteSpace($((Get-ItemProperty -Path "$ModuleHKCURegistryPath" -Name ModuleSourcePath -ErrorAction SilentlyContinue).ModuleSourcePath)))) {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: ModuleSourcePath was not set to Windows Registry (HKCU)!"
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Possible Path (8): $((Get-ItemProperty -Path "$ModuleHKCURegistryPath" -Name ModuleSourcePath -ErrorAction SilentlyContinue).ModuleSourcePath)" -ErrorAction SilentlyContinue
|
||||
$Paths.Add("$((Get-ItemProperty -Path "$ModuleHKCURegistryPath" -Name ModuleSourcePath -ErrorAction SilentlyContinue).ModuleSourcePath)") | Out-Null
|
||||
|
||||
} #end if/else
|
||||
|
||||
[Int]$Counter = 0
|
||||
[String]$ModuleSourcePath = $Null
|
||||
|
||||
#Loop for multiple Pathtests - for each Path, where Module files could be
|
||||
DO {
|
||||
|
||||
$Counter++ | Out-Null
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Testing mutiple Paths ( $Counter of"($($Paths.Count)-1)") for existence, now testing:"
|
||||
Write-Host "DEBUG Info - Import-CustomModule: $($Paths[$Counter])"
|
||||
|
||||
IF ((([String]::IsNullOrWhiteSpace($($Paths[$Counter]))) -ne $True) -and (([String]::IsNullOrEmpty($($Paths[$Counter])) -ne $True))) {
|
||||
|
||||
$PathTest = (Test-Path $($Paths[$Counter]) -ErrorAction SilentlyContinue)
|
||||
|
||||
IF ($PathTest -eq $True) {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Yes, Path seems to exist."
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Lets check, if there are any Module Files, in it."
|
||||
|
||||
$FileTest = Get-ChildItem -Path $($Paths[$Counter]) -Filter *.$ModuleFileExtension
|
||||
|
||||
IF ($($FileTest.count) -gt 0) {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Found $($FileTest.count) $ModuleFileExtension Module Files in Path!"
|
||||
Set-Variable -Name ModuleSourcePath -Value $($Paths[$Counter]) -Scope local
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Found no $ModuleFileExtension Module Files in Path!"
|
||||
|
||||
} #end if/else
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: No, Path seems not to exist."
|
||||
|
||||
} #end if/else
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Path seems to be invalid!"
|
||||
|
||||
} #end if/else
|
||||
|
||||
} #end do
|
||||
|
||||
UNTIL ($Counter -ge ($($Paths.Count)-1) -or ($ModuleSourcePath -eq $($Paths[$Counter])))
|
||||
|
||||
IF ($ModuleSourcePath -eq $($Paths[$Counter])) {
|
||||
|
||||
$FileTest = (Test-Path -Path $ModuleSourcePath\$ModuleName.$ModuleFileExtension -PathType Leaf -ErrorAction SilentlyContinue)
|
||||
|
||||
IF ($FileTest -eq $True) {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Trying to import Module: $ModuleName.$ModuleFileExtension"
|
||||
|
||||
Try {
|
||||
|
||||
$Result = Import-Module $ModuleSourcePath\$ModuleName -Verbose -DisableNameChecking -Scope Global -Force:$Force -PassThru -ErrorAction SilentlyContinue
|
||||
|
||||
IF ("$Result" -eq "$ModuleName") {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Successfully loaded Module: $ModuleName.$ModuleFileExtension"
|
||||
Set-Variable -Name ModuleDefaultSourcePath -Value $ModuleSourcePath -Scope Global
|
||||
Return $True
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Error "DEBUG Info - Import-CustomModule: Unsuccessfully loaded Module: $ModuleName.$ModuleFileExtension"
|
||||
Return $False
|
||||
|
||||
} #end if/else
|
||||
|
||||
} Catch {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Loading Module: $ModuleName went wrong."
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Exiting Script, because of this error!"
|
||||
Write-Host $Error
|
||||
Return $False
|
||||
exit
|
||||
|
||||
} #end try/catch
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Module does not exist!"
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Skipping: $ModuleName.$ModuleFileExtension"
|
||||
|
||||
} #end if/else
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Cant locate Module Files automaticlly!"
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Please select Folder in Dialog."
|
||||
|
||||
#Prepare Folder Browser Dialog, to choose the Directory with the .psm1 Files.
|
||||
$FolderBrowserDialog = New-Object System.Windows.Forms.FolderBrowserDialog
|
||||
$FolderBrowserDialog.Rootfolder = "Desktop"
|
||||
$FolderBrowserDialog.Description = "Please, choose the Folder, where the Module ""$ModuleName.$ModuleFileExtension"" is stored."
|
||||
$FolderBrowserDialog.SelectedPath = "$ScriptPath"
|
||||
$FolderBrowserDialog.ShowNewFolderButton = $True
|
||||
|
||||
DO {
|
||||
|
||||
#Now show the Folder Browser, if neccessary in a loop
|
||||
$FolderBrowserDialogShow = $FolderBrowserDialog.ShowDialog()
|
||||
|
||||
#By pressing the OK Button..
|
||||
If ($FolderBrowserDialogShow -eq "OK") {
|
||||
|
||||
#Save selected folder path in the variable
|
||||
$ModuleSourcePath = ($FolderBrowserDialog.SelectedPath)
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info - Import-CustomModule: You choose: $ModuleSourcePath"
|
||||
Write-Host "DEBUG Info - Import-CustomModule: ...testing, if Module ""$ModuleName.$ModuleFileExtension"" can be found there."
|
||||
|
||||
$FileTest = (Test-Path $ModuleSourcePath\$ModuleName.$ModuleFileExtension -PathType Leaf -ErrorAction SilentlyContinue)
|
||||
|
||||
IF ($FileTest -eq $True) {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Module seems to exist, in the selected Folder."
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Now trying to load Module: $ModuleName.$ModuleFileExtension"
|
||||
|
||||
Try {
|
||||
|
||||
$Result = Import-Module $ModuleSourcePath\$ModuleName -Verbose -DisableNameChecking -Scope Global -Force:$Force -PassThru -ErrorAction SilentlyContinue
|
||||
|
||||
IF ("$Result" -eq "$ModuleName") {
|
||||
|
||||
Set-Variable -Name ModuleDefaultSourcePath -Value $ModuleSourcePath -Scope Global
|
||||
|
||||
$MessageBoxBody = "Module: $ModuleName.$ModuleFileExtension - successsfully loaded into current PSSession!"
|
||||
$MessageBoxTitle = "ScriptName: $ScriptName - Module/Section: Import-CustomModule"
|
||||
$MessageBoxButtonType = "OK"
|
||||
$MessageBoxIcon = "Information"
|
||||
$MessageBox = [Windows.Forms.MessageBox]::Show($MessageBoxBody,$MessageBoxTitle,$MessageBoxButtonType,$MessageBoxIcon) | Out-Null
|
||||
|
||||
#Set new default path for next foreach loop
|
||||
Set-Variable -Name ModuleDefaultSourcePath -Value $ModuleSourcePath -Scope Global
|
||||
Set-Variable -Name ModuleOverrideSourcePath -Value $ModuleSourcePath -Scope Global
|
||||
Set-Variable -Name ModuleSourcePath -Value $ModuleSourcePath -Scope Global
|
||||
|
||||
} ELSE {
|
||||
|
||||
$MessageBoxBody = "Module: $ModuleName.$ModuleFileExtension - cannot load into current PSSession!"
|
||||
$MessageBoxTitle = "ScriptName: $ScriptName - Module/Section: Import-CustomModule"
|
||||
$MessageBoxButtonType = "OK"
|
||||
$MessageBoxIcon = "Warning"
|
||||
$MessageBox = [Windows.Forms.MessageBox]::Show($MessageBoxBody,$MessageBoxTitle,$MessageBoxButtonType,$MessageBoxIcon) | Out-Null
|
||||
|
||||
} #end If/else
|
||||
|
||||
} Catch {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Loading Module: $ModuleName.$ModuleFileExtension went wrong."
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Exiting Script, because of this error!"
|
||||
Write-Host $Error
|
||||
exit
|
||||
|
||||
} #end try/catch
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Module seems not to exist, in the selected Folder."
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Please, select another one! ...this Time the right!"
|
||||
|
||||
$MessageBoxBody = "Module seems not to exist, in the selected Folder! Please, select another one!"
|
||||
$MessageBoxTitle = "ScriptName: $ScriptName - Module/Section: Import-CustomModule"
|
||||
$MessageBoxButtonType = "OK"
|
||||
$MessageBoxIcon = "Warning"
|
||||
$MessageBox = [Windows.Forms.MessageBox]::Show($MessageBoxBody,$MessageBoxTitle,$MessageBoxButtonType,$MessageBoxIcon) | Out-Null
|
||||
|
||||
} #end if/else
|
||||
|
||||
} ELSE { #If you didnt pressed the OK Button..
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Operation cancelled by user."
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Exiting Script, because of this!"
|
||||
exit
|
||||
|
||||
} #end if/else
|
||||
|
||||
} #end do
|
||||
|
||||
#Variable "$?" is $True when last operation was ok
|
||||
UNTIL ((($FileTest -eq $True) -and ($? -eq $True)) -or ($FolderBrowserDialogShow -eq "Cancel"))
|
||||
|
||||
IF (([String]::IsNullOrWhiteSpace($ModuleSourcePath) -ne $True) -and ([String]::IsNullOrEmpty($ModuleSourcePath) -ne $True)) {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Should ModuleSourcePath written to Windows Registry?"
|
||||
|
||||
$MessageBoxBody = "Would you like to save the ModulePath to the Windows Registry?"
|
||||
$MessageBoxTitle = "ScriptName: $ScriptName - Module/Section: Import-CustomModule"
|
||||
$MessageBoxButtonType = "YesNo"
|
||||
$MessageBoxIcon = "Question"
|
||||
$MessageBox = [Windows.Forms.MessageBox]::Show($MessageBoxBody,$MessageBoxTitle,$MessageBoxButtonType,$MessageBoxIcon)
|
||||
|
||||
IF ($MessageBox -eq 'Yes') {
|
||||
|
||||
$PathTest = (Test-Path -Path "$ModuleHKLMRegistryPath" -ErrorAction SilentlyContinue)
|
||||
$MessageBox = $NULL
|
||||
|
||||
IF ($PathTest -eq $False) {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Registry Key seems not to exist."
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Trying to write ModuleSourcepath to HKLM."
|
||||
|
||||
Try {
|
||||
|
||||
New-Item -Path "$ModuleHKLMRegistryPath" -Force -ErrorAction Stop | Out-Null
|
||||
New-ItemProperty -Path "$ModuleHKLMRegistryPath" -Name ModuleSourcePath -Value $ModuleSourcePath -ErrorAction Stop | Out-Null
|
||||
|
||||
} Catch {
|
||||
|
||||
Write-Host $Error
|
||||
$MessageBoxBody = "Could not save ModuleSourcePath to Windows Registry! Check your access rights! To bypass this issue you can write the ModuleSourcePath to User Registry (HKCU). Would you?"
|
||||
$MessageBoxTitle = "ScriptName: $ScriptName - Module/Section: Import-CustomModule"
|
||||
$MessageBoxButtonType = "YesNo"
|
||||
$MessageBoxIcon = "Question"
|
||||
$MessageBox = [Windows.Forms.MessageBox]::Show($MessageBoxBody,$MessageBoxTitle,$MessageBoxButtonType,$MessageBoxIcon)
|
||||
|
||||
} #end try/catch
|
||||
|
||||
} ELSEIF ($PathTest -eq $True) {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Registry Key seems to exist."
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Trying to write ModuleSourcepath to HKLM."
|
||||
|
||||
Try {
|
||||
|
||||
Set-ItemProperty -Path "$ModuleHKLMRegistryPath" -Name ModuleSourcePath -Value $ModuleSourcePath -ErrorAction Stop | Out-Null
|
||||
|
||||
} Catch {
|
||||
|
||||
Write-Host $Error
|
||||
$MessageBoxBody = "Could not save ModuleSourcePath to Windows Registry! Check your access rights! To Bypass Error: Write ModuleSource Path to User Registry (HKCU)?"
|
||||
$MessageBoxTitle = "ScriptName: $ScriptName - Module/Section: Import-CustomModule"
|
||||
$MessageBoxButtonType = "YesNo"
|
||||
$MessageBoxIcon = "Question"
|
||||
$MessageBox = [Windows.Forms.MessageBox]::Show($MessageBoxBody,$MessageBoxTitle,$MessageBoxButtonType,$MessageBoxIcon)
|
||||
|
||||
} #end try/catch
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Something went wrong, by getting the ModuleSourcePath!"
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Exiting Script, because of this!"
|
||||
exit
|
||||
|
||||
} #end if/elseif/else
|
||||
|
||||
#Block for trying to write the ModuleSourcePath to the User Registry, if System Registry failed.
|
||||
IF ($MessageBox -eq 'Yes') {
|
||||
|
||||
$PathTest = (Test-Path -Path "$ModuleHKCURegistryPath" -ErrorAction SilentlyContinue)
|
||||
$MessageBox = $NULL
|
||||
|
||||
IF ($PathTest -eq $False) {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Registry Key seems not to exist."
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Trying to write ModuleSourcepath to HKCU."
|
||||
|
||||
Try {
|
||||
|
||||
New-Item -Path "$ModuleHKCURegistryPath" -Force -ErrorAction Stop | Out-Null
|
||||
New-ItemProperty -Path "$ModuleHKCURegistryPath" -Name ModuleSourcePath -Value $ModuleSourcePath -ErrorAction Stop | Out-Null
|
||||
|
||||
} Catch {
|
||||
|
||||
Write-Host $Error
|
||||
$MessageBoxBody = "Could not save ModuleSourcePath to Windows Registry! Not even to User Registry! Check your access rights! Exiting now.."
|
||||
$MessageBoxTitle = "ScriptName: $ScriptName - Module/Section: Import-CustomModule"
|
||||
$MessageBoxButtonType = "OK"
|
||||
$MessageBoxIcon = "Warning"
|
||||
$MessageBox = [Windows.Forms.MessageBox]::Show($MessageBoxBody,$MessageBoxTitle,$MessageBoxButtonType,$MessageBoxIcon)
|
||||
exit
|
||||
|
||||
} #end try/catch
|
||||
|
||||
} ELSEIF ($PathTest -eq $True) {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Registry Key seems to exist."
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Trying to write ModuleSourcepath to HKCU."
|
||||
|
||||
Try {
|
||||
|
||||
Set-ItemProperty -Path "$ModuleHKCURegistryPath" -Name ModuleSourcePath -Value $ModuleSourcePath -ErrorAction Stop | Out-Null
|
||||
|
||||
} Catch {
|
||||
|
||||
Write-Host $Error
|
||||
$MessageBoxBody = "Could not save ModuleSourcePath to Windows Registry! Not even to User Registry! Check your access rights! Exiting now.."
|
||||
$MessageBoxTitle = "ScriptName: $ScriptName - Module/Section: Import-CustomModule"
|
||||
$MessageBoxButtonType = "OK"
|
||||
$MessageBoxIcon = "Warning"
|
||||
$MessageBox = [Windows.Forms.MessageBox]::Show($MessageBoxBody,$MessageBoxTitle,$MessageBoxButtonType,$MessageBoxIcon)
|
||||
exit
|
||||
|
||||
} #end try/catch
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Something went wrong, by getting the ModuleSourcePath!"
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Exiting Script, because of this!"
|
||||
exit
|
||||
|
||||
} #end if/elseif/else
|
||||
|
||||
} #end if
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: You choose, not to save the ModuleSourcePath to the Windows Registry!"
|
||||
|
||||
$MessageBoxBody = "You choose, not to save the ModuleSourcePath to the Windows Registry!"
|
||||
$MessageBoxTitle = "ScriptName: $ScriptName - Module/Section: Import-CustomModule"
|
||||
$MessageBoxButtonType = "OK"
|
||||
$MessageBoxIcon = "Warning"
|
||||
$MessageBox = [Windows.Forms.MessageBox]::Show($MessageBoxBody,$MessageBoxTitle,$MessageBoxButtonType,$MessageBoxIcon)
|
||||
|
||||
} #end if/else
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Something went wrong, by getting the ModuleSourcePath!"
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Exiting Script, because of this!"
|
||||
exit
|
||||
|
||||
} #end if/else
|
||||
|
||||
} #end if/else
|
||||
|
||||
} #end if/ else
|
||||
|
||||
} ELSE {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Required Variables (ScriptName and ScriptPath) were not set!"
|
||||
Write-Host "DEBUG Info - Import-CustomModule: Module Import is unvailable without this Variables!"
|
||||
|
||||
} #end if/else
|
||||
|
||||
} #end foreach
|
||||
|
||||
} #end process
|
||||
|
||||
} #end function
|
||||
|
||||
Function Get-CurrentVersion {
|
||||
Param ($MozillaSoftware)
|
||||
|
||||
# Check if MozillaSoftware parameter is provided
|
||||
If (-not $MozillaSoftware) {
|
||||
Write-Logfile -LogLine "No Mozilla software specified!"
|
||||
Return [Version]::0
|
||||
}
|
||||
|
||||
Try {
|
||||
$CurrentMozillaSoftwareVersionRegPath = "HKLM:\SOFTWARE\Mozilla\Mozilla $MozillaSoftware"
|
||||
Write-Logfile -LogLine "Checking registry path: $CurrentMozillaSoftwareVersionRegPath"
|
||||
|
||||
# Check if the registry path exists
|
||||
If (Test-Path -Path $CurrentMozillaSoftwareVersionRegPath) {
|
||||
$CurrentMozillaSoftwareVersion = (Get-ItemProperty -Path $CurrentMozillaSoftwareVersionRegPath -Name "(default)" -ErrorAction Stop)."(default)"
|
||||
Write-Logfile -LogLine "Currently installed $MozillaSoftware Version: $CurrentMozillaSoftwareVersion"
|
||||
Return [Version]$CurrentMozillaSoftwareVersion
|
||||
} Else {
|
||||
Write-Logfile -LogLine "Registry path for $MozillaSoftware not found!"
|
||||
Return [Version]::0
|
||||
}
|
||||
} Catch {
|
||||
Write-Logfile -LogLine "Error retrieving version for $MozillaSoftware`: $_"
|
||||
Return [Version]::0
|
||||
}
|
||||
} #end function
|
||||
|
||||
Function Get-NewVersion {
|
||||
Param ($MozillaSoftware, $VersionURL)
|
||||
|
||||
Try {
|
||||
|
||||
$WebRequestResult = Invoke-WebRequest -Uri $VersionURL -ErrorAction Stop
|
||||
If ($WebRequestResult.StatusCode -eq "200") {
|
||||
Write-Logfile -LogLine "Connection to server established!"
|
||||
|
||||
$RestMethodResult = Invoke-RestMethod -Uri $VersionURL -ErrorAction Stop
|
||||
Write-Logfile -LogLine "Software Version on server retrived!"
|
||||
$VersionAttribut = "LATEST_$MozillaSoftware`_VERSION"
|
||||
|
||||
IF ($($RestMethodResult.$VersionAttribut) -gt "0" ) {
|
||||
[version]$NewVersion = $($RestMethodResult.$VersionAttribut)
|
||||
Write-Logfile -LogLine "Latest Version: $NewVersion"
|
||||
Return $NewVersion.ToString()
|
||||
} else {
|
||||
Write-Logfile -LogLine "Could not find the $MozillaSoftware version number from JSON interface."
|
||||
Return 0
|
||||
} #end if/else
|
||||
|
||||
} Else {
|
||||
Write-Logfile -LogLine "Connection to server failed!"
|
||||
Write-Logfile -LogLine "StatusCode: $($WebRequestResult.StatusCode)"
|
||||
Write-Logfile -LogLine "StatusDescription: $($WebRequestResult.StatusDescription)"
|
||||
Return 0
|
||||
} #end if/else
|
||||
|
||||
} Catch {
|
||||
Write-Logfile -LogLine "Error while getting the new software version from the server!"
|
||||
Write-Logfile -LogLine $Error[0].ToString()
|
||||
Return 0
|
||||
} #end try/catch
|
||||
|
||||
} #end function
|
||||
|
||||
Function Install-NewVersion {
|
||||
Param ($MozillaSoftware, $NewVersion, $DownloadURL, $InstallPath)
|
||||
|
||||
Try {
|
||||
# Define the URL for the latest installer
|
||||
$NewVersionURL = $DownloadURL -replace("%NewVersion%",$NewVersion)
|
||||
$NewVersionSetup = "$env:TEMP\$MozillaSoftware$NewVersion.msi"
|
||||
|
||||
# Use Invoke-WebRequest to download the installer
|
||||
Write-Logfile -LogLine "Downloading $MozillaSoftware Version $NewVersion from: "
|
||||
Write-Logfile -LogLine $NewVersionURL
|
||||
Invoke-WebRequest -Uri $NewVersionURL -OutFile $NewVersionSetup -ErrorAction Stop
|
||||
|
||||
IF (Test-Path -Path $NewVersionSetup -PathType Leaf -ErrorAction SilentlyContinue) {
|
||||
|
||||
$MozillaSoftwareProcess = Get-Process -Name $MozillaSoftware -ErrorAction SilentlyContinue
|
||||
If ($MozillaSoftwareProcess) {Stop-Process -Name $MozillaSoftware -Force -ErrorAction Stop}
|
||||
|
||||
Write-Logfile -LogLine "Installing $MozillaSoftware Version $NewVersion, please wait..."
|
||||
$ArgumentList = "/i $NewVersionSetup INSTALL_DIRECTORY_PATH=""$InstallPath"" /quiet"
|
||||
Start-Process -Verb runAs -FilePath "msiexec.exe" -ArgumentList $ArgumentList -Wait -ErrorAction Stop
|
||||
Write-Logfile -LogLine "Install or Update is completed!"
|
||||
|
||||
} Else {
|
||||
Write-Logfile -LogLine "Cannot find setup file!"
|
||||
} #end if/else
|
||||
|
||||
} Catch {
|
||||
Write-Logfile -LogLine "ERROR!"
|
||||
Write-Logfile -LogLine $Error[0].ToString()
|
||||
|
||||
} Finally {
|
||||
Write-Logfile -LogLine "Cleaning Up!"
|
||||
Remove-Item "$env:TEMP\$MozillaSoftware$NewVersion.msi" -Force -ErrorAction SilentlyContinue
|
||||
|
||||
} #end try/catch/finally
|
||||
|
||||
} #end function
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------#
|
||||
########################################### preparing part ############################################
|
||||
#-----------------------------------------------------------------------------------------------------#
|
||||
|
||||
#Clear Console Content
|
||||
#Clear-Host
|
||||
|
||||
#Load external Modules - use Force ( -Force) Parameter, to reload in every run
|
||||
FOREACH ($Module in $Modules) {
|
||||
|
||||
$Result = Import-CustomModule -ModuleName $Module -Force
|
||||
|
||||
IF ($Result -eq $False) {
|
||||
|
||||
Write-Host "DEBUG Info: Module: $Module was not successful been loaded!"
|
||||
Write-Host "DEBUG Info: Please load the Module and try again, running this Function/Module!"
|
||||
Write-Host "DEBUG Info: Exiting, because of this Issue."
|
||||
Write-Host $Error
|
||||
EXIT
|
||||
|
||||
} #end if
|
||||
|
||||
} #end foreach
|
||||
|
||||
#Read ConfigFile and load its content into a Object
|
||||
[OBJECT]$ConfigFileContent = Read-ConfigFile2 -ConfigFile $ConfigFile
|
||||
|
||||
#Allocate Variable Values, depending on the read ConfigFile
|
||||
[ARRAY]$LogPaths = $ConfigFileContent."LogPath_$($ConfigFileContent.LogPath[0])"
|
||||
[STRING]$LogFileKeepTime = $ConfigFileContent."LogFileKeepTime_$($ConfigFileContent.LogFileKeepTime[0])"
|
||||
|
||||
Try {
|
||||
[OBJECT]$Firefox = New-Object PSObject -ErrorAction Stop
|
||||
Add-Member -InputObject $Firefox -MemberType NoteProperty -Name ProductName -Value "Firefox" -ErrorAction Stop
|
||||
Add-Member -InputObject $Firefox -MemberType NoteProperty -Name Action -Value $ConfigFileContent."FirefoxAction_$($ConfigFileContent.FirefoxAction[0])" -ErrorAction Stop
|
||||
Add-Member -InputObject $Firefox -MemberType NoteProperty -Name VersionURL -Value $ConfigFileContent."FirefoxVersionURL_$($ConfigFileContent.FirefoxVersionURL[0])" -ErrorAction Stop
|
||||
Add-Member -InputObject $Firefox -MemberType NoteProperty -Name DownloadURL -Value $ConfigFileContent."FirefoxDownloadURL_$($ConfigFileContent.FirefoxDownloadURL[0])" -ErrorAction Stop
|
||||
Add-Member -InputObject $Firefox -MemberType NoteProperty -Name InstallPath -Value $ConfigFileContent."FirefoxInstallPath_$($ConfigFileContent.FirefoxInstallPath[0])" -ErrorAction Stop
|
||||
Add-Member -InputObject $Firefox -MemberType NoteProperty -Name CurrentVersion -Value 0 -ErrorAction Stop
|
||||
Add-Member -InputObject $Firefox -MemberType NoteProperty -Name NewVersion -Value 0 -ErrorAction Stop
|
||||
|
||||
} Catch {
|
||||
Write-Logfile -LogLine " "
|
||||
Write-Logfile -LogLine "Error creating Object for: Firefox"
|
||||
|
||||
Write-Logfile -LogLine "Property Value is missing or invalid!"
|
||||
} #end try/catch
|
||||
|
||||
Try {
|
||||
[OBJECT]$Thunderbird = New-Object PSObject -ErrorAction Stop
|
||||
Add-Member -InputObject $Thunderbird -MemberType NoteProperty -Name ProductName -Value "Thunderbird" -ErrorAction Stop
|
||||
Add-Member -InputObject $Thunderbird -MemberType NoteProperty -Name Action -Value $ConfigFileContent."ThunderbirdAction_$($ConfigFileContent.ThunderbirdAction[0])" -ErrorAction Stop
|
||||
Add-Member -InputObject $Thunderbird -MemberType NoteProperty -Name VersionURL -Value $ConfigFileContent."ThunderbirdVersionURL_$($ConfigFileContent.ThunderbirdVersionURL[0])" -ErrorAction Stop
|
||||
Add-Member -InputObject $Thunderbird -MemberType NoteProperty -Name DownloadURL -Value $ConfigFileContent."ThunderbirdDownloadURL_$($ConfigFileContent.ThunderbirdDownloadURL[0])" -ErrorAction Stop
|
||||
Add-Member -InputObject $Thunderbird -MemberType NoteProperty -Name InstallPath -Value $ConfigFileContent."ThunderbirdInstallPath_$($ConfigFileContent.ThunderbirdInstallPath[0])" -ErrorAction Stop
|
||||
Add-Member -InputObject $Thunderbird -MemberType NoteProperty -Name CurrentVersion -Value 0 -ErrorAction Stop
|
||||
Add-Member -InputObject $Thunderbird -MemberType NoteProperty -Name NewVersion -Value 0 -ErrorAction Stop
|
||||
|
||||
} Catch {
|
||||
Write-Logfile -LogLine " "
|
||||
Write-Logfile -LogLine "Error creating Object for: Thunderbird"
|
||||
Write-Logfile -LogLine "Property Value is missing or invalid!"
|
||||
|
||||
} #end try/catch
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------#
|
||||
############################################# main part ###############################################
|
||||
#-----------------------------------------------------------------------------------------------------#
|
||||
|
||||
#Clear Error Variable
|
||||
$Error.Clear() | Out-Null
|
||||
|
||||
#Clear Console Output
|
||||
#Clear-Host
|
||||
|
||||
Write-Host " "
|
||||
Write-Logfile -LogLine "********************************************************************************"
|
||||
Write-Logfile -LogLine "Program Startup: $ScriptName on $env:COMPUTERNAME,"
|
||||
Write-Logfile -LogLine "from Account $env:USERDOMAIN\$env:USERNAME."
|
||||
Write-Logfile -LogLine "********************************************************************************"
|
||||
|
||||
Write-Logfile -LogLine " "
|
||||
Write-Logfile -LogLine "Starting with $($Firefox.ProductName) ..."
|
||||
IF (($Firefox.Action) -and ($Firefox.VersionURL) -and ($Firefox.DownloadURL) -and ($Firefox.InstallPath)) {
|
||||
Write-Logfile -LogLine "All required Variables are set for this Step."
|
||||
Write-Logfile -LogLine "Action: $($Firefox.Action)"
|
||||
Write-Logfile -LogLine "VersionURL: $($Firefox.VersionURL)"
|
||||
Write-Logfile -LogLine "DownloadURL: $($Firefox.DownloadURL)"
|
||||
Write-Logfile -LogLine "InstallPath: $($Firefox.InstallPath)"
|
||||
Write-Logfile -LogLine " "
|
||||
|
||||
$Firefox.CurrentVersion = Get-CurrentVersion -MozillaSoftware $Firefox.ProductName
|
||||
$Firefox.NewVersion = Get-NewVersion -MozillaSoftware $Firefox.ProductName -VersionURL $Firefox.VersionURL[0]
|
||||
|
||||
If ([Version]$Firefox.NewVersion -gt [Version]$Firefox.CurrentVersion) {
|
||||
|
||||
IF ($Firefox.Action -match "InstallAndUpdate") {
|
||||
Write-Logfile -LogLine "Install or Update is neccessary!"
|
||||
Install-NewVersion -MozillaSoftware $Firefox.ProductName -NewVersion $Firefox.NewVersion -DownloadURL $Firefox.DownloadURL[0] -InstallPath $Firefox.InstallPath[0]
|
||||
Get-CurrentVersion -MozillaSoftware $Firefox.ProductName | Out-Null
|
||||
|
||||
} ElseIf (($Firefox.Action -match "UpdateOnly") -and ([Version]$Firefox.CurrentVersion -gt 0)) {
|
||||
Write-Logfile -LogLine "Update is neccessary!"
|
||||
Install-NewVersion -MozillaSoftware $Firefox.ProductName -NewVersion $Firefox.NewVersion -DownloadURL $Firefox.DownloadURL[0] -InstallPath $Firefox.InstallPath[0]
|
||||
Get-CurrentVersion -MozillaSoftware $Firefox.ProductName | Out-Null
|
||||
|
||||
} ElseIf (($Firefox.Action -match "UpdateOnly") -and (([Version]$Firefox.CurrentVersion -eq $NULL) -or ([Version]$Firefox.CurrentVersion -eq 0))) {
|
||||
Write-Logfile -LogLine "Skipping Update because of non exisitng installation and config!"
|
||||
|
||||
} Else {
|
||||
Write-Logfile -LogLine "Unknown config!"
|
||||
|
||||
} #end if/elseif/else
|
||||
|
||||
} Else {
|
||||
Write-Logfile -LogLine "No Install or Update is neccessary!"
|
||||
} #end if/else
|
||||
|
||||
} Else {
|
||||
Write-Logfile -LogLine "Not all required Variables are set for this Step."
|
||||
|
||||
} #end if/else
|
||||
|
||||
Write-Logfile -LogLine "--------------------------------------------------------------------------------"
|
||||
|
||||
Write-Logfile -LogLine " "
|
||||
Write-Logfile -LogLine "Continue with $($Thunderbird.ProductName) ..."
|
||||
IF (($Thunderbird.Action) -and ($Thunderbird.VersionURL) -and ($Thunderbird.DownloadURL) -and ($Thunderbird.InstallPath)) {
|
||||
Write-Logfile -LogLine "All required Variables are set for this Step."
|
||||
Write-Logfile -LogLine "Action: $($Thunderbird.Action)"
|
||||
Write-Logfile -LogLine "VersionURL: $($Thunderbird.VersionURL)"
|
||||
Write-Logfile -LogLine "DownloadURL: $($Thunderbird.DownloadURL)"
|
||||
Write-Logfile -LogLine "InstallPath: $($Thunderbird.InstallPath)"
|
||||
Write-Logfile -LogLine " "
|
||||
|
||||
$Thunderbird.CurrentVersion = Get-CurrentVersion -MozillaSoftware $Thunderbird.ProductName
|
||||
$Thunderbird.NewVersion = Get-NewVersion -MozillaSoftware $Thunderbird.ProductName -VersionURL $Thunderbird.VersionURL[0]
|
||||
|
||||
If ([Version]$Thunderbird.NewVersion -gt [Version]$Thunderbird.CurrentVersion) {
|
||||
|
||||
IF ($Thunderbird.Action -match "InstallAndUpdate") {
|
||||
Write-Logfile -LogLine "Install or Update is neccessary!"
|
||||
Install-NewVersion -MozillaSoftware $Thunderbird.ProductName -NewVersion $Thunderbird.NewVersion -DownloadURL $Thunderbird.DownloadURL[0] -InstallPath $Thunderbird.InstallPath[0]
|
||||
Get-CurrentVersion -MozillaSoftware $Thunderbird.ProductName | Out-Null
|
||||
|
||||
} ElseIf (($Thunderbird.Action -match "UpdateOnly") -and ([Version]$Thunderbird.CurrentVersion -gt 0)) {
|
||||
Write-Logfile -LogLine "Update is neccessary!"
|
||||
Install-NewVersion -MozillaSoftware $Thunderbird.ProductName -NewVersion $Thunderbird.NewVersion -DownloadURL $Thunderbird.DownloadURL[0] -InstallPath $Thunderbird.InstallPath[0]
|
||||
Get-CurrentVersion -MozillaSoftware $Thunderbird.ProductName | Out-Null
|
||||
|
||||
} ElseIf (($Thunderbird.Action -match "UpdateOnly") -and (([Version]$Thunderbird.CurrentVersion -eq $NULL) -or ([Version]$Thunderbird.CurrentVersion -eq 0))) {
|
||||
Write-Logfile -LogLine "Skipping Update because of non exisitng installation!"
|
||||
|
||||
} Else {
|
||||
Write-Logfile -LogLine "Unknown config!"
|
||||
|
||||
} #end if/elseif/else
|
||||
|
||||
} Else {
|
||||
Write-Logfile -LogLine "No Install or Update is neccessary!"
|
||||
} #end if/else
|
||||
|
||||
} Else {
|
||||
Write-Logfile -LogLine "Not all required Variables are set for this Step."
|
||||
|
||||
} #end if/else
|
||||
|
||||
Write-Logfile -LogLine " "
|
||||
Write-Logfile -LogLine "--------------------------------------------------------------------------------"
|
||||
Write-Logfile -LogLine "Checking for old LogFiles."
|
||||
Write-Logfile -LogLine "--------------------------------------------------------------------------------"
|
||||
|
||||
Remove-Item-withLogging -Path $LogPath -FileKeepTime $LogFileKeepTime -FileBaseName $ScriptName
|
||||
|
||||
Write-Logfile -LogLine " "
|
||||
Write-Logfile -LogLine "********************************************************************************"
|
||||
Write-Logfile -LogLine "Program Completed: $ScriptName on $env:COMPUTERNAME,"
|
||||
Write-Logfile -LogLine "from Account $env:USERDOMAIN\$env:USERNAME."
|
||||
Write-Logfile -LogLine "********************************************************************************"
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------#
|
||||
########################################### finishing part ############################################
|
||||
#-----------------------------------------------------------------------------------------------------#
|
||||
|
||||
#Enable only for debugging
|
||||
#exit
|
||||
|
||||
Remove-Variable -Name ScriptName -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name ScriptPath -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name ConfigFile -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name ConfigFileContent -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name Timestamp1 -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name Timestamp2 -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name Timestamp3 -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name Timestamp4 -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name LogFile -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name LogFileKeepTime -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name LogPath -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name Module -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name Modules -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name ModuleOverrideSourcePath -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name ModuleDefaultSourcePath -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name ModuleHKLMRegistryPath -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name ModuleHKCURegistryPath -Force -ErrorAction SilentlyContinue
|
||||
|
||||
Remove-Variable -Name Firefox -Force -ErrorAction SilentlyContinue
|
||||
Remove-Variable -Name Thunderbird -Force -ErrorAction SilentlyContinue
|
||||
|
||||
$error.clear()
|
||||
@@ -0,0 +1,131 @@
|
||||
TITLE DIGITAL DATA - Run all files in directory
|
||||
@ECHO OFF
|
||||
REM ----------------------------------------------------------------------------
|
||||
REM This script runs all specified files in the current directory
|
||||
REM
|
||||
REM Returns: <NOTHING>
|
||||
REM ----------------------------------------------------------------------------
|
||||
REM Copyright (c) 2024 by Digital Data GmbH
|
||||
REM
|
||||
REM Digital Data GmbH • Ludwig-Rinn-Strasse 16 • D-35452 Heuchelheim
|
||||
REM Tel.: 0641/202360 • E-Mail: info-flow@digitaldata.works
|
||||
REM ----------------------------------------------------------------------------
|
||||
REM Creation Date / Author: 13.08.2015 / MK
|
||||
REM Version Date / Editor: 12.08.2025 / MK
|
||||
REM Version Number: 2.0.0.1
|
||||
|
||||
pushd "%~dp0"
|
||||
|
||||
REM --------------------------------------------------------------
|
||||
REM ------------------------set variables-------------------------
|
||||
REM --------------------------------------------------------------
|
||||
|
||||
SET /A ADMINMODE=1
|
||||
SET FILEEXTENSION=*.ps1
|
||||
|
||||
SET POWERSHELL7EXE="C:\Program Files\PowerShell\7\pwsh.exe"
|
||||
SET POWERSHELL6EXE="C:\Program Files\PowerShell\6\pwsh.exe"
|
||||
SET POWERSHELLBUILDINEXE="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
|
||||
|
||||
SET DIRECTORY="%cd%"
|
||||
SET /A COUNT=0
|
||||
SET LOGFILE="%cd%\error.log"
|
||||
|
||||
REM --------------------------------------------------------------
|
||||
REM ------------------------preparing part------------------------
|
||||
REM --------------------------------------------------------------
|
||||
|
||||
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
|
||||
ECHO Program Startup %date% at %time:~0,8% o'clock, on %computername%.
|
||||
|
||||
ECHO -
|
||||
IF !ADMINMODE! EQU 1 (ECHO WARNING: In AdminMode, network drives/files will maybe be unavailable! && timeout /T 15)
|
||||
|
||||
ECHO -
|
||||
ECHO Searching for PowerShell 7...
|
||||
IF EXIST "!POWERSHELL7EXE!" (
|
||||
ECHO Found PowerShell 7 on this system.
|
||||
SET POWERSHELLEXE=!POWERSHELL7EXE!
|
||||
) ELSE (
|
||||
ECHO WARNING: Did not found PowerShell 7 on this system
|
||||
ECHO This could lead to malfunctions. Check the ..._Readme.txt file
|
||||
timeout /T 15
|
||||
ECHO Searching for PowerShell 6...
|
||||
IF EXIST "!POWERSHELL6EXE!" (
|
||||
ECHO Found PowerShell 6 on this system.
|
||||
SET POWERSHELLEXE=!POWERSHELL6EXE!
|
||||
) ELSE (
|
||||
ECHO WARNING: Did not found PowerShell 6 on this system.
|
||||
ECHO This could lead to malfunctions. Check the ..._Readme.txt file.
|
||||
timeout /T 15
|
||||
ECHO Searching for old PowerShell buildin version...
|
||||
IF EXIST "!POWERSHELLBUILDINEXE!" (
|
||||
ECHO Found old PowerShell buildin version on this system.
|
||||
SET POWERSHELLEXE=!POWERSHELLBUILDINEXE!
|
||||
) ELSE (
|
||||
ECHO ERROR: Did not found any PowerShell on this system.
|
||||
ECHO Exiting, because of this issue...
|
||||
timeout /T 15
|
||||
GOTO exit
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
REM --------------------------------------------------------------
|
||||
REM ---------------------Running Scripts---------------------------
|
||||
REM --------------------------------------------------------------
|
||||
|
||||
FOR /F "tokens=*" %%f in ('dir /S /b %FILEEXTENSION%') do (
|
||||
SET /a COUNT+=1
|
||||
)
|
||||
|
||||
ECHO -
|
||||
ECHO Found %COUNT% File(s) with File Extension %FILEEXTENSION% in Directory:
|
||||
ECHO %DIRECTORY%
|
||||
|
||||
ECHO -
|
||||
ECHO Running these scripts now:
|
||||
FOR /F "tokens=*" %%f in ('dir /S /b %FILEEXTENSION%') do (
|
||||
|
||||
ECHO -
|
||||
SET "SCRIPT=%%f"
|
||||
ECHO Running script:
|
||||
ECHO !SCRIPT!
|
||||
|
||||
ECHO -
|
||||
SET "ARGUMENTS=-NoProfile -ExecutionPolicy Bypass -File \""!SCRIPT!\"""
|
||||
ECHO With Arguments:
|
||||
ECHO !ARGUMENTS!
|
||||
|
||||
ECHO -
|
||||
SET "SUBCOMMAND=Start-Process -FilePath '!POWERSHELLEXE!' -WindowStyle hidden -ArgumentList '!ARGUMENTS!' "
|
||||
ECHO Subcommand:
|
||||
ECHO !SUBCOMMAND!
|
||||
|
||||
ECHO -
|
||||
IF !ADMINMODE! EQU 1 (
|
||||
SET "COMMAND=Start-Process powershell.exe -WindowStyle hidden -Verb runas {!SUBCOMMAND!} "
|
||||
) ELSE (
|
||||
SET "COMMAND=Start-Process powershell.exe -WindowStyle hidden {!SUBCOMMAND!} "
|
||||
)
|
||||
ECHO In nested command:
|
||||
ECHO !COMMAND!
|
||||
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "!COMMAND!"
|
||||
|
||||
IF ERRORLEVEL 1 (
|
||||
ECHO There was an error running the script: !SCRIPT! >> !LOGFILE!
|
||||
)
|
||||
)
|
||||
|
||||
REM --------------------------------------------------------------
|
||||
REM -------------------------final part---------------------------
|
||||
REM --------------------------------------------------------------
|
||||
|
||||
:exit
|
||||
ENDLOCAL
|
||||
ECHO -
|
||||
ECHO Program Complete %date% at %time:~0,8% o'clock, on %computername%.
|
||||
ECHO This Window will close in:
|
||||
timeout /T 10
|
||||
exit
|
||||
@@ -0,0 +1,40 @@
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Version 1.2.0.1 - 13.08.2025
|
||||
NEW: -
|
||||
FIX: -
|
||||
CHG: - Script accepts only one config file now
|
||||
- PowerShell Version check removed
|
||||
REM: -
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Version 1.2.0.0 - 24.11.2024
|
||||
NEW: - Added support for updating Thunderbird
|
||||
- Added switch for install and update action (=FirefoxAction;=ThunderbirdAction)
|
||||
FIX: -
|
||||
CHG: - Script renamed. Old name: "Update-Firefox", new name: "Update-MozillaSoftware"
|
||||
REM: -
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Version 1.1.0.0 - 23.11.2024
|
||||
NEW: - Logging and Configfile implemented
|
||||
FIX: -
|
||||
CHG: - New way to retrive the new software version (now via JSON)
|
||||
REM: -
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Version 1.0.0.0 - 04.11.2024
|
||||
NEW: -
|
||||
FIX: -
|
||||
CHG: -
|
||||
REM: -
|
||||
|
||||
-------------------------------------legend------------------------------------
|
||||
NEW: = Added a new functionality
|
||||
FIX: = Fixed a Issue with existing functionality
|
||||
CHG: = Changed a existing functionality
|
||||
REM: = Removed a functionality
|
||||
-------------------------------------------------------------------------------
|
||||
Binary file not shown.
Reference in New Issue
Block a user