Anlage des Repos
This commit is contained in:
@@ -0,0 +1,268 @@
|
||||
Function GetWinLineDocInfoByAccountAndRunningNr(DocAccountAndRunningNr, PostingType, WinLineDocType)
|
||||
|
||||
'Stand 25.08.2020
|
||||
|
||||
On Error Resume Next
|
||||
|
||||
'Set SQL Table and Query for DocHead. Default: "T025"
|
||||
SQLTable_DocHead = "[T025]"
|
||||
SQLQuery_DocHead = "c000 = '" & DocAccountAndRunningNr & "'" & SQLQuery_BasicWhere
|
||||
|
||||
'Set SQL Table and Query for DocMid. Default: "T026"
|
||||
SQLTable_DocMid = "[T026]"
|
||||
|
||||
SQLQuery_DocMid_MengeGeliefert = ""
|
||||
SQLQuery_DocMid_MengeGeliefert = SQLQuery_DocMid_MengeGeliefert & "SELECT SUM(c006) as [MengeGeliefert] "
|
||||
SQLQuery_DocMid_MengeGeliefert = SQLQuery_DocMid_MengeGeliefert & "FROM " & SQLTable_DocMid & "(NOLOCK) "
|
||||
SQLQuery_DocMid_MengeGeliefert = SQLQuery_DocMid_MengeGeliefert & "WHERE [c000] LIKE '" & DocAccountAndRunningNr & "-%'" & SQLQuery_BasicWhere
|
||||
|
||||
SQLQuery_DocMid_Rueckstandsmenge = ""
|
||||
SQLQuery_DocMid_Rueckstandsmenge = SQLQuery_DocMid_Rueckstandsmenge & "SELECT SUM(c099) as [RueckstandsMenge] "
|
||||
SQLQuery_DocMid_Rueckstandsmenge = SQLQuery_DocMid_Rueckstandsmenge & "FROM " & SQLTable_DocMid & "(NOLOCK) "
|
||||
SQLQuery_DocMid_Rueckstandsmenge = SQLQuery_DocMid_Rueckstandsmenge & "WHERE [c000] LIKE '" & DocAccountAndRunningNr & "-%'" & SQLQuery_BasicWhere
|
||||
|
||||
IF (SQLTable_DocHead <> "") and (SQLQuery_DocHead <> "") and (PostingType <> "") and (WinLineDocType <> "") Then
|
||||
|
||||
Set SQLResult_DocHead = CWLStart.CurrentCompany.SearchRecord (SQLTable_DocHead, SQLQuery_DocHead)
|
||||
|
||||
If Err.Number <> 0 Then
|
||||
MSGBOX "Error Code: "& Err.Number & vbCrlf & _
|
||||
"Error Description: "& Err.Description,,"ERROR: Function GetWinLineDocInfoByAccountAndRunningNr Getting DocHead from DB Table "& SQLTable_DocHead
|
||||
Err.Clear
|
||||
Else
|
||||
|
||||
'If no line results
|
||||
If SQLResult_DocHead.RowCount = -1 Then
|
||||
|
||||
If DebugMode = "Enabled" Then
|
||||
MSGBOX "No Rows found, SQL: "& SQLQuery_DocHead,,"DEBUG - Info: Function GetWinLineDocInfoByAccountAndRunningNrDocHead from Database table "& SQLTable_DocHead
|
||||
End If
|
||||
|
||||
Elseif SQLResult_DocHead.RowCount = 1 Then
|
||||
|
||||
If DebugMode = "Enabled" Then
|
||||
MSGBOX "One Row found, SQL: "& SQLQuery_DocHead,,"DEBUG - Info: Function GetWinLineDocInfoByAccountAndRunningNrDocHead from Database table "& SQLTable_DocHead
|
||||
End If
|
||||
|
||||
'Unique Key
|
||||
DocAccountAndRunningNr = SQLResult_DocHead.value(0)
|
||||
|
||||
'Laufnumemr
|
||||
DocRunningNr = SQLResult_DocHead.value(21)
|
||||
|
||||
'Druckstatus Angebot / Anfrage
|
||||
DocPrintState1 = SQLResult_DocHead.value(22)
|
||||
|
||||
'Druckstatus Auftrag / Bestellung
|
||||
DocPrintState2 = SQLResult_DocHead.value(23)
|
||||
|
||||
'Druckstatus Lieferschein
|
||||
DocPrintState3 = SQLResult_DocHead.value(24)
|
||||
|
||||
'Druckstatus Rechnung
|
||||
DocPrintState4 = SQLResult_DocHead.value(25)
|
||||
|
||||
'Number of the Offer ("Angebot")
|
||||
DocOfferNr = SQLResult_DocHead.value(41)
|
||||
|
||||
'Number of the Order ("Angebot")
|
||||
DocOrderNr = SQLResult_DocHead.value(42)
|
||||
|
||||
'Number of delivery note ("Lieferschein")
|
||||
DocDeliveryNoteNr = SQLResult_DocHead.value(43)
|
||||
|
||||
'Number of the Invoice ("Rechung")
|
||||
DocInvoiceNr = SQLResult_DocHead.value(52)
|
||||
|
||||
'When the doc ("Beleg") was created
|
||||
DocCreated = SQLResult_DocHead.value(56)
|
||||
|
||||
'When the doc ("Beleg") was last changed
|
||||
DocLastChange = SQLResult_DocHead.value(57)
|
||||
|
||||
'The ten "Belegkopfnotizen"
|
||||
DocHeadText1 = SQLResult_DocHead.value(59)
|
||||
DocHeadText2 = SQLResult_DocHead.value(60)
|
||||
DocHeadText3 = SQLResult_DocHead.value(61)
|
||||
DocHeadText4 = SQLResult_DocHead.value(62)
|
||||
DocHeadText5 = SQLResult_DocHead.value(63)
|
||||
DocHeadText6 = SQLResult_DocHead.value(64)
|
||||
DocHeadText7 = SQLResult_DocHead.value(65)
|
||||
DocHeadText8 = SQLResult_DocHead.value(66)
|
||||
DocHeadText9 = SQLResult_DocHead.value(67)
|
||||
DocHeadText10 = SQLResult_DocHead.value(68)
|
||||
|
||||
'The current type (1= Anfrage/Angebot; 2= Auftrag/Bestellung; 3= Lieferschein; 4=Rechnung)
|
||||
DocType = SQLResult_DocHead.value(134)
|
||||
DocComment = SQLResult_DocHead.value(163)
|
||||
|
||||
'msgbox SQLQuery_DocMid_MengeGeliefert
|
||||
'msgbox SQLQuery_DocMid_RueckstandsMenge
|
||||
|
||||
Set SQLResult_DocMid_MengeGeliefert = CWLStart.CurrentCompany.Connection.Select(SQLQuery_DocMid_MengeGeliefert)
|
||||
'msgbox SQLResult_DocMid_MengeGeliefert.value("MengeGeliefert")
|
||||
|
||||
Set SQLResult_DocMid_RueckstandsMenge = CWLStart.CurrentCompany.Connection.Select(SQLQuery_DocMid_RueckstandsMenge)
|
||||
'msgbox SQLResult_DocMid_RueckstandsMenge.value("RueckstandsMenge")
|
||||
IF DebugMode = "Enabled" THEN
|
||||
|
||||
End if
|
||||
DocBackOrder = SQLResult_DocMid_RueckstandsMenge.value("RueckstandsMenge")
|
||||
|
||||
'msgbox SQLResult_DocMid_Rueckstandsmenge.value("RueckstandsMenge")
|
||||
|
||||
IF (PostingType = 1) Then
|
||||
|
||||
'If doc = "Angebot" or "Angebots-storno"
|
||||
IF (WinLineDocType = 1) or (WinLineDocType = 11) then
|
||||
|
||||
DocNr = DocOfferNr
|
||||
|
||||
IF (WinLineDocType = 1) then
|
||||
|
||||
WinLineDocType = "Angebot (debitorisch)"
|
||||
|
||||
ElseIF (WinLineDocType = 11) then
|
||||
|
||||
WinLineDocType = "Angebot-Storno (debitorisch)"
|
||||
|
||||
End If
|
||||
|
||||
'If doc = "Auftrag" or "Auftrag-storno"
|
||||
ElseIf (WinLineDocType = 2) or (WinLineDocType = 12) then
|
||||
|
||||
DocNr = DocOrderNr
|
||||
|
||||
IF (WinLineDocType = 2) then
|
||||
|
||||
WinLineDocType = "Auftrag (debitorisch)"
|
||||
|
||||
ElseIF (WinLineDocType = 12) then
|
||||
|
||||
WinLineDocType = "Auftrag-Storno (debitorisch)"
|
||||
|
||||
End If
|
||||
|
||||
'If doc = "Lieferschein" or "Lieferschein-storno" or "Teillieferschein"
|
||||
ElseIf (WinLineDocType = 3) or (WinLineDocType = 13) or (WinLineDocType = -3) then
|
||||
|
||||
DocNr = DocDeliveryNoteNr
|
||||
|
||||
IF (DocBackOrder = 0) and (DocPrintState3 <> "L") then
|
||||
|
||||
WinLineDocType = "Lieferschein (debitorisch)"
|
||||
|
||||
ElseIF (DocBackOrder = 0) and (DocPrintState3 = "L") then
|
||||
|
||||
WinLineDocType = "Lieferschein-Storno (debitorisch)"
|
||||
|
||||
ElseIF (DocBackOrder <> 0) and (DocPrintState3 <> "L") then
|
||||
|
||||
WinLineDocType = "Teillieferschein (debitorisch)"
|
||||
|
||||
ElseIF (DocBackOrder <> 0) and (DocPrintState3 = "L") then
|
||||
|
||||
'Über die DB Werte ist eine Unterscheidung zwischen Lieferschein und Teillieferschein Storno nicht möglich!
|
||||
WinLineDocType = "Teillieferschein-Storno (debitorisch)"
|
||||
|
||||
End If
|
||||
|
||||
'If doc = "Rechnung" or "Rechnungs-storno"
|
||||
ElseIf (WinLineDocType = 4) or (WinLineDocType = 14) then
|
||||
|
||||
DocNr = DocInvoiceNr
|
||||
|
||||
IF (WinLineDocType = 4) and (DocPrintState4 <> "L") then
|
||||
|
||||
WinLineDocType = "Rechnung (debitorisch)"
|
||||
|
||||
ElseIF (WinLineDocType = 4) and (DocPrintState4 = "L") then
|
||||
|
||||
WinLineDocType = "Rechnung-Storno (debitorisch)"
|
||||
|
||||
ElseIF (WinLineDocType = 14) and (DocPrintState4 = "L") then
|
||||
|
||||
WinLineDocType = "Rechnung-Storno (debitorisch)"
|
||||
|
||||
End If
|
||||
|
||||
Else
|
||||
|
||||
IF DebugMode = "Enabled" THEN
|
||||
MSGBOX "WinLineDocType is not configured!" & vbCrLf & _
|
||||
"WinLineDocType: " & WinLineDocType, , "DEBUG - Info: Export Metadata"
|
||||
END IF
|
||||
|
||||
End if
|
||||
|
||||
ElseIf (PostingType = 2) Then
|
||||
|
||||
'not implement
|
||||
|
||||
End if
|
||||
|
||||
'Array for the function to return
|
||||
DIM DocInfo(250)
|
||||
|
||||
'Items like T25 c000 to c188
|
||||
DocInfo(59) = DocCreated
|
||||
DocInfo(60) = DocLastChange
|
||||
|
||||
DocInfo(63) = DocHeadText1
|
||||
DocInfo(64) = DocHeadText2
|
||||
DocInfo(65) = DocHeadText3
|
||||
DocInfo(66) = DocHeadText4
|
||||
DocInfo(67) = DocHeadText5
|
||||
DocInfo(68) = DocHeadText6
|
||||
DocInfo(69) = DocHeadText7
|
||||
DocInfo(70) = DocHeadText8
|
||||
DocInfo(71) = DocHeadText9
|
||||
DocInfo(72) = DocHeadText10
|
||||
|
||||
DocInfo(139) = DocType
|
||||
DocInfo(165) = DocComment
|
||||
|
||||
'Items beyond T25
|
||||
DocInfo(200) = WinLineDocType
|
||||
DocInfo(201) = DocNr
|
||||
|
||||
IF DebugMode = "Enabled" THEN
|
||||
|
||||
CRLF = chr(13)&chr(10)
|
||||
msg = "Parameter:" & CRLF
|
||||
|
||||
For i = 0 To Ubound(DocInfo)
|
||||
|
||||
If (DocInfo(i) <> "") then
|
||||
msg = msg & i & ".: " & DocInfo(i) & CRLF
|
||||
end if
|
||||
Next
|
||||
|
||||
msgbox msg ,, "Macro Name: " & CWLMacro.MName
|
||||
|
||||
End if
|
||||
|
||||
GetWinLineDocInfoByAccountAndRunningNr = DocInfo
|
||||
|
||||
Else
|
||||
|
||||
If DebugMode = "Enabled" Then
|
||||
MSGBOX "To many Rows found, SQL: "& SQLQuery_DocHead,,"DEBUG - Info: Function GetWinLineDocInfoByAccountAndRunningNr DocHead from Database table "& SQLTable_DocHead
|
||||
End If
|
||||
|
||||
GetWinLineDocInfoByAccountAndRunningNr = ""
|
||||
|
||||
End If
|
||||
|
||||
End If
|
||||
Else
|
||||
|
||||
If DebugMode = "Enabled" Then
|
||||
MSGBOX "Missing Parameter values, SQL: "& SQLQuery_DocHead,,"DEBUG - Info: Function GetWinLineDocInfoByAccountAndRunningNrDocHead from Database table " & SQLTable_DocHead
|
||||
End If
|
||||
|
||||
GetWinLineDocInfoByAccountAndRunningNr = ""
|
||||
|
||||
End If
|
||||
|
||||
End Function
|
||||
@@ -0,0 +1,41 @@
|
||||
Function GetWinLineOriginalLineNumber(OrderNumber, ArticleNumber, IsSerialNumberArticle)
|
||||
Set Conn = CWLStart.CurrentCompany.Connection
|
||||
|
||||
If IsSerialNumberArticle = 1 Then
|
||||
SQL = "SELECT TOP 1 c078 FROM t026 (NOLOCK) "
|
||||
SQL = SQL & "WHERE c067 = '"& OrderNumber &"' AND c003 = '"& ArticleNumber &"' "
|
||||
SQL = SQL & SQLQuery_BasicWhere
|
||||
|
||||
Set Result = Conn.Select(SQL)
|
||||
|
||||
If DEBUG_ON = True Then
|
||||
AddDebugLine "Querying for Original Line Number.. " & vbNewline
|
||||
AddDebugLine "Result Columns: " & Result
|
||||
AddDebugLine "Result Rows: " & Result.RowCount
|
||||
AddDebugLine "SQL: " & SQL
|
||||
|
||||
ShowDebugBox "GetWinLineOriginalLineNumber"
|
||||
End If
|
||||
|
||||
If Result < 0 Then
|
||||
If err <> 0 Then
|
||||
Msgbox "Fehler bei Abfrage:" & vbNewline & err.description, vbExclamation, DEFAULT_TITLE & " - GetWinLineOriginalLineNumber"
|
||||
Exit Function
|
||||
Else
|
||||
Msgbox "Abfrage lieferte keine Ergebnisse.", vbExclamation, DEFAULT_TITLE & " - GetWinLineOriginalLineNumber"
|
||||
Exit Function
|
||||
End If
|
||||
End If
|
||||
|
||||
GetWinLineOriginalLineNumber = Result.Value("c078")
|
||||
Else
|
||||
If DEBUG_ON = True Then
|
||||
AddDebugLine "Setting Original Line Number to 0.."
|
||||
|
||||
ShowDebugBox "GetWinLineOriginalLineNumber"
|
||||
End If
|
||||
|
||||
|
||||
GetWinLineOriginalLineNumber = "0"
|
||||
End If
|
||||
End Function
|
||||
@@ -0,0 +1,75 @@
|
||||
Function GetWinLineStorageLocation(ProductNumber, ProductSerialNumber, IsSerialNumberArticle)
|
||||
Set Conn = CWLStart.CurrentCompany.Connection
|
||||
|
||||
' Get 'Lagerortstruktur' for Product
|
||||
SQL = "SELECT c178 FROM [V021] (NOLOCK) WHERE c010 = '"& ProductNumber &"'"
|
||||
|
||||
Set Result = Conn.Select(SQL)
|
||||
|
||||
If Result.Value("c178") = 0 Then
|
||||
GetWinLineStorageLocation = 0
|
||||
Exit Function
|
||||
End If
|
||||
|
||||
If IsSerialNumberArticle = 1 Then
|
||||
SQL = ""
|
||||
SQL = SQL & "SELECT TOP 1 T335.c000 "
|
||||
SQL = SQL & "FROM [T024] (NOLOCK), [T335] (NOLOCK), [T299] (NOLOCK) "
|
||||
SQL = SQL & "OUTER APPLY (SELECT C000, C001, C003, C031 FROM T335 (NOLOCK) WHERE C000 = T299.C001 AND T335.MESOCOMP = '" & MandatorNr & "' AND T335.MESOYEAR = " & WinLineCurrentYear & ") L1 "
|
||||
SQL = SQL & "OUTER APPLY (SELECT C000, C001, C003, C031 FROM T335 (NOLOCK) WHERE C000 = T299.C002 AND T335.MESOCOMP = '" & MandatorNr & "' AND T335.MESOYEAR = " & WinLineCurrentYear & ") L2 "
|
||||
SQL = SQL & "OUTER APPLY (SELECT C000, C001, C003, C031 FROM T335 (NOLOCK) WHERE C000 = T299.C003 AND T335.MESOCOMP = '" & MandatorNr & "' AND T335.MESOYEAR = " & WinLineCurrentYear & ") L3 "
|
||||
SQL = SQL & "OUTER APPLY (SELECT C000, C001, C003, C031 FROM T335 (NOLOCK) WHERE C000 = T299.C004 AND T335.MESOCOMP = '" & MandatorNr & "' AND T335.MESOYEAR = " & WinLineCurrentYear & ") L4 "
|
||||
SQL = SQL & "OUTER APPLY (SELECT C000, C001, C003, C031 FROM T335 (NOLOCK) WHERE C000 = T299.C005 AND T335.MESOCOMP = '" & MandatorNr & "' AND T335.MESOYEAR = " & WinLineCurrentYear & ") L5 "
|
||||
SQL = SQL & "WHERE T299.C000 = '"& GetWinLineInternalProductNumber(ProductNumber, ProductSerialNumber) &"' AND T299.C000 = T024.C002 AND T299.MESOCOMP = '" & MandatorNr & "' AND T299.MESOYEAR = " & WinLineCurrentYear & " AND T024.MESOCOMP = '" & MandatorNr & "' "
|
||||
SQL = SQL & "AND T024.MESOYEAR = " & WinLineCurrentYear & " AND T335.MESOCOMP = '" & MandatorNr & "' AND T335.MESOYEAR = " & WinLineCurrentYear & " AND (T299.C001 = T335.C020 AND T299.C002 = T335.C021 "
|
||||
SQL = SQL & "AND T299.C003 = T335.C022 AND T299.C004 = T335.C023 AND T299.C005 = T335.C024 AND T299.C006 = T335.C025) "
|
||||
SQL = SQL & "ORDER BY T335.c000 DESC, T299.C001,T299.C002,T299.C003,T299.C004,T299.C005,T299.C006"
|
||||
Else
|
||||
SQL = ""
|
||||
SQL = SQL & "SELECT TOP 1 T335.c000 "
|
||||
SQL = SQL & "FROM T024 (NOLOCK), T335 (NOLOCK), T299 (NOLOCK) "
|
||||
SQL = SQL & "OUTER APPLY (SELECT C000, C001, C003, C031 FROM T335 (NOLOCK) WHERE C000 = T299.C001 AND T335.MESOCOMP = '" & MandatorNr & "' AND T335.MESOYEAR = " & WinLineCurrentYear & ") L1 "
|
||||
SQL = SQL & "OUTER APPLY (SELECT C000, C001, C003, C031 FROM T335 (NOLOCK) WHERE C000 = T299.C002 AND T335.MESOCOMP = '" & MandatorNr & "' AND T335.MESOYEAR = " & WinLineCurrentYear & ") L2 "
|
||||
SQL = SQL & "OUTER APPLY (SELECT C000, C001, C003, C031 FROM T335 (NOLOCK) WHERE C000 = T299.C003 AND T335.MESOCOMP = '" & MandatorNr & "' AND T335.MESOYEAR = " & WinLineCurrentYear & ") L3 "
|
||||
SQL = SQL & "OUTER APPLY (SELECT C000, C001, C003, C031 FROM T335 (NOLOCK) WHERE C000 = T299.C004 AND T335.MESOCOMP = '" & MandatorNr & "' AND T335.MESOYEAR = " & WinLineCurrentYear & ") L4 "
|
||||
SQL = SQL & "OUTER APPLY (SELECT C000, C001, C003, C031 FROM T335 (NOLOCK) WHERE C000 = T299.C005 AND T335.MESOCOMP = '" & MandatorNr & "' AND T335.MESOYEAR = " & WinLineCurrentYear & ") L5 "
|
||||
SQL = SQL & "WHERE T299.C000 = '"& ProductNumber &"' AND T299.C000 = T024.C002 AND T299.MESOCOMP = '" & MandatorNr & "' AND T299.MESOYEAR = " & WinLineCurrentYear & " AND T024.MESOCOMP = '" & MandatorNr & "' "
|
||||
SQL = SQL & "AND T024.MESOYEAR = " & WinLineCurrentYear & " AND T335.MESOCOMP = '" & MandatorNr & "' AND T335.MESOYEAR = " & WinLineCurrentYear & " AND (T299.C001 = T335.C020 AND T299.C002 = T335.C021 "
|
||||
SQL = SQL & "AND T299.C003 = T335.C022 AND T299.C004 = T335.C023 AND T299.C005 = T335.C024 AND T299.C006 = T335.C025) "
|
||||
SQL = SQL & "ORDER BY T335.c000 DESC, T299.C001,T299.C002,T299.C003,T299.C004,T299.C005,T299.C006"
|
||||
End If
|
||||
|
||||
If DEBUG_ON = True Then
|
||||
AddDebugLine "SQL Part 1: " & Mid(SQL, 1, 750)
|
||||
ShowDebugBox "GetWinLineStorageLocation"
|
||||
|
||||
AddDebugLine "SQL Part 2: " & Mid(SQL, 750)
|
||||
ShowDebugBox "GetWinLineStorageLocation"
|
||||
End If
|
||||
|
||||
Set Result = Conn.Select(SQL)
|
||||
|
||||
If DEBUG_ON = True Then
|
||||
AddDebugLine "Querying storage location... " & vbNewline
|
||||
AddDebugLine "ArticleNumber: " & ProductNumber
|
||||
AddDebugLine "SerialNumber: " & ProductSerialNumber
|
||||
AddDebugLine "IsSerialNumber Article: " & IsSerialNumberArticle
|
||||
AddDebugLine "Result Columns: " & Result
|
||||
AddDebugLine "Result Rows: " & Result.RowCount
|
||||
AddDebugLine "SQL: " & SQL
|
||||
|
||||
ShowDebugBox "GetWinLineStorageLocation"
|
||||
End If
|
||||
|
||||
' If Result < 0 Then
|
||||
' If err <> 0 Then
|
||||
' Msgbox "Fehler bei Abfrage:" & vbNewline & err.description, vbExclamation, DEFAULT_TITLE & " - GetWinLineStorageLocation"'
|
||||
' Exit Function
|
||||
' Else
|
||||
' Msgbox "Abfrage lieferte keine Ergebnisse.", vbExclamation, DEFAULT_TITLE & " - GetWinLineStorageLocation"
|
||||
' Exit Function
|
||||
' End If
|
||||
' End If
|
||||
|
||||
GetWinLineStorageLocation = Result.Value("c000")
|
||||
End Function
|
||||
Binary file not shown.
@@ -0,0 +1,194 @@
|
||||
'Function to load VBS modules
|
||||
Public Function LoadVBSModule(VBSModuleParams)
|
||||
|
||||
'SYNOPSIS
|
||||
'Function will load external - additional - VBS Modules into current Script.
|
||||
|
||||
'DESCRIPTION
|
||||
'By working With Modules, this Function Is necessary To load external Modul Functions into the current VB-Script.
|
||||
'Call parameter must be an array, because VB-Script functions cannot handle optional Parameters.
|
||||
'In develepment and Test Enviroment it is possible, to work with distributed Folders with different Modules. Therefor the Parameter
|
||||
'"VBSModuleParams(1)" (which is the 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
|
||||
'VBS must be enabled
|
||||
|
||||
'REQUIREMENT Assembly
|
||||
'<NONE>
|
||||
|
||||
'REQUIREMENT Variables
|
||||
'FSOModule, Module, ModuleName, ModuleCode, ModulePath, WshShell, ModuleAutoSourcePath
|
||||
|
||||
'REQUIREMENT Variables preSet
|
||||
'ModuleDefaultSourcePath (optional)
|
||||
|
||||
'REQUIREMENT Functions
|
||||
'<NONE>
|
||||
|
||||
'VERSION
|
||||
'Number: 1.3.0.1 / Date: 29.08.2020
|
||||
|
||||
'PARAMETER VBSModuleParams(0) = ModuleName
|
||||
'Give the Module Name, you want to load into the current VB-Script.
|
||||
|
||||
'PARAMETER VBSModuleParams(1) = ModuleOverrideSourcePath
|
||||
'Optional Parameter. By giving the ModuleOverrideSourcePath, Function will not check other Paths for the Function you want to load.
|
||||
|
||||
'EXAMPLE
|
||||
'Dim VBSModuleParams
|
||||
'Redim VBSModuleParams(0)
|
||||
'VBSModuleParams(0) = Module
|
||||
'LoadVBSModule(VBSModuleParams)
|
||||
|
||||
'EXAMPLE
|
||||
'Dim VBSModuleParams
|
||||
'Redim VBSModuleParams(1)
|
||||
'VBSModuleParams(0) = Module
|
||||
'VBSModuleParams(1) = "D:\ScriptFiles\Modules"
|
||||
'LoadVBSModule(VBSModuleParams)
|
||||
|
||||
On Error Resume Next
|
||||
|
||||
'Clear Error Variable
|
||||
Err.Clear
|
||||
|
||||
Dim FSOModule, Module, ModuleName, ModuleCode, ModulePath, WshShell, ModuleAutoSourcePath
|
||||
Set FSOModule = CreateObject("Scripting.FileSystemObject")
|
||||
|
||||
'How many parameters are given in the array
|
||||
If (UBound(VBSModuleParams) = 0) Then
|
||||
|
||||
ModuleName = VBSModuleParams(0)
|
||||
|
||||
If FSOModule.FolderExists(ModuleDefaultSourcePath) Then
|
||||
|
||||
'If global var is set, take it!
|
||||
ModulePath = ModuleDefaultSourcePath
|
||||
|
||||
ELSE
|
||||
|
||||
'Getting the current dir, when ModuleDefaultSourcePath does not exist
|
||||
Set WshShell = CreateObject("WScript.Shell")
|
||||
ModuleAutoSourcePath = WshShell.CurrentDirectory
|
||||
|
||||
'By this parameter way the path is more variable
|
||||
ModulePath = ModuleAutoSourcePath & "\" & "Modules"
|
||||
|
||||
If (DEBUG_ON = True) Or (DebugMode = "Enabled") Then
|
||||
MSGBOX "Parameter1 = " & VBSModuleParams(0) & vbCrlf & _
|
||||
"ModuleDefaultSourcePath = " & ModuleDefaultSourcePath,,"DEBUG Info: Parameter Values in Array - VBSModuleParams"
|
||||
End If
|
||||
|
||||
End if
|
||||
|
||||
ElseIf (UBound(VBSModuleParams) = 1) Then
|
||||
|
||||
ModuleName = VBSModuleParams(0)
|
||||
ModulePath = VBSModuleParams(1)
|
||||
|
||||
If (DEBUG_ON = True) Or (DebugMode = "Enabled") Then
|
||||
MSGBOX "Parameter1 = " & VBSModuleParams(0) & vbCrlf & _
|
||||
"Parameter2 = " & VBSModuleParams(1),,"DEBUG Info: Parameter Values in Array - VBSModuleParams"
|
||||
End If
|
||||
|
||||
Else
|
||||
|
||||
msgbox "Invalid function call!" & vbCrlf & _
|
||||
"Please check the parameters!" & vbCrlf & _
|
||||
"...then restart this Script!",vbExclamation ,"LoadVBSModule: Parameter Error!"
|
||||
|
||||
End if
|
||||
|
||||
'Checking folder paths 'Check if given path is valid, if not create it
|
||||
If Not FSOModule.FolderExists(ModulePath) Then
|
||||
|
||||
FSOModule.CreateFolder(ModulePath)
|
||||
msgbox "The ModulePath doesnt exist, trying to create!" & vbCrlf & _
|
||||
"Please place your Modules there: " & vbCrlf & _
|
||||
ModulePath & vbCrlf & vbCrlf & _
|
||||
"...then restart this Script!",vbExclamation ,"LoadVBSModule: Modules / ModulePath is missing!"
|
||||
Else
|
||||
|
||||
'Clear Error Variable
|
||||
Err.Clear
|
||||
|
||||
'Building full module path and name
|
||||
ModuleFullName = ModulePath & "\" & Modulename & ".vbs"
|
||||
|
||||
'does the file exist?
|
||||
If Not FSOModule.FileExists(ModuleFullName) Then
|
||||
If Err.Number <> 0 Then
|
||||
MSGBOX "Error Code: "& Err.Number & vbCrlf & _
|
||||
"Error Description: "& Err.Description,,"ERROR: Module does not exist! "
|
||||
Err.Clear
|
||||
LoadVBSModule = "False"
|
||||
End If
|
||||
|
||||
Else
|
||||
|
||||
'Open file
|
||||
Set Module = FSOModule.OpenTextFile(ModuleFullName, 1)
|
||||
|
||||
'Get file content
|
||||
ModuleCode = Module.ReadAll
|
||||
|
||||
'Close file handle
|
||||
Module.Close
|
||||
|
||||
'Execute the file content
|
||||
ExecuteGlobal ModuleCode
|
||||
|
||||
If Err.Number <> 0 Then
|
||||
MSGBOX "Error Code: "& Err.Number & vbCrlf & _
|
||||
"Error Description: "& Err.Description,,"ERROR: Module cannot be loaded!"
|
||||
Err.Clear
|
||||
LoadVBSModule = "False"
|
||||
Else
|
||||
LoadVBSModule = "True"
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
End Function 'LoadVBSModule
|
||||
|
||||
'------------------------------------ EXAMPLE TO CALL THE FUNCTION ------------------------------------
|
||||
|
||||
'Prepare Array (Arrays are zero based!)
|
||||
Modules = Array("TestModule1","TestModule2","TestModule3")
|
||||
|
||||
Dim Module
|
||||
|
||||
'Load external Modules.
|
||||
For Each Module In Modules
|
||||
|
||||
'Create the array to pass in to our function
|
||||
Dim VBSModuleParams
|
||||
|
||||
'Call the subroutine with two arguments
|
||||
Redim VBSModuleParams(0) 'Change to 1, for 2 values
|
||||
VBSModuleParams(0) = Module
|
||||
'VBSModuleParams(1) = ""
|
||||
|
||||
LoadVBSModuleResult = LoadVBSModule(VBSModuleParams)
|
||||
|
||||
If (LoadVBSModuleResult <> "True") Then
|
||||
|
||||
'Set WScript = CreateObject("WScript.Shell")
|
||||
MSGBOX "Module: " & Module & " was Not succesful been loaded!" & vbCrlf & _
|
||||
"Please load the Module and try again, running this Function/Module!" & vbCrlf & _
|
||||
"Exiting, because of this Issue." & vbCrlf & _
|
||||
Err.Description, vbCritical, "DEBUG Info: Cannot load Module!"
|
||||
'WScript.Quit = not possible in Winline enviroment
|
||||
|
||||
End If
|
||||
|
||||
Next 'end for each
|
||||
|
||||
TestModule1
|
||||
TestModule2
|
||||
TestModule3
|
||||
|
||||
'------------------------------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,227 @@
|
||||
'Function to load VBS modules
|
||||
Public Function LoadVBSModule(VBSModuleParams)
|
||||
|
||||
'SYNOPSIS
|
||||
'Function will load external - additional - VBS Modules (VBM or VBS File(s)) into current Script.
|
||||
|
||||
'DESCRIPTION
|
||||
'By working With Modules, this Function Is necessary To load external Modul Functions into the current VB-Script.
|
||||
'Call parameter must be an array, because VB-Script functions cannot handle optional Parameters.
|
||||
'In develepment and Test Enviroment it is possible, to work with distributed Folders with different Modules. Therefor the Parameter
|
||||
'"VBSModuleParams(1)" (which is the 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
|
||||
'VBS must be enabled
|
||||
|
||||
'REQUIREMENT Assembly
|
||||
'<NONE>
|
||||
|
||||
'REQUIREMENT Variables
|
||||
'FSOModule, Module, ModuleName, ModuleCode, ModulePath, WshShell, ModuleAutoSourcePath
|
||||
|
||||
'REQUIREMENT Variables preSet
|
||||
'ModuleDefaultSourcePath (optional)
|
||||
|
||||
'REQUIREMENT Functions
|
||||
'<NONE>
|
||||
|
||||
'VERSION
|
||||
'Number: 1.5.0.2 / Date: 17.06.2021
|
||||
|
||||
'PARAMETER VBSModuleParams(0) = ModuleName
|
||||
'Give the Module Name, you want to load into the current VB-Script.
|
||||
|
||||
'PARAMETER VBSModuleParams(1) = ModuleOverrideSourcePath
|
||||
'Optional Parameter. By giving the ModuleOverrideSourcePath, Function will not check other Paths for the Function you want to load.
|
||||
|
||||
'EXAMPLE
|
||||
'Dim VBSModuleParams
|
||||
'Redim VBSModuleParams(0)
|
||||
'VBSModuleParams(0) = Module
|
||||
'LoadVBSModule(VBSModuleParams)
|
||||
|
||||
'EXAMPLE
|
||||
'Dim VBSModuleParams
|
||||
'Redim VBSModuleParams(1)
|
||||
'VBSModuleParams(0) = Module
|
||||
'VBSModuleParams(1) = "D:\ScriptFiles\Modules"
|
||||
'LoadVBSModule(VBSModuleParams)
|
||||
|
||||
On Error Resume Next
|
||||
|
||||
'Clear Error Variable
|
||||
Err.Clear
|
||||
|
||||
Dim FSOModule, Module, ModuleName, ModuleCode, ModulePath, WshShell, ModuleAutoSourcePath
|
||||
Set FSOModule = CreateObject("Scripting.FileSystemObject")
|
||||
|
||||
'How many parameters are given in the array
|
||||
If (UBound(VBSModuleParams) = 0) Then
|
||||
|
||||
ModuleName = VBSModuleParams(0)
|
||||
|
||||
If FSOModule.FolderExists(ModuleDefaultSourcePath) Then
|
||||
|
||||
'If global var is set, take it!
|
||||
ModulePath = ModuleDefaultSourcePath
|
||||
|
||||
ELSE
|
||||
|
||||
'Getting the current dir, when ModuleDefaultSourcePath does not exist
|
||||
Set WshShell = CreateObject("WScript.Shell")
|
||||
ModuleAutoSourcePath = WshShell.CurrentDirectory
|
||||
|
||||
'By this parameter way the path is more variable
|
||||
ModulePath = ModuleAutoSourcePath & "\" & "Modules"
|
||||
|
||||
If (DEBUG_ON = True) Or (DebugMode = "Enabled") Then
|
||||
MSGBOX "Parameter1 = " & VBSModuleParams(0) & vbCrlf & _
|
||||
"ModuleDefaultSourcePath = " & ModuleDefaultSourcePath,,"DEBUG Info: Parameter Values in Array - VBSModuleParams"
|
||||
End If
|
||||
|
||||
End if
|
||||
|
||||
ElseIf (UBound(VBSModuleParams) = 1) Then
|
||||
|
||||
ModuleName = VBSModuleParams(0)
|
||||
ModulePath = VBSModuleParams(1)
|
||||
|
||||
If (DEBUG_ON = True) Or (DebugMode = "Enabled") Then
|
||||
MSGBOX "Parameter1 = " & VBSModuleParams(0) & vbCrlf & _
|
||||
"Parameter2 = " & VBSModuleParams(1),,"DEBUG Info: Parameter Values in Array - VBSModuleParams"
|
||||
End If
|
||||
|
||||
Else
|
||||
|
||||
msgbox "Invalid function call!" & vbCrlf & _
|
||||
"Please check the parameters!" & vbCrlf & _
|
||||
"...then restart this Script!",vbExclamation ,"LoadVBSModule: Parameter Error!"
|
||||
|
||||
End if
|
||||
|
||||
'Checking folder paths 'Check if given path is valid, if not create it
|
||||
If Not FSOModule.FolderExists(ModulePath) Then
|
||||
|
||||
FSOModule.CreateFolder(ModulePath)
|
||||
msgbox "The ModulePath doesnt exist, trying to create!" & vbCrlf & _
|
||||
"Please place your Modules there: " & vbCrlf & _
|
||||
ModulePath & vbCrlf & vbCrlf & _
|
||||
"...then restart this Script!",vbExclamation ,"LoadVBSModule: Modules / ModulePath is missing!"
|
||||
Else
|
||||
|
||||
'Clear Error Variable
|
||||
Err.Clear
|
||||
|
||||
'does the file exist? vbm is preferred!
|
||||
If FSOModule.FileExists((ModulePath & "\" & Modulename & ".vbm")) Then
|
||||
|
||||
'Building full module path and name
|
||||
ModuleFullName = ModulePath & "\" & Modulename & ".vbm"
|
||||
|
||||
'does the file exist?
|
||||
Elseif FSOModule.FileExists((ModulePath & "\" & Modulename & ".vbs")) Then
|
||||
|
||||
'Building full module path and name
|
||||
ModuleFullName = ModulePath & "\" & Modulename & ".vbs"
|
||||
|
||||
Else
|
||||
|
||||
'Otherwise set empty string var
|
||||
ModuleFullName = Empty
|
||||
|
||||
End if
|
||||
|
||||
If (ModuleFullName = Empty) Then
|
||||
|
||||
MSGBOX "ModulePath cannot be determined! " & vbCrlf & _
|
||||
"Path: " & ModulePath & "\" & Modulename & vbCrlf & _
|
||||
"",vbOkayonly+vbCritical,"ERROR: Module does NOT exist! "
|
||||
Err.Clear
|
||||
LoadVBSModule = "False"
|
||||
|
||||
Else
|
||||
|
||||
Set Module = CreateObject("ADODB.Stream")
|
||||
|
||||
'IF ADODB object could not be created, fallback
|
||||
If (Err.Number <> 0) Then
|
||||
|
||||
Set Module = FSOModule.OpenTextFile(ModuleFullName, 1)
|
||||
ModuleCode = Module.ReadAll
|
||||
Module.Close
|
||||
|
||||
Else
|
||||
|
||||
Module.CharSet = "utf-8"
|
||||
Module.Open
|
||||
Module.LoadFromFile(ModuleFullName)
|
||||
ModuleCode = Module.ReadText()
|
||||
Module.Close
|
||||
|
||||
End If
|
||||
|
||||
Set Module = Nothing
|
||||
|
||||
'Execute the file content
|
||||
ExecuteGlobal ModuleCode
|
||||
|
||||
If Err.Number <> 0 Then
|
||||
MSGBOX "Error Code: " & Err.Number & vbCrlf & _
|
||||
"Error Description: " & Err.Description & vbCrlf & _
|
||||
"Path: " & ModuleFullName & vbCrlf & _
|
||||
"",vbOkayonly+vbCritical,"ERROR: Module cannot be loaded!"
|
||||
Err.Clear
|
||||
LoadVBSModule = "False"
|
||||
Else
|
||||
LoadVBSModule = "True"
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
End Function 'LoadVBSModule
|
||||
|
||||
'------------------------------------ EXAMPLE TO CALL THE FUNCTION ------------------------------------
|
||||
|
||||
''Prepare Array (Arrays are zero based!)
|
||||
'Modules = Array("TestModule1","TestModule2","TestModule3")
|
||||
'
|
||||
' Dim Module
|
||||
'
|
||||
' 'Load external Modules.
|
||||
' For Each Module In Modules
|
||||
'
|
||||
' If (Module <> "") Then
|
||||
'
|
||||
' 'Create the array to pass in to our function
|
||||
' Dim VBSModuleParams
|
||||
'
|
||||
' 'Call the subroutine with two arguments
|
||||
' Redim VBSModuleParams(0) 'Change to 1, for 2 values
|
||||
' VBSModuleParams(0) = Module
|
||||
' 'VBSModuleParams(1) = ""
|
||||
'
|
||||
' LoadVBSModuleResult = LoadVBSModule(VBSModuleParams)
|
||||
'
|
||||
' If (LoadVBSModuleResult <> "True") Then
|
||||
'
|
||||
' 'Set WScript = CreateObject("WScript.Shell")
|
||||
' MSGBOX "Module: " & Module & " was Not succesful been loaded!" & vbCrlf & _
|
||||
' "Please load the Module and try again, running this Function/Module!" & vbCrlf & _
|
||||
' "Exiting, because of this Issue." & vbCrlf & _
|
||||
' Err.Description, vbCritical, "DEBUG Info: Cannot load Module!"
|
||||
' 'WScript.Quit = not possible in Winline enviroment
|
||||
'
|
||||
' End If 'LoadVBSModuleResult
|
||||
'
|
||||
' End If 'Module <> ""
|
||||
'
|
||||
' Next 'end for each
|
||||
'
|
||||
'TestModule1
|
||||
'TestModule2
|
||||
'TestModule3
|
||||
|
||||
'------------------------------------------------------------------------------------------------------
|
||||
@@ -0,0 +1,135 @@
|
||||
' ArticleExists(Identifier: String)
|
||||
' ---------------------------------------------------------
|
||||
' Findet Artikelnummer anhand von versch. Kriterien
|
||||
' - Artikel-Nummer, Alternative Artikel-Nummer, EAN-Code, Seriennummer
|
||||
' - Gibt die Zeile im Grid zurück in der Artikel das erste Mal gefunden wurde
|
||||
'
|
||||
' Rückgabewert: ArticleRow: Int
|
||||
' ---------------------------------------------------------
|
||||
|
||||
Const ARTICLE_EXISTS_NO_STOCK = -99
|
||||
Const ARTICLE_EXISTS_NO_SERIALNUMBER = -98
|
||||
Const ARTICLE_EXISTS_NO_ARTICLE_EAN = -97
|
||||
|
||||
Function ArticleExists(Identifier)
|
||||
ArticleExists = 0
|
||||
CURRENT_SERIALNUMBER = ""
|
||||
|
||||
Set mywin = CWLStart.CurrentModule.Windows.Item(WINDOW_ID)
|
||||
Set Grid = mywin.Controls.Item(GRID_ID).Grid
|
||||
|
||||
' ===================== ARTIKEL NUMMER / EAN-CODE =====================
|
||||
SQL = ""
|
||||
' Artikelnummer / EAN-Code / Alternative Artikelnummer
|
||||
SQL = SQL & "((C002 = '" & Identifier & "') Or (C075 = '" & Identifier & "') Or (C114 = '" & Identifier & "')) AND "
|
||||
' Artikel darf nicht inaktiv sein
|
||||
SQL = SQL & "(c038 IS NULL) "
|
||||
' Nach Mandant und Wirtschaftsjahr filtern
|
||||
SQL = SQL & SQLQuery_BasicWhere
|
||||
|
||||
Set ResultArtikel = CWLStart.CurrentCompany.SearchRecord(TABLE_21, SQL)
|
||||
|
||||
If DEBUG_ON = True Then
|
||||
AddDebugLine "Searching for Article by ArticleNo/EAN-Code.. " & vbNewline & vbNewline
|
||||
AddDebugLine "Result Columns: " & ResultArtikel & vbNewline
|
||||
AddDebugLine "Result Rows: " & ResultArtikel.RowCount & vbNewline
|
||||
AddDebugLine "SQL: " & SQL
|
||||
|
||||
ShowDebugBox "ArticleExists"
|
||||
End If
|
||||
|
||||
' ===================== SERIENNUMMER =====================
|
||||
SQL = ""
|
||||
' Artikelnummer
|
||||
SQL = SQL & "(C068 = '" & Identifier & "') AND "
|
||||
' Artikel darf nicht inaktiv sein
|
||||
SQL = SQL & "(c038 IS NULL) "
|
||||
' Nach Mandant und Wirtschaftsjahr filtern
|
||||
SQL = SQL & SQLQuery_BasicWhere
|
||||
|
||||
Set ResultSeriennummer = CWLStart.CurrentCompany.SearchRecord(TABLE_21, SQL)
|
||||
|
||||
If DEBUG_ON = True Then
|
||||
AddDebugLine "Searching for Article by Article serial number " & vbNewline & vbNewline
|
||||
AddDebugLine "Result Columns: " & ResultSeriennummer & vbNewline
|
||||
AddDebugLine "Result Rows: " & ResultSeriennummer.RowCount & vbNewline
|
||||
AddDebugLine "SQL: " & SQL
|
||||
|
||||
ShowDebugBox "ArticleExists"
|
||||
End If
|
||||
|
||||
If ResultSeriennummer.RowCount > 0 Then
|
||||
CURRENT_SERIALNUMBER = Identifier
|
||||
Set Result = ResultSeriennummer
|
||||
Else
|
||||
Set Result = ResultArtikel
|
||||
End If
|
||||
|
||||
'==========================================================
|
||||
If Result.RowCount > 0 Then
|
||||
' Wir brauchen die Hauptartikelnummer, weil die Prüfung sonst bei SN-Artikeln fehlschlägt
|
||||
MainArticleNumber = Result.Value("C011")
|
||||
RealArticleNumber = Result.Value("C002")
|
||||
|
||||
' Lagerstand des Artikels prüfen
|
||||
SQL = ""
|
||||
SQL = SQL & "SELECT "
|
||||
SQL = SQL & "(SELECT C008 AS [MengeZugang] from [v021] (NOLOCK) where (c011 = '__ARTICLENUMBER__' OR c002 = '__ARTICLENUMBER__') "& SQLQuery_BasicWhere &") - "
|
||||
SQL = SQL & "(SELECT C009 AS [MengeAbgang] from [v021] (NOLOCK) where (c011 = '__ARTICLENUMBER__' OR c002 = '__ARTICLENUMBER__') "& SQLQuery_BasicWhere &") - "
|
||||
SQL = SQL & "ISNULL((SELECT SUM(C035) AS [MengeVerkauf] FROM [t014] (NOLOCK) where c000 = '__ARTICLENUMBER__' "& SQLQuery_BasicWhere &"), 0) AS c000"
|
||||
|
||||
SQL = Replace(SQL, "__ARTICLENUMBER__", RealArticleNumber)
|
||||
|
||||
Set Result = CWLStart.CurrentCompany.Connection.Select(SQL)
|
||||
AmountStocked = Result.Value("c000")
|
||||
|
||||
If DEBUG_ON = True Then
|
||||
AddDebugLine "Checking stock of product: " & RealArticleNumber & " (" & MainArticleNumber & ")" & vbNewline & vbNewline
|
||||
AddDebugLine "Result Columns: " & Result & vbNewline
|
||||
AddDebugLine "Result Rows: " & Result.RowCount & vbNewline
|
||||
AddDebugLine "Stock: " & AmountStocked & vbNewLine
|
||||
AddDebugLine "SQL: " & SQL
|
||||
|
||||
ShowDebugBox "ArticleExists"
|
||||
End If
|
||||
|
||||
If AmountStocked > 0 Then
|
||||
If DEBUG_ON = True Then
|
||||
AddDebugLine "Amount stocked: " & AmountStocked
|
||||
ShowDebugBox "ArticleExists"
|
||||
End If
|
||||
|
||||
' Vorkommen in Tabelle prüfen
|
||||
For Row = 1 To Grid.LineCount
|
||||
CurrentArticleNumber = Grid.GetCellValue(Row, COLUMN_ARTICLENUMBER)
|
||||
Total = Cint(Grid.GetCellValue(Row, COLUMN_TOTAL))
|
||||
Scanned = Cint(Grid.GetCellValue(Row, COLUMN_SCANNED))
|
||||
|
||||
If CurrentArticleNumber = MainArticleNumber Then
|
||||
If DEBUG_ON = True Then
|
||||
AddDebugLine "CurrentArticleNumber matches MainArticleNumber! (" & CurrentArticleNumber & ")"
|
||||
ShowDebugBox "ArticleExists"
|
||||
End If
|
||||
|
||||
If Total > Scanned Then
|
||||
If DEBUG_ON = True Then
|
||||
AddDebugLine "Product is not yet scanned completetly and exists in Row " & Row & "!"
|
||||
ShowDebugBox "ArticleExists"
|
||||
End If
|
||||
|
||||
ArticleExists = Row
|
||||
Exit For
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
Else
|
||||
ArticleExists = ARTICLE_EXISTS_NO_STOCK
|
||||
End If
|
||||
Else
|
||||
If CURRENT_SERIALNUMBER = "" Then
|
||||
ArticleExists = ARTICLE_EXISTS_NO_ARTICLE_EAN
|
||||
Else
|
||||
ArticleExists = ARTICLE_EXISTS_NO_SERIALNUMBER
|
||||
End If
|
||||
End If
|
||||
End Function
|
||||
@@ -0,0 +1,199 @@
|
||||
' CompleteOrder()
|
||||
' ---------------------------------------------------------
|
||||
' Schließt die Prüfung ab und erstellt einen Lieferschein
|
||||
'
|
||||
' Rückgabewert: Keiner
|
||||
' ---------------------------------------------------------
|
||||
Sub CompleteOrder()
|
||||
Set mywin = CWLStart.CurrentModule.Windows.Item(WINDOW_ID)
|
||||
Set Conn = CWLStart.CurrentCompany.Connection
|
||||
Set Grid = mywin.Controls.Item(GRID_ID).Grid
|
||||
|
||||
Dim OrderId, AccountSQL, MandatorId, RunningNumber
|
||||
|
||||
|
||||
OrderId = mywin.Controls.Item(ORDER_INPUT).ScreenContents
|
||||
AccountSQL = "SELECT DISTINCT c021 FROM t025 (NOLOCK) WHERE c044 = '" & OrderId & "' " & SQLQuery_BasicWhere
|
||||
|
||||
Set AccountResult = Connection.Select(AccountSQL)
|
||||
|
||||
If DEBUG_ON = True Then
|
||||
AddDebugLine "Querying for CustomerAccountId.. " & vbNewline
|
||||
AddDebugLine "Result Columns: " & AccountResult
|
||||
AddDebugLine "Result Rows: " & AccountResult.RowCount
|
||||
AddDebugLine "SQL: " & AccountSQL
|
||||
|
||||
ShowDebugBox "CompleteOrder"
|
||||
End If
|
||||
|
||||
MandatorId = AccountResult.Value("c021")
|
||||
RunningNumber = RUNNING_NUMBER_PREFIX & OrderId
|
||||
BelegKey = Cstr(DateDiff("s", "01/01/1970 00:00:00", Now))
|
||||
|
||||
' ===================== KOPFDATEN =====================
|
||||
|
||||
HeadSQL = "INSERT INTO " & SQLDB_for_EXIM & "." & SQLHeadTB_for_EXIM & " "
|
||||
HeadSQL = HeadSQL & "(BELEGKEY, Kontonummer, Laufnummer, Auftragsnummer, Datum_Lieferschein) "
|
||||
HeadSQL = HeadSQL & "VALUES("& BelegKey &", '"& MandatorId &"', '"& RunningNumber &"', '"& OrderId &"', GETDATE())"
|
||||
|
||||
HeadResult = Conn.ExecuteSQL(HeadSQL)
|
||||
|
||||
If DEBUG_ON = True Then
|
||||
AddDebugLine "Inserting Head Data" & vbNewline
|
||||
AddDebugLine "Result: " & HeadResult
|
||||
AddDebugLine "SQL: " & HeadSQL
|
||||
|
||||
ShowDebugBox "CompleteOrder"
|
||||
End If
|
||||
|
||||
' ===================== ENDE KOPFDATEN =====================
|
||||
|
||||
' ===================== MITTEDATEN =====================
|
||||
|
||||
Dim ArticleNumber, AmountDelivered, SerialNumber, StorageLocation, LineNumber
|
||||
|
||||
For Row = 1 To Grid.LineCount
|
||||
IsSerialNumberArticle = Grid.GetCellValue(Row, COLUMN_TYPE)
|
||||
ArticleNumber = Grid.GetCellValue(Row, COLUMN_ARTICLENUMBER)
|
||||
SerialNumber = Grid.GetCellValue(Row, COLUMN_SERIALNUMBER)
|
||||
LineNumber = GetWinLineOriginalLineNumber(OrderId, ArticleNumber, IsSerialNumberArticle)
|
||||
StorageLocation = GetWinLineStorageLocation(ArticleNumber, SerialNumber, IsSerialNumberArticle)
|
||||
AmountDelivered = Grid.GetCellValue(Row, COLUMN_SCANNED)
|
||||
|
||||
If IsSerialNumberArticle = 1 Then
|
||||
MidSQL = "INSERT INTO " & SQLDB_for_EXIM & "." & SQLMiddleTB_for_EXIM & " "
|
||||
MidSQL = MidSQL & "(BELEGKEY, Artikelnummer, Hauptartikelnummer, Zeilennummer, Datentyp, Mengegeliefert, ChargeIdentnummer, Lagerort) "
|
||||
MidSQL = MidSQL & "VALUES("& BelegKey &", '"& ArticleNumber &"', '"& ArticleNumber &"', "& LineNumber &", '1', "& AmountDelivered &", '"& SerialNumber &"', "& StorageLocation &")"
|
||||
Else
|
||||
MidSQL = "INSERT INTO " & SQLDB_for_EXIM & "." & SQLMiddleTB_for_EXIM & " "
|
||||
MidSQL = MidSQL & "(BELEGKEY, Artikelnummer, Hauptartikelnummer, Zeilennummer, Datentyp, Mengegeliefert, ChargeIdentnummer, Lagerort) "
|
||||
MidSQL = MidSQL & "VALUES("& BelegKey &", '"& ArticleNumber &"', '"& ArticleNumber &"', NULL, '1', "& AmountDelivered &", '"& SerialNumber &"', "& StorageLocation &")"
|
||||
End If
|
||||
|
||||
MidResult = Conn.ExecuteSQL(MidSQL)
|
||||
|
||||
If DEBUG_ON = True Then
|
||||
AddDebugLine "Inserting Middle Data" & vbNewline
|
||||
AddDebugLine "Result: " & MidResult
|
||||
AddDebugLine "SQL: " & MidSQL
|
||||
|
||||
ShowDebugBox "CompleteOrder"
|
||||
End If
|
||||
Next
|
||||
|
||||
' ===================== ENDE MITTEDATEN =====================
|
||||
|
||||
' ============================ XML ============================
|
||||
Dim Request, URL, XML
|
||||
Dim DObj : DObj = Now
|
||||
Dim DateString : DateString = Year(DObj) & "-" & GetLeftPad(Month(DObj)) & "-" & GetLeftPad(Day(DObj))
|
||||
|
||||
XML = ""
|
||||
XML = XML & "<?xml version=""1.0"" encoding=""UTF-8""?>"
|
||||
XML = XML & "<MESOWebService TemplateType=""__TYPE__"" Template=""__VORLAGE__"" option=""__OPTION__"" printVoucher=""__PRINT__"">"
|
||||
|
||||
' Kopf
|
||||
XML = XML & "<__VORLAGE__T025>"
|
||||
XML = XML & "<BELEGKEY>" & BelegKey & "</BELEGKEY>"
|
||||
XML = XML & "<Kontonummer>" & MandatorId & "</Kontonummer>"
|
||||
XML = XML & "<Laufnummer>" & RunningNumber & "</Laufnummer>"
|
||||
XML = XML & "<Auftragsnummer>" & OrderId & "</Auftragsnummer>"
|
||||
XML = XML & "<Datum_Lieferschein>" & DateString & "</Datum_Lieferschein>"
|
||||
XML = XML & "</__VORLAGE__T025>"
|
||||
|
||||
For Row = 1 To Grid.LineCount
|
||||
|
||||
ArticleNumber = Grid.GetCellValue(Row, COLUMN_ARTICLENUMBER)
|
||||
SerialNumber = Grid.GetCellValue(Row, COLUMN_SERIALNUMBER)
|
||||
LineNumber = GetWinLineOriginalLineNumber(OrderId, ArticleNumber, IsSerialNumberArticle)
|
||||
StorageLocation = GetWinLineStorageLocation(ArticleNumber, SerialNumber, IsSerialNumberArticle)
|
||||
AmountDelivered = Grid.GetCellValue(Row, COLUMN_SCANNED)
|
||||
InternalArticleNumber = GetWinLineInternalProductNumber(ArticleNumber, SerialNumber)
|
||||
|
||||
' Mitte
|
||||
MidXML = ""
|
||||
MidXML = MidXML & "<__VORLAGE__T026>"
|
||||
MidXML = MidXML & "<BELEGKEY>" & BelegKey & "</BELEGKEY>"
|
||||
MidXML = MidXML & "<Artikelnummer>" & InternalArticleNumber & "</Artikelnummer>"
|
||||
MidXML = MidXML & "<Hauptartikelnummer>" & ArticleNumber & "</Hauptartikelnummer>"
|
||||
MidXML = MidXML & "<Zeilennummer>" & LineNumber & "</Zeilennummer>"
|
||||
MidXML = MidXML & "<Datentyp>" & "1" & "</Datentyp>"
|
||||
MidXML = MidXML & "<Mengegeliefert>" & AmountDelivered & "</Mengegeliefert>"
|
||||
MidXML = MidXML & "<ChargeIdentnummer>" & SerialNumber & "</ChargeIdentnummer>"
|
||||
MidXML = MidXML & "<Lagerort>" & StorageLocation & "</Lagerort>"
|
||||
MidXML = MidXML & "</__VORLAGE__T026>"
|
||||
|
||||
If DEBUG_ON = True Then
|
||||
AddDebugLine "Adding Product Row to XML:" & vbNewLine
|
||||
AddDebugLine MidXML
|
||||
|
||||
ShowDebugBox "CompleteOrder"
|
||||
End If
|
||||
|
||||
XML = XML & MidXML
|
||||
Next
|
||||
|
||||
XML = XML & "</MESOWebService>"
|
||||
XML = Replace(XML, "__VORLAGE__", WEB_VORLAGE)
|
||||
XML = Replace(XML, "__TYPE__", WEB_TYPE)
|
||||
XML = Replace(XML, "__OPTION__", WEB_OPTION)
|
||||
XML = Replace(XML, "__PRINT__", WEB_PRINT)
|
||||
|
||||
URL = "http://__SERVER__/ewlservice/import?User=__USER__&Password=__PASSWORD__&Company=__COMPANY__&Type=30&Vorlage=__VORLAGE__&Actioncode=__ACTIONCODE__&byref=0&Data=__DATA__"
|
||||
URL = Replace(URL, "__SERVER__", WEB_SERVER)
|
||||
URL = Replace(URL, "__USER__", WEB_USER)
|
||||
URL = Replace(URL, "__PASSWORD__", WEB_PASS)
|
||||
URL = Replace(URL, "__COMPANY__", WEB_COMPANY)
|
||||
URL = Replace(URL, "__VORLAGE__", WEB_VORLAGE)
|
||||
URL = Replace(URL, "__ACTIONCODE__", WEB_ACTIONCODE)
|
||||
URL = Replace(URL, "__DATA__", XML)
|
||||
|
||||
If DEBUG_ON = True Then
|
||||
AddDebugLine "Sending Request to WebServices.."
|
||||
AddDebugLine "URL: " & URL
|
||||
|
||||
ShowDebugBox "CompleteOrder"
|
||||
End If
|
||||
|
||||
' ======================= ENDE XML =======================
|
||||
|
||||
' ===================== HTTP REQUEST =====================
|
||||
|
||||
Set Request = CreateObject("MSXML2.XMLHTTP")
|
||||
Request.Open "POST", URL, False
|
||||
Request.Send
|
||||
Response = Request.ResponseText
|
||||
Status = Request.Status
|
||||
|
||||
If DEBUG_ON = True Then
|
||||
AddDebugLine "Response from WebServices!"
|
||||
AddDebugLine "Status: " & Status
|
||||
AddDebugLine "Body: " & Response
|
||||
|
||||
ShowDebugBox "CompleteOrder"
|
||||
End If
|
||||
|
||||
' =================== ENDE HTTP REQUEST ==================
|
||||
|
||||
Error = False
|
||||
Message = ""
|
||||
|
||||
If Status = 200 Then
|
||||
If InStr(Response, "<OverallSuccess>true</OverallSuccess>") > 0 Then
|
||||
Message = "Lieferschein wurde übertragen!"
|
||||
Else
|
||||
Error = True
|
||||
Message = "Lieferschein wurde nicht übertragen! Fehlerdetails: " & vbNewline & vbNewline & Response
|
||||
End If
|
||||
Else
|
||||
Error = True
|
||||
Message = "Fehler beim Zugriff auf Webservices aufgetreten" & vbNewline & "Status: " & Status
|
||||
End If
|
||||
|
||||
If Error = False Then
|
||||
MsgBox Message, vbInformation, DEFAULT_TITLE & " - Abschluss erfolgreich"
|
||||
MacroCommands.MSetFieldFocus WINDOW_ID, ORDER_INPUT
|
||||
Else
|
||||
MsgBox Message, vbExclamation, DEFAULT_TITLE & " - Fehler bei Abschluss"
|
||||
End If
|
||||
End Sub
|
||||
@@ -0,0 +1,47 @@
|
||||
' IsOrderAvailable()
|
||||
' ---------------------------------------------------------
|
||||
' Überprüft, ob Auftrag noch (teilweise) offen ist
|
||||
'
|
||||
' Rückgabewert: OrderAvailable: Boolean
|
||||
' ---------------------------------------------------------
|
||||
Function IsOrderAvailable(OrderNumber)
|
||||
Set mywin = CWLStart.CurrentModule.Windows.Item(WINDOW_ID)
|
||||
Set Grid = mywin.Controls.Item(GRID_ID).Grid
|
||||
|
||||
IsOrderAvailable = False
|
||||
|
||||
SQL = ""
|
||||
SQL = SQL & "(c044 = '"& OrderNumber &"')"
|
||||
SQL = SQL & "AND (c025 IN ('M', 'A', 'S'))"
|
||||
SQL = SQL & SQLQuery_BasicWhere
|
||||
|
||||
Set Result = CWLStart.CurrentCompany.SearchRecord(TABLE_25, SQL)
|
||||
|
||||
If DEBUG_ON = True Then
|
||||
MsgBox "SQL: ... FROM "& TABLE_25 & " WHERE " & SQL, vbOkonly, DEBUG_TITLE
|
||||
|
||||
AddDebugLine "Checking For Order by OrderId.." & vbNewline & vbNewline
|
||||
AddDebugLine "Result Columns: " & Result & vbNewline
|
||||
AddDebugLine "Result Rows: " & Result.RowCount & vbNewline
|
||||
AddDebugLine "SQL: " & SQL
|
||||
|
||||
ShowDebugBox "IsOrderAvailable"
|
||||
End If
|
||||
|
||||
If Result < 0 Then
|
||||
If err <> 0 Then
|
||||
Msgbox "Fehler bei Abfrage:" & vbNewline & err.description, vbExclamation, DEFAULT_TITLE & " - IsOrderAvailable"
|
||||
Exit Function
|
||||
Else
|
||||
Msgbox "Der Auftrag " & _
|
||||
OrderNumber & _
|
||||
" wurde bereits vollständig erledigt oder als abgeschlossen markiert!", _
|
||||
vbExclamation, DEFAULT_TITLE & " - IsOrderAvailable"
|
||||
Exit Function
|
||||
End If
|
||||
End If
|
||||
|
||||
If Result.RowCount > 0 Then
|
||||
IsOrderAvailable = True
|
||||
End If
|
||||
End Function
|
||||
@@ -0,0 +1,22 @@
|
||||
' IsOrderComplete()
|
||||
' ---------------------------------------------------------
|
||||
' Überprüft, ob alle Zeilen vollständig gescannt wurden
|
||||
'
|
||||
' Rückgabewert: OrderComplete: Boolean
|
||||
' ---------------------------------------------------------
|
||||
Function IsOrderComplete()
|
||||
Set mywin = CWLStart.CurrentModule.Windows.Item(WINDOW_ID)
|
||||
Set Grid = mywin.Controls.Item(GRID_ID).Grid
|
||||
|
||||
IsOrderComplete = True
|
||||
|
||||
For Row = 1 To Grid.LineCount
|
||||
Total = Cint(Grid.GetCellValue(Row, COLUMN_TOTAL))
|
||||
Scanned = Cint(Grid.GetCellValue(Row, COLUMN_SCANNED))
|
||||
|
||||
If Scanned < Total Then
|
||||
IsOrderComplete = False
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
End Function
|
||||
@@ -0,0 +1,111 @@
|
||||
' LoadOrder(OrderNumber: String)
|
||||
' ---------------------------------------------------------
|
||||
' Sucht Belegzeilen zur angegebenen Belegnummer
|
||||
' - Filtert Artikel der Gruppe 100 aus
|
||||
' - Lädt Ergebnisse in eine Tabelle auf dem Formular
|
||||
' - Erzeugt N Zeilen für Seriennummer-Artikel der Menge N
|
||||
'
|
||||
' Rückgabewert: LoadSuccessful: Boolean
|
||||
' ---------------------------------------------------------
|
||||
Function LoadOrder(OrderNumber)
|
||||
Set mywin = CWLStart.CurrentModule.Windows.Item(WINDOW_ID)
|
||||
Set Grid = mywin.Controls.Item(GRID_ID).Grid
|
||||
|
||||
' ARTIKEL FILTERN
|
||||
SQL = ""
|
||||
' Nach eingescannter Auftragsnummer/Belegnummer filtern
|
||||
SQL = SQL & "(c067 = '"& OrderNumber &"') "
|
||||
' Versandkosten (Art.Gruppe 100) rausfiltern
|
||||
SQL = SQL & "and c012 NOT IN (100) "
|
||||
' Nur Artikel aus offenen Belegen anzeigen
|
||||
SQL = SQL & "and c031 = c112"
|
||||
' Nach Mandant und Wirtschaftsjahr filtern
|
||||
SQL = SQL & SQLQuery_BasicWhere
|
||||
|
||||
Set Result = CWLStart.CurrentCompany.SearchRecord (TABLE_26, SQL)
|
||||
|
||||
If DEBUG_ON = True Then
|
||||
MsgBox "SQL: ... FROM "& TABLE_26 & " WHERE " & SQL, vbOkonly, DEBUG_TITLE
|
||||
|
||||
AddDebugLine "Searching For Order by OrderId.." & vbNewline & vbNewline
|
||||
AddDebugLine "Result Columns: " & Result & vbNewline
|
||||
AddDebugLine "Result Rows: " & Result.RowCount & vbNewline
|
||||
AddDebugLine "SQL: " & SQL
|
||||
|
||||
ShowDebugBox "LoadOrder"
|
||||
End If
|
||||
|
||||
If Result < 0 Then
|
||||
If err <> 0 Then
|
||||
Msgbox "Fehler bei Abfrage:" & vbNewline & err.description, vbExclamation, DEFAULT_TITLE & " - LoadOrder"
|
||||
Exit Function
|
||||
Else
|
||||
Msgbox "Abfrage lieferte keine Ergebnisse.", vbExclamation, DEFAULT_TITLE & " - LoadOrder"
|
||||
Exit Function
|
||||
End If
|
||||
End If
|
||||
|
||||
Grid.InitUserGrid
|
||||
Grid.Header
|
||||
Grid.Clear(1002)
|
||||
Grid.IsRedraw = False
|
||||
|
||||
If Result.RowCount > 0 Then
|
||||
LineCounter = 1
|
||||
|
||||
' Speicher für benutzerdefinierte Felder
|
||||
' (495,0) - Menge Gescannt
|
||||
' (495,1) - Menge Gesamt
|
||||
' (495,2) - Seriennummer
|
||||
' (495,3) - Artikelnummer
|
||||
' (495,4) - Bezeichnung
|
||||
|
||||
Do
|
||||
' Zeilen hochzählen
|
||||
Amount = Cint(Result.Value("c005"))
|
||||
ChargeFlag = Cint(Result.Value("c055"))
|
||||
|
||||
If ChargeFlag = 2 Then
|
||||
For index = 1 To Amount
|
||||
CWLCurrentWindow.ActiveWindow.Vars.Value(495,0) = 1
|
||||
CWLCurrentWindow.ActiveWindow.Vars.Value(495,1) = 0
|
||||
CWLCurrentWindow.ActiveWindow.Vars.Value(495,2) = ""
|
||||
CWLCurrentWindow.ActiveWindow.Vars.Value(495,3) = Result.Value("c003")
|
||||
CWLCurrentWindow.ActiveWindow.Vars.Value(495,4) = Result.Value("c004")
|
||||
CWLCurrentWindow.ActiveWindow.Vars.Value(495,5) = 1
|
||||
Grid.AddLine
|
||||
|
||||
' Zeilenfarbe mit ROT vorbelegen
|
||||
Grid.SetLineColor LineCounter, COLOR_RED
|
||||
|
||||
LineCounter = LineCounter + 1
|
||||
Next
|
||||
Else
|
||||
CWLCurrentWindow.ActiveWindow.Vars.Value(495,0) = Cint(Result.Value("c005"))
|
||||
CWLCurrentWindow.ActiveWindow.Vars.Value(495,1) = 0
|
||||
CWLCurrentWindow.ActiveWindow.Vars.Value(495,2) = ""
|
||||
CWLCurrentWindow.ActiveWindow.Vars.Value(495,3) = Result.Value("c003")
|
||||
CWLCurrentWindow.ActiveWindow.Vars.Value(495,4) = Result.Value("c004")
|
||||
CWLCurrentWindow.ActiveWindow.Vars.Value(495,5) = 0
|
||||
|
||||
' Ergebnisse aus SQL in Zeile schreiben
|
||||
Grid.AddLine
|
||||
|
||||
' Zeilenfarbe mit ROT vorbelegen
|
||||
Grid.SetLineColor LineCounter, COLOR_RED
|
||||
|
||||
LineCounter = LineCounter + 1
|
||||
End If
|
||||
|
||||
If Result.NextRecord = False Then
|
||||
Exit Do
|
||||
End If
|
||||
Loop
|
||||
LoadOrder = True
|
||||
Else
|
||||
MsgBox "Auftrag wurde bereits bearbeitet oder existiert nicht", vbExclamation, DEFAULT_TITLE
|
||||
LoadOrder = False
|
||||
End If
|
||||
|
||||
Grid.IsRedraw = True
|
||||
End Function
|
||||
@@ -0,0 +1,20 @@
|
||||
Function SerialNumberExists(SerialNumber)
|
||||
Set mywin = CWLStart.CurrentModule.Windows.Item(WINDOW_ID)
|
||||
Set Grid = mywin.Controls.Item(GRID_ID).Grid
|
||||
|
||||
SerialNumberExists = False
|
||||
|
||||
If DEBUG_ON = True Then
|
||||
AddDebugLine "Checking existence of SerialNumber: " & SerialNumber
|
||||
ShowDebugBox "SerialNumberExists"
|
||||
End If
|
||||
|
||||
For Row = 1 To Grid.LineCount
|
||||
CurrentSerialNumber = Grid.GetCellValue(Row, COLUMN_SERIALNUMBER)
|
||||
|
||||
If SerialNumber = CurrentSerialNumber Then
|
||||
SerialNumberExists = True
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
End Function
|
||||
@@ -0,0 +1,18 @@
|
||||
' SetAmount(Amount: Integer)
|
||||
' ---------------------------------------------------------
|
||||
' Setzt eigegeben Menge in das Mengenfeld
|
||||
' - Überschreibt Menge beim ersten Eintrag, danach
|
||||
' wird die Zahl angehängt
|
||||
'
|
||||
' Rückgabewert: Keiner
|
||||
' ---------------------------------------------------------
|
||||
Sub SetAmount(Amount)
|
||||
Set mywin = CWLStart.CurrentModule.Windows.Item(WINDOW_ID)
|
||||
Set amountBox = mywin.Controls.Item(AMOUNT_INPUT)
|
||||
|
||||
If amountBox.Contents = AMOUNT_PLACEHOLDER Then
|
||||
amountBox.Contents = Cstr(Amount)
|
||||
Else
|
||||
amountBox.Contents = amountBox.Contents & Cstr(Amount)
|
||||
End If
|
||||
End Sub
|
||||
@@ -0,0 +1,39 @@
|
||||
Sub SetupWindow()
|
||||
Set mywin = CWLStart.CurrentModule.Windows.Item(WINDOW_ID)
|
||||
Set Grid = mywin.Controls.Item(GRID_ID).Grid
|
||||
|
||||
' Speicher für benutzerdefinierte Felder
|
||||
' (495,0) - Menge Gescannt
|
||||
' (495,1) - Menge Gesamt
|
||||
' (495,2) - Seriennummer
|
||||
' (495,3) - Artikelnummer
|
||||
' (495,4) - Bezeichnung
|
||||
' (495,5) - Chargen-/Identflag
|
||||
CWLCurrentWindow.ActiveWindow.Vars.CreateVar 495, 0, "2", 10
|
||||
CWLCurrentWindow.ActiveWindow.Vars.CreateVar 495, 1, "2", 10
|
||||
CWLCurrentWindow.ActiveWindow.Vars.CreateVar 495, 2, "1", 20
|
||||
CWLCurrentWindow.ActiveWindow.Vars.CreateVar 495, 3, "1", 20
|
||||
CWLCurrentWindow.ActiveWindow.Vars.CreateVar 495, 4, "1", 60
|
||||
CWLCurrentWindow.ActiveWindow.Vars.CreateVar 495, 5, "2", 3
|
||||
|
||||
Grid.InitUserGrid
|
||||
Grid.IsRedraw = False
|
||||
Grid.Header
|
||||
|
||||
If COLUMNS_CREATED = False Then
|
||||
COLUMN_ARTICLENUMBER = Grid.AddColumn("Artikelnummer", "T21,Artikelnummer", "1","V",0,495,3,20,scrtflag+sizeflag+hideflag)
|
||||
COLUMN_DESCRIPTION = Grid.AddColumn("Bezeichnung", "T21,Bezeichnung", "1","V",0,495,4,30,scrtflag+sizeflag+hideflag)
|
||||
COLUMN_TOTAL = Grid.AddColumn("Gesamt", "T22,Gesamt", "1","V",0,495,0,10,scrtflag+sizeflag+hideflag)
|
||||
COLUMN_SCANNED = Grid.AddColumn("Gescannt", "T22,Gescannt", "1","V",0,495,1,10,scrtflag+sizeflag+hideflag)
|
||||
COLUMN_SERIALNUMBER = Grid.AddColumn("Seriennummer", "T21,Seriennummer", "l","V",0,495,2,20,scrtflag+sizeflag+hideflag)
|
||||
COLUMN_TYPE = Grid.AddColumn("SN-Artikel", "T17,Artikeltyp", "l","V",0,495,5,5,scrtflag+sizeflag+hideflag)
|
||||
COLUMNS_CREATED = True
|
||||
End If
|
||||
|
||||
Grid.IsRedraw = True
|
||||
|
||||
Set amountBox = mywin.Controls.Item(AMOUNT_INPUT)
|
||||
amountBox.Contents = AMOUNT_PLACEHOLDER
|
||||
|
||||
MacroCommands.MSetFieldFocus WINDOW_ID, ORDER_INPUT
|
||||
End Sub
|
||||
@@ -0,0 +1,45 @@
|
||||
' UpdateArticleRow(RowNumber: Integer)
|
||||
' ---------------------------------------------------------
|
||||
' Trägt die gescannte Menge eines Artikel in das Grid ein
|
||||
' - Ändert die Farbe, abhängig von Gesamtmenge und Gescannte Menge
|
||||
'
|
||||
' Rückgabewert: Keiner
|
||||
' ---------------------------------------------------------
|
||||
Sub UpdateArticleRow(RowNumber)
|
||||
Set mywin = CWLStart.CurrentModule.Windows.Item(WINDOW_ID)
|
||||
Set Grid = mywin.Controls.Item(GRID_ID).Grid
|
||||
Set amountBox = mywin.Controls.Item(AMOUNT_INPUT)
|
||||
DebugMessage = ""
|
||||
|
||||
' Bereits gescannte, Gesamt und Anzahl zu Scannen auslesen
|
||||
Total = Cint(Grid.GetCellValue(RowNumber, COLUMN_TOTAL))
|
||||
Scanned = Cint(Grid.GetCellValue(RowNumber, COLUMN_SCANNED))
|
||||
ScannedAmount = Cint(amountBox.Contents)
|
||||
|
||||
' Neue bereits gescannte berechnen
|
||||
NewScanned = Scanned + ScannedAmount
|
||||
|
||||
If DEBUG_ON = True Then
|
||||
AddDebugLine "Total " & Total & vbNewline
|
||||
AddDebugLine "Scanned: " & Scanned & vbNewline
|
||||
AddDebugLine "NewScanned: " & NewScanned & vbNewline
|
||||
|
||||
ShowDebugBox "UpdateArticleRow"
|
||||
End If
|
||||
|
||||
' Zeilenfarbe anpassen:
|
||||
' GRÜN: Komplett gescannt
|
||||
' GELB: Teilweise gescannt
|
||||
If NewScanned = Total Then
|
||||
Grid.SetLineColor RowNumber, COLOR_GREEN
|
||||
Grid.SetCellValue RowNumber, COLUMN_SCANNED, NewScanned
|
||||
Elseif NewScanned < Total Then
|
||||
Grid.SetLineColor RowNumber, COLOR_YELLOW
|
||||
Grid.SetCellValue RowNumber, COLUMN_SCANNED, NewScanned
|
||||
Else
|
||||
Message = ""
|
||||
Message = Message & "Eingegebene Menge überschreitet die Gesamt-Anzahl oder" & vbNewline
|
||||
Message = Message & "Artikel wurde bereits vollständig gescannt!"
|
||||
Msgbox Message, vbExclamation, DEFAULT_TITLE
|
||||
End If
|
||||
End Sub
|
||||
@@ -0,0 +1,451 @@
|
||||
Function Read-ConfigFile {
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Function will read the given ConfigFile, and returns Values or creates Profiles.
|
||||
|
||||
.DESCRIPTION
|
||||
This Function will get Script configurations from a ASCII/ANSI based ConfigFile (INI).
|
||||
The important criterion is, that every Value the should be read, has to look like this: ConfigLabel = ConfigValue
|
||||
The ConfigFile should be formated within UTF8 and every Line in a ConfigFile which is beginning with a "#", will be ignored!
|
||||
By calling this Function the first time, it will read the ConfigFile and save its content into the Variable ConfigFileValues.
|
||||
In the same call or later calls you can instruct this Function to Return a value for a searched pattern (ConfigLabel).
|
||||
If nothing was found, Function will try to get a FailSafe Setting (predefined global Variable in Script), if even this fails it will Return $NULL.
|
||||
Depending on the way your calling this Function, it can return a single Value for a searched ConfigLabel like: $LogPath = E:\Logs,
|
||||
or it can return multiple Values like; $Domains = .*@my-domain.com;'.*@my-second-domain.com',
|
||||
or it can create multiple Profiles with single or multiple Values and only returning the Count of the created Profiles.
|
||||
|
||||
.REQUIREMENT General
|
||||
PowerShell V2
|
||||
|
||||
.REQUIREMENT Assembly
|
||||
<NONE>
|
||||
|
||||
.REQUIREMENT Variables
|
||||
ConfigFile, ConfigLabel, ConfigValue, ConfigValues, ConfigLinesValue, ConfigLinesValueSeparator, FileTest, Item, Items, ItemValue, ItemValues, ItemValuesTEMP
|
||||
|
||||
.REQUIREMENT Variables preSet
|
||||
ConfigFile
|
||||
|
||||
.REQUIREMENT Functions
|
||||
<NONE>
|
||||
|
||||
.VERSION
|
||||
Number: 2.0.0.0 / Date: 16.02.2017
|
||||
|
||||
.PARAMETER ConfigFile
|
||||
Give the full path to the ConfigFile (eg. <ScriptName>_Settings.ini). (Default: If you dont give it, Function will try the retrieve ConfigFile (Path and Name) from the Global Variables, set by the calling Script.)
|
||||
|
||||
.PARAMETER ConfigLabel
|
||||
Give the ConfigLabel, you are looking for a Value.
|
||||
|
||||
.PARAMETER ConfigLinesValue
|
||||
Optional Parameter. Select "MultiValue", if in one Line are multiple Values (eg. Array List) separated by "$ConfigLinesValueSeparator". (Default: "SingleValue").
|
||||
|
||||
.PARAMETER ConfigLinesValueSeparator
|
||||
Optional Parameter. Which declares the symbol or character for Value separation (Default: ';').
|
||||
|
||||
.PARAMETER ConfigLines
|
||||
Optional Parameter. Select how many Lines from ConfigFile you expect to get returned. Use Values higher than 1, to work with Profiles. If you do, Function will set Variables and just returns how many are created! (Default: 1).
|
||||
|
||||
.PARAMETER Force
|
||||
Optional Parameter. By using the Force Parameter, ConfigFile will be reloaded.
|
||||
|
||||
.EXAMPLE
|
||||
Set-Variable -Scope Global -Name LogPaths -Value (Read-ConfigFile -ConfigFile "<Path>\<ScriptName>_Settings.ini" -ConfigLabel LogPath) -Force
|
||||
|
||||
.EXAMPLE
|
||||
Set-Variable -Scope Global -Name ListofValues -Value (Read-ConfigFile -ConfigLabel ListofValues -ConfigLinesValue MultiValue) -Force
|
||||
|
||||
.EXAMPLE
|
||||
Set-Variable -Scope Global -Name ProfileCount -Value (Read-ConfigFile -ConfigLabel Profile -ConfigLines 999) -Force
|
||||
|
||||
.EXAMPLE
|
||||
Set-Variable -Scope Global -Name ProfileCount -Value (Read-ConfigFile -ConfigLabel Profile -ConfigLines 999 -ConfigLinesValue MultiValue) -Force
|
||||
|
||||
.EXAMPLE
|
||||
Set-Variable -Scope Global -Name ProfileCount -Value (Read-ConfigFile -ConfigLabel Profile -ConfigLines 999 -ConfigLinesValue MultiValue -ConfigLinesValueSeparator |) -Force
|
||||
#>
|
||||
|
||||
Param (
|
||||
|
||||
[Parameter(Position=0,Mandatory=$False,HelpMessage='Give the full path to the ConfigFile (eg. <ScriptName>_Settings.ini). (Default: If you dont give it, Function will try the retrieve ConfigFile (Path and Name) from the Global Variables, set by the calling Script.)')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$ConfigFile=(Get-Variable -Name ConfigFile -Scope Global -ValueOnly),
|
||||
|
||||
[Parameter(Position=1,Mandatory=$True,HelpMessage='Give the ConfigLabel, you are looking for a Value.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$ConfigLabel=$NULL,
|
||||
|
||||
[Parameter(Position=2,Mandatory=$False,HelpMessage='Optional Parameter. Select "MultiValue", if in one Line are multiple Values (eg. Array List) separated by "$ConfigLinesValueSeparator". (Default: "SingleValue").')]
|
||||
[ValidateSet("SingleValue","MultiValue")]
|
||||
[String]$ConfigLinesValue="SingleValue",
|
||||
|
||||
[Parameter(Position=3,Mandatory=$False,HelpMessage='Optional Parameter. Which declares the symbol or character for Value separation (Default: ";").')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$ConfigLinesValueSeparator=';',
|
||||
|
||||
[Parameter(Position=4,Mandatory=$False,HelpMessage='Optional Parameter. Select how many Lines from ConfigFile you expect to get returned. Use Values higher than 1, to work with Profiles. If you do, Function will set Variables and just returns how many are created! (Default: 1).')]
|
||||
[ValidateRange(0,1000)]
|
||||
[Int]$ConfigLines=1,
|
||||
|
||||
[Parameter(Position=5,Mandatory=$False,HelpMessage='Optional Parameter. By using the Force Parameter, ConfigFile will be reloaded.')]
|
||||
[Switch]$Force
|
||||
|
||||
) #end param
|
||||
|
||||
#Clear Error Variable
|
||||
$error.clear()
|
||||
|
||||
#If ConfigFile wasnt read, do this at first
|
||||
IF ((($ConfigFile) -and (!$ConfigValues)) -or ($Force -eq $True)) {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ConfigFile has not been evaluated jet..."
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Checking for ConfigFile: $ConfigFile"
|
||||
$FileTest = Test-Path -PathType Leaf $ConfigFile
|
||||
|
||||
IF ($FileTest -eq $True) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ConfigFile does exists!"
|
||||
|
||||
Try {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Getting Values from ConfigFile."
|
||||
Set-Variable -Name ConfigValues -Value (Select-String -Path $ConfigFile -pattern "=" | where {-not($_-match ":[0-9]{1,}:#")}) -Scope Global
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Cannot get Values from ConfigFile."
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Unexpected Error!"
|
||||
Write-Host $Error
|
||||
EXIT
|
||||
|
||||
} #end catch
|
||||
|
||||
Finally {
|
||||
|
||||
IF (!$ConfigValues) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Found no valid Values in ConfigFile!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Unexpected Error!"
|
||||
Write-Host $Error
|
||||
EXIT
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Found"$ConfigValues.count"Lines in ConfigFile!."
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: These are:"
|
||||
|
||||
FOREACH ($ConfigValue in $ConfigValues) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: $($ConfigValue)"
|
||||
|
||||
}# end foreach
|
||||
|
||||
} #end else
|
||||
|
||||
} #end finally
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ConfigFile does not exists!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Unexpected Error!"
|
||||
Write-Host $Error
|
||||
EXIT
|
||||
|
||||
} #end else
|
||||
|
||||
} #end if
|
||||
|
||||
#If ConfigFile was read
|
||||
IF (($ConfigFile) -and ($ConfigValues)) {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ConfigFile has been evaluated."
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: You are looking for: $ConfigLabel."
|
||||
|
||||
[Array]$Items = $NULL
|
||||
[Array]$Items = ($ConfigValues.line | select-string -pattern "$ConfigLabel" | Select-Object -First $ConfigLines)
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Line(s) in ConfigFile -> $Items"
|
||||
|
||||
#If no Line was found
|
||||
IF ($($Items.count) -lt 1) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ($ConfigLabel) seems not to exist in ConfigFile."
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: FailSafe Setting will be used, if there was one..."
|
||||
|
||||
Try {
|
||||
|
||||
$Items = (Get-Variable -Name $ConfigLabel -ValueOnly -Scope Global -ErrorAction Stop)
|
||||
|
||||
IF ($Items) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: FailSafe returning: $Items"
|
||||
Return $Items
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: FailSafe returning nothing."
|
||||
Return $NULL
|
||||
|
||||
} #end else
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Error reading ConfigValue!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: FailSafe returning nothing."
|
||||
Return $NULL
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
#If exactly one Line was found
|
||||
ELSEIF ($($Items.count) -eq 1) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Found exactly one Line!"
|
||||
[Array]$Item = $Items
|
||||
|
||||
[Array]$Item = ($Item -split "=",2)
|
||||
[String]$ItemName = $Item[0]
|
||||
[String]$ItemName = ($ItemName.TrimStart())
|
||||
[String]$ItemName = ($ItemName.TrimEnd())
|
||||
[String]$ItemValues = $Item[1]
|
||||
[String]$ItemValues = ($ItemValues.TrimStart())
|
||||
[String]$ItemValues = ($ItemValues.TrimEnd())
|
||||
|
||||
#If exactly one Line was found, but has no Value inside!
|
||||
IF (!$ItemValues) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ($ConfigLabel) seems to exist, but is not configured jet."
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: FailSafe Setting will be used, if was configured!"
|
||||
|
||||
Try {
|
||||
|
||||
$ItemValues = (Get-Variable -Name $ConfigLabel -ValueOnly -Scope Global -ErrorAction Stop)
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: FailSafe returning: $ItemValues"
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Error reading ConfigValue!"
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
#Check again after looking for FailSafe Settings...
|
||||
IF (!$ItemValues) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Returning NULL, because nothing was found!"
|
||||
Return $NULL
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
IF ($ConfigLinesValue -eq "SingleValue") {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Looking for SingleValue Lines."
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Value -> $ItemValues"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Returning Datatyp: String"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
Return [String]$ItemValues
|
||||
|
||||
} #end if
|
||||
|
||||
ELSEIF ($ConfigLinesValue -eq "MultiValue") {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Looking for MultiValue Lines,"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: which are separated by a: $ConfigLinesValueSeparator"
|
||||
|
||||
#Prepare Arrays
|
||||
[Array]$ItemValues = $ItemValues -split "$ConfigLinesValueSeparator"
|
||||
[System.Collections.ArrayList]$ItemValuesTEMP = @()
|
||||
|
||||
#Rebuild the Array, to remove possible Blanks
|
||||
FOREACH ($ItemValue in $ItemValues) {
|
||||
|
||||
IF ($ItemValue) {
|
||||
|
||||
#The "| Out-Null" is VERY important, otherwise the Array will be f**ked!
|
||||
$ItemValue = ($ItemValue.TrimStart())
|
||||
$ItemValue = ($ItemValue.TrimEnd())
|
||||
$ItemValuesTEMP.Add("$ItemValue") | Out-null
|
||||
|
||||
} #end if
|
||||
|
||||
} #end foreach
|
||||
|
||||
[Array]$ItemValues = $NULL
|
||||
[Array]$ItemValues = $ItemValuesTEMP
|
||||
|
||||
IF ($($ItemValues.count) -eq 1) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Found $($ItemValues.count) Array Item!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Value -> $ItemValues"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Returning Datatyp: String"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
Return [String]$ItemValues
|
||||
|
||||
} #end if
|
||||
|
||||
ELSEIF ($($ItemValues.count) -gt 1) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Found $($ItemValues.count) Array Items!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Values -> $ItemValues"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Returning Datatyp: Array"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
Return [Array]$ItemValues
|
||||
|
||||
} #end elseif
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Found $($ItemValues.count) Array Item(s)!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Value(s) -> $ItemValues"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Returning Datatyp: $($ItemValues.gettype())"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
Return $ItemValues
|
||||
|
||||
} #end else
|
||||
|
||||
} #end elseif
|
||||
|
||||
} #end else
|
||||
|
||||
} #end elseif
|
||||
|
||||
#If multiple Lines are found
|
||||
ELSEIF ($($Items.count) -gt 1) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Found multiple ($($Items.count)) Lines!"
|
||||
[Int]$Counter1 = 0
|
||||
|
||||
FOREACH ($Item in $Items) {
|
||||
|
||||
[Array]$Item = ($Item -split "=",2)
|
||||
[String]$ItemName = $Item[0]
|
||||
[String]$ItemName = ($ItemName.TrimStart())
|
||||
[String]$ItemName = ($ItemName.TrimEnd())
|
||||
[String]$ItemValues = $Item[1]
|
||||
[String]$ItemValues = ($ItemValues.TrimStart())
|
||||
[String]$ItemValues = ($ItemValues.TrimEnd())
|
||||
|
||||
IF (($ItemName) -and ($ItemValues)) {
|
||||
|
||||
[Int]$Counter1++ | Out-Null
|
||||
|
||||
IF ($ConfigLinesValue -eq "SingleValue") {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Looking for SingleValue Lines."
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: -> $ItemValues"
|
||||
|
||||
} #end if
|
||||
|
||||
ELSEIF ($ConfigLinesValue -eq "MultiValue") {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Looking for MultiValue Lines,"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: which are separated by a: $ConfigLinesValueSeparator"
|
||||
|
||||
#Rebuild the Array, to remove possible Blanks
|
||||
[Array]$ItemValues = $ItemValues -split "$ConfigLinesValueSeparator"
|
||||
[System.Collections.ArrayList]$ItemValuesTEMP = @()
|
||||
|
||||
FOREACH ($ItemValue in $ItemValues) {
|
||||
|
||||
IF ($ItemValue) {
|
||||
|
||||
#The "| Out-Null" is VERY important, otherwise the Array will be f**ked!
|
||||
$ItemValue = ($ItemValue.TrimStart())
|
||||
$ItemValue = ($ItemValue.TrimEnd())
|
||||
$ItemValuesTEMP.Add("$ItemValue") | Out-null
|
||||
|
||||
} #end if
|
||||
|
||||
} #end foreach
|
||||
|
||||
[Array]$ItemValues = $NULL
|
||||
[Array]$ItemValues = $ItemValuesTEMP
|
||||
|
||||
} #end elseif
|
||||
|
||||
IF ($($ItemValues.count) -eq 1) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Found $($ItemValues.count) Array Item!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Setting Variable: $($ItemName+$Counter1)"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: with Value -> $ItemValues"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: in Datatyp: String"
|
||||
Set-Variable -Name ($ItemName+$Counter1) -Value ([String]$ItemValues) -Scope Global
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
|
||||
} #end if
|
||||
|
||||
ELSEIF ($($ItemValues.count) -gt 1) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Found $($ItemValues.count) Array Item(s)!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Setting Variable: $($ItemName+$Counter1)"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: with Value(s) -> $ItemValues"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: in Datatyp: Array"
|
||||
Set-Variable -Name ($ItemName+$Counter1) -Value @([Array]$ItemValues) -Scope Global
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
|
||||
} #end elseif
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Found $($ItemValues.count) Array Item(s)!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Setting Variable: $($ItemName+$Counter1)"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: with Value(s) -> $ItemValues"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: in Datatyp: $($ItemValues.gettype() | Select BaseType)"
|
||||
Set-Variable -Name ($ItemName+$Counter1) -Value $ItemValues -Scope Global
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
|
||||
} #end else
|
||||
|
||||
} #end if
|
||||
|
||||
} #end foreach
|
||||
|
||||
#Return how many Profiles were are created!
|
||||
Return [Int]$Counter1
|
||||
|
||||
} #end elseif
|
||||
|
||||
#That shouldnt be happen...
|
||||
ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Error reading ConfigValues!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Exiting, because of this Issue."
|
||||
Write-Host $Error
|
||||
EXIT
|
||||
|
||||
} #end else
|
||||
|
||||
} #end elseif
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Invalid ConfigValues from ConfigFile!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Please check the Description of this Function"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: and the ConfigFile!"
|
||||
|
||||
} #end else
|
||||
|
||||
} #end function
|
||||
@@ -0,0 +1,452 @@
|
||||
Function Read-ConfigFile {
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Function will read the given ConfigFile, and returns Values or creates Profiles.
|
||||
|
||||
.DESCRIPTION
|
||||
This Function will get Script configurations from a ASCII/ANSI based ConfigFile (INI).
|
||||
The important criterion is, that every Value the should be read, has to look like this: ConfigLabel = ConfigValue
|
||||
The ConfigFile should be formated within UTF8 and every Line in a ConfigFile which is beginning with a "#", will be ignored!
|
||||
By calling this Function the first time, it will read the ConfigFile and save its content into the Variable ConfigFileValues.
|
||||
In the same call or later calls you can instruct this Function to Return a value for a searched pattern (ConfigLabel).
|
||||
If nothing was found, Function will try to get a FailSafe Setting (predefined global Variable in Script), if even this fails it will Return $NULL.
|
||||
Depending on the way your calling this Function, it can return a single Value for a searched ConfigLabel like: $LogPath = E:\Logs,
|
||||
or it can return multiple Values like; $Domains = .*@my-domain.com;'.*@my-second-domain.com',
|
||||
or it can create multiple Profiles with single or multiple Values and only returning the Count of the created Profiles.
|
||||
|
||||
.REQUIREMENT General
|
||||
PowerShell V2
|
||||
|
||||
.REQUIREMENT Assembly
|
||||
<NONE>
|
||||
|
||||
.REQUIREMENT Variables
|
||||
ConfigFile, ConfigLabel, ConfigValue, ConfigValues, ConfigLinesValue, ConfigLinesValueSeparator, FileTest, Item, Items, ItemValue, ItemValues, ItemValuesTEMP
|
||||
|
||||
.REQUIREMENT Variables preSet
|
||||
ConfigFile
|
||||
|
||||
.REQUIREMENT Functions
|
||||
<NONE>
|
||||
|
||||
.VERSION
|
||||
Number: 2.0.0.0 / Date: 16.02.2017
|
||||
|
||||
.PARAMETER ConfigFile
|
||||
Give the full path to the ConfigFile (eg. <ScriptName>_Settings.ini). (Default: If you dont give it, Function will try the retrieve ConfigFile (Path and Name) from the Global Variables, set by the calling Script.)
|
||||
|
||||
.PARAMETER ConfigLabel
|
||||
Give the ConfigLabel, you are looking for a Value.
|
||||
|
||||
.PARAMETER ConfigLinesValue
|
||||
Optional Parameter. Select "MultiValue", if in one Line are multiple Values (eg. Array List) separated by "$ConfigLinesValueSeparator". (Default: "SingleValue").
|
||||
|
||||
.PARAMETER ConfigLinesValueSeparator
|
||||
Optional Parameter. Which declares the symbol or character for Value separation (Default: ';').
|
||||
|
||||
.PARAMETER ConfigLines
|
||||
Optional Parameter. Select how many Lines from ConfigFile you expect to get returned. Use Values higher than 1, to work with Profiles. If you do, Function will set Variables and just returns how many are created! (Default: 1).
|
||||
|
||||
.PARAMETER Force
|
||||
Optional Parameter. By using the Force Parameter, ConfigFile will be reloaded.
|
||||
|
||||
.EXAMPLE
|
||||
Set-Variable -Scope Global -Name LogPaths -Value (Read-ConfigFile -ConfigFile "<Path>\<ScriptName>_Settings.ini" -ConfigLabel LogPath) -Force
|
||||
|
||||
.EXAMPLE
|
||||
Set-Variable -Scope Global -Name ListofValues -Value (Read-ConfigFile -ConfigLabel ListofValues -ConfigLinesValue MultiValue) -Force
|
||||
|
||||
.EXAMPLE
|
||||
Set-Variable -Scope Global -Name ProfileCount -Value (Read-ConfigFile -ConfigLabel Profile -ConfigLines 999) -Force
|
||||
|
||||
.EXAMPLE
|
||||
Set-Variable -Scope Global -Name ProfileCount -Value (Read-ConfigFile -ConfigLabel Profile -ConfigLines 999 -ConfigLinesValue MultiValue) -Force
|
||||
|
||||
.EXAMPLE
|
||||
Set-Variable -Scope Global -Name ProfileCount -Value (Read-ConfigFile -ConfigLabel Profile -ConfigLines 999 -ConfigLinesValue MultiValue -ConfigLinesValueSeparator |) -Force
|
||||
#>
|
||||
|
||||
Param (
|
||||
|
||||
[Parameter(Position=0,Mandatory=$False,HelpMessage='Give the full path to the ConfigFile (eg. <ScriptName>_Settings.ini). (Default: If you dont give it, Function will try the retrieve ConfigFile (Path and Name) from the Global Variables, set by the calling Script.)')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$ConfigFile=(Get-Variable -Name ConfigFile -Scope Global -ValueOnly),
|
||||
|
||||
[Parameter(Position=1,Mandatory=$True,HelpMessage='Give the ConfigLabel, you are looking for a Value.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$ConfigLabel=$NULL,
|
||||
|
||||
[Parameter(Position=2,Mandatory=$False,HelpMessage='Optional Parameter. Select "MultiValue", if in one Line are multiple Values (eg. Array List) separated by "$ConfigLinesValueSeparator". (Default: "SingleValue").')]
|
||||
[ValidateSet("SingleValue","MultiValue")]
|
||||
[String]$ConfigLinesValue="SingleValue",
|
||||
|
||||
[Parameter(Position=3,Mandatory=$False,HelpMessage='Optional Parameter. Which declares the symbol or character for Value separation (Default: ";").')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$ConfigLinesValueSeparator=';',
|
||||
|
||||
[Parameter(Position=4,Mandatory=$False,HelpMessage='Optional Parameter. Select how many Lines from ConfigFile you expect to get returned. Use Values higher than 1, to work with Profiles. If you do, Function will set Variables and just returns how many are created! (Default: 1).')]
|
||||
[ValidateRange(0,1000)]
|
||||
[Int]$ConfigLines=1,
|
||||
|
||||
[Parameter(Position=5,Mandatory=$False,HelpMessage='Optional Parameter. By using the Force Parameter, ConfigFile will be reloaded.')]
|
||||
[Switch]$Force
|
||||
|
||||
) #end param
|
||||
|
||||
#Clear Error Variable
|
||||
$error.clear()
|
||||
|
||||
#If ConfigFile wasnt read, do this at first
|
||||
IF ((($ConfigFile) -and (!$ConfigValues)) -or ($Force -eq $True)) {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ConfigFile has not been evaluated jet..."
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Checking for ConfigFile: $ConfigFile"
|
||||
$FileTest = Test-Path -PathType Leaf $ConfigFile
|
||||
|
||||
IF ($FileTest -eq $True) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ConfigFile does exists!"
|
||||
|
||||
Try {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Getting Values from ConfigFile."
|
||||
Set-Variable -Name ConfigValues -Value (Select-String -Path $ConfigFile -pattern "=" | where {-not($_-match ":[0-9]{1,}:#")}) -Scope Global
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Cannot get Values from ConfigFile."
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Unexpected Error!"
|
||||
Write-Host $Error
|
||||
EXIT
|
||||
|
||||
} #end catch
|
||||
|
||||
Finally {
|
||||
|
||||
IF (!$ConfigValues) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Found no valid Values in ConfigFile!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Unexpected Error!"
|
||||
Write-Host $Error
|
||||
EXIT
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Found"$ConfigValues.count"Lines in ConfigFile!."
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: These are:"
|
||||
|
||||
FOREACH ($ConfigValue in $ConfigValues) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: $($ConfigValue)"
|
||||
|
||||
}# end foreach
|
||||
|
||||
} #end else
|
||||
|
||||
} #end finally
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ConfigFile does not exists!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Unexpected Error!"
|
||||
Write-Host $Error
|
||||
EXIT
|
||||
|
||||
} #end else
|
||||
|
||||
} #end if
|
||||
|
||||
#If ConfigFile was read
|
||||
IF (($ConfigFile) -and ($ConfigValues)) {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ConfigFile has been evaluated."
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: You are looking for: $ConfigLabel."
|
||||
|
||||
[Array]$Items = $NULL
|
||||
[Array]$Items = ($ConfigValues.line | select-string -pattern "$ConfigLabel" | Select-Object -First $ConfigLines)
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Line(s) in ConfigFile -> $Items"
|
||||
|
||||
#If no Line was found
|
||||
IF ($($Items.count) -lt 1) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ($ConfigLabel) seems not to exist in ConfigFile."
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: FailSafe Setting will be used, if there was one..."
|
||||
|
||||
Try {
|
||||
|
||||
$Items = (Get-Variable -Name $ConfigLabel -ValueOnly -Scope Global -ErrorAction Stop)
|
||||
|
||||
IF ($Items) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: FailSafe returning: $Items"
|
||||
Return $Items
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: FailSafe returning nothing."
|
||||
Return $NULL
|
||||
|
||||
} #end else
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Error reading ConfigValue!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: FailSafe returning nothing."
|
||||
Return $NULL
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
#If exactly one Line was found
|
||||
ELSEIF ($($Items.count) -eq 1) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Found exactly one Line!"
|
||||
[Array]$Item = $Items
|
||||
|
||||
[Array]$Item = ($Item -split "=",2)
|
||||
[String]$ItemName = $Item[0]
|
||||
[String]$ItemName = ($ItemName.TrimStart())
|
||||
[String]$ItemName = ($ItemName.TrimEnd())
|
||||
[String]$ItemValues = $Item[1]
|
||||
[String]$ItemValues = ($ItemValues.TrimStart())
|
||||
[String]$ItemValues = ($ItemValues.TrimEnd())
|
||||
|
||||
#If exactly one Line was found, but has no Value inside!
|
||||
IF (!$ItemValues) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ($ConfigLabel) seems to exist, but is not configured jet."
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: FailSafe Setting will be used, if was configured!"
|
||||
|
||||
Try {
|
||||
|
||||
$ItemValues = (Get-Variable -Name $ConfigLabel -ValueOnly -Scope Global -ErrorAction Stop)
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: FailSafe returning: $ItemValues"
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Error reading ConfigValue!"
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
#Check again after looking for FailSafe Settings...
|
||||
IF (!$ItemValues) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Returning NULL, because nothing was found!"
|
||||
Return $NULL
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
IF ($ConfigLinesValue -eq "SingleValue") {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Looking for SingleValue Lines."
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Value -> $ItemValues"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Returning Datatyp: String"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
Return [String]$ItemValues
|
||||
|
||||
} #end if
|
||||
|
||||
ELSEIF ($ConfigLinesValue -eq "MultiValue") {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Looking for MultiValue Lines,"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: which are separated by a: $ConfigLinesValueSeparator"
|
||||
|
||||
#Prepare Arrays
|
||||
[Array]$ItemValues = $ItemValues -split "$ConfigLinesValueSeparator"
|
||||
[System.Collections.ArrayList]$ItemValuesTEMP = @()
|
||||
|
||||
#Rebuild the Array, to remove possible Blanks
|
||||
FOREACH ($ItemValue in $ItemValues) {
|
||||
|
||||
IF ($ItemValue) {
|
||||
|
||||
#The "| Out-Null" is VERY important, otherwise the Array will be f**ked!
|
||||
$ItemValue = ($ItemValue.TrimStart())
|
||||
$ItemValue = ($ItemValue.TrimEnd())
|
||||
$ItemValuesTEMP.Add("$ItemValue") | Out-null
|
||||
|
||||
} #end if
|
||||
|
||||
} #end foreach
|
||||
|
||||
[Array]$ItemValues = $NULL
|
||||
[Array]$ItemValues = $ItemValuesTEMP
|
||||
|
||||
IF ($($ItemValues.count) -eq 1) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Found $($ItemValues.count) Array Item!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Value -> $ItemValues"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Returning Datatyp: String"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
Return [String]$ItemValues
|
||||
|
||||
} #end if
|
||||
|
||||
ELSEIF ($($ItemValues.count) -gt 1) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Found $($ItemValues.count) Array Items!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Values -> $ItemValues"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Returning Datatyp: Array"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
Return [Array]$ItemValues
|
||||
|
||||
} #end elseif
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Found $($ItemValues.count) Array Item(s)!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Value(s) -> $ItemValues"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Returning Datatyp: $($ItemValues.gettype())"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
Return $ItemValues
|
||||
|
||||
} #end else
|
||||
|
||||
} #end elseif
|
||||
|
||||
} #end else
|
||||
|
||||
} #end elseif
|
||||
|
||||
#If multiple Lines are found
|
||||
ELSEIF ($($Items.count) -gt 1) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Found multiple ($($Items.count)) Lines!"
|
||||
[Int]$Counter1 = 0
|
||||
|
||||
FOREACH ($Item in $Items) {
|
||||
|
||||
[Array]$Item = ($Item -split "=",2)
|
||||
[String]$ItemName = $Item[0]
|
||||
[String]$ItemName = ($ItemName.TrimStart())
|
||||
[String]$ItemName = ($ItemName.TrimEnd())
|
||||
[String]$ItemValues = $Item[1]
|
||||
[String]$ItemValues = ($ItemValues.TrimStart())
|
||||
[String]$ItemValues = ($ItemValues.TrimEnd())
|
||||
|
||||
IF (($ItemName) -and ($ItemValues)) {
|
||||
|
||||
[Int]$Counter1++ | Out-Null
|
||||
|
||||
IF ($ConfigLinesValue -eq "SingleValue") {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Looking for SingleValue Lines."
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: -> $ItemValues"
|
||||
|
||||
} #end if
|
||||
|
||||
ELSEIF ($ConfigLinesValue -eq "MultiValue") {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Looking for MultiValue Lines,"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: which are separated by a: $ConfigLinesValueSeparator"
|
||||
|
||||
#Rebuild the Array, to remove possible Blanks
|
||||
[Array]$ItemValues = $ItemValues -split "$ConfigLinesValueSeparator"
|
||||
[System.Collections.ArrayList]$ItemValuesTEMP = @()
|
||||
|
||||
FOREACH ($ItemValue in $ItemValues) {
|
||||
|
||||
IF ($ItemValue) {
|
||||
|
||||
#The "| Out-Null" is VERY important, otherwise the Array will be f**ked!
|
||||
$ItemValue = ($ItemValue.TrimStart())
|
||||
$ItemValue = ($ItemValue.TrimEnd())
|
||||
$ItemValuesTEMP.Add("$ItemValue") | Out-null
|
||||
|
||||
} #end if
|
||||
|
||||
} #end foreach
|
||||
|
||||
[Array]$ItemValues = $NULL
|
||||
[Array]$ItemValues = $ItemValuesTEMP
|
||||
|
||||
} #end elseif
|
||||
|
||||
IF ($($ItemValues.count) -eq 1) {
|
||||
#IF (($($ItemValues.count) -eq 1) -ne ($ConfigLinesValue -eq "MultiValue")) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Found $($ItemValues.count) Array Item!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Setting Variable: $($ItemName+$Counter1)"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: with Value -> $ItemValues"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: in Datatyp: String"
|
||||
Set-Variable -Name ($ItemName+$Counter1) -Value ([String]$ItemValues) -Scope Global
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
|
||||
} #end if
|
||||
|
||||
ELSEIF (($($ItemValues.count) -gt 1) -or ($ConfigLinesValue -eq "MultiValue")) {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Found $($ItemValues.count) Array Item(s)!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Setting Variable: $($ItemName+$Counter1)"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: with Value(s) -> $ItemValues"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: in Datatyp: Array"
|
||||
Set-Variable -Name ($ItemName+$Counter1) -Value @([Array]$ItemValues) -Scope Global
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
|
||||
} #end elseif
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Found $($ItemValues.count) Array Item(s)!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Setting Variable: $($ItemName+$Counter1)"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: with Value(s) -> $ItemValues"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: in Datatyp: $($ItemValues.gettype() | Select BaseType)"
|
||||
Set-Variable -Name ($ItemName+$Counter1) -Value $ItemValues -Scope Global
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: ------------------------------"
|
||||
|
||||
} #end else
|
||||
|
||||
} #end if
|
||||
|
||||
} #end foreach
|
||||
|
||||
#Return how many Profiles were are created!
|
||||
Return [Int]$Counter1
|
||||
|
||||
} #end elseif
|
||||
|
||||
#That shouldnt be happen...
|
||||
ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Error reading ConfigValues!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Exiting, because of this Issue."
|
||||
Write-Host $Error
|
||||
EXIT
|
||||
|
||||
} #end else
|
||||
|
||||
} #end elseif
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Invalid ConfigValues from ConfigFile!"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: Please check the Description of this Function"
|
||||
Write-Host "DEBUG Info - Read-ConfigFile: and the ConfigFile!"
|
||||
|
||||
} #end else
|
||||
|
||||
} #end function
|
||||
@@ -0,0 +1,117 @@
|
||||
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.1.0.0 / Date: 21.11.2016
|
||||
|
||||
.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> an which will be selected, the Item(s) to delete. Given <Filename> will be set with Wildcards: *<Filename>*.
|
||||
|
||||
.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 an which will be selected, the Item(s) to delete. Given <Filename> will be set with Wildcards: *<Filename>*.')]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String]$FileBaseName=$NULL
|
||||
|
||||
) #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)."
|
||||
$Items = (Get-ChildItem -Path "$Path\*" -Filter *.log | where {$_.Name -like "*$FileBaseName*" -and $_.lastwritetime -lt $((Get-Date).AddDays(-$FileKeepTime)) -and -not $_.psiscontainer})
|
||||
|
||||
IF ($Items -eq $null) {
|
||||
|
||||
Write-Logfile -LogLine "Found no old Files."
|
||||
Return $False
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine "Deleting old Files (Found: $($Items.count)) :"
|
||||
FOREACH ($Item in $Items) {
|
||||
|
||||
Try {
|
||||
|
||||
Remove-Item -Path $Item -Force -Verbose -ErrorVariable Error -ErrorAction Continue
|
||||
Write-Logfile -LogLine "LogFile: $Item was removed."
|
||||
Return $True
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Logfile -LogLine "File: $Item cannot been removed."
|
||||
Write-Logfile -LogLine "Please check your privileges!"
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end foreach
|
||||
|
||||
} #end else
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Logfile -LogLine "You disabled File deleting, they all will be kept."
|
||||
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
|
||||
@@ -0,0 +1,363 @@
|
||||
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.1.0.0 / 21.11.2016
|
||||
|
||||
.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.
|
||||
|
||||
.EXAMPLE
|
||||
Restart-windreamClient
|
||||
|
||||
.EXAMPLE
|
||||
Restart-windreamClient -Action Start
|
||||
|
||||
.EXAMPLE
|
||||
Restart-windreamClient -Action Start -ServiceTest $False
|
||||
#>
|
||||
|
||||
[cmdletbinding()]
|
||||
|
||||
Param (
|
||||
|
||||
[Parameter(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(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
|
||||
|
||||
) #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) | 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) | 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) | 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) | 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
|
||||
@@ -0,0 +1,361 @@
|
||||
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.1.0.1 / 22.11.2016
|
||||
|
||||
.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.
|
||||
|
||||
.EXAMPLE
|
||||
Restart-windreamClient
|
||||
|
||||
.EXAMPLE
|
||||
Restart-windreamClient -Action Start
|
||||
|
||||
.EXAMPLE
|
||||
Restart-windreamClient -Action Start -ServiceTest $False
|
||||
#>
|
||||
|
||||
Param (
|
||||
|
||||
[Parameter(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(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
|
||||
|
||||
) #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) | 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) | 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) | 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) | 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
|
||||
@@ -0,0 +1,304 @@
|
||||
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
|
||||
|
||||
.REQUIREMENT Variables preSet
|
||||
<NONE>
|
||||
|
||||
.REQUIREMENT Functions
|
||||
Write-LogFile
|
||||
|
||||
.VERSION
|
||||
1.1.0.0 / 21.11.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)).
|
||||
|
||||
.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
|
||||
|
||||
) #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
|
||||
|
||||
} #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
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
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, Counter1, LogLine
|
||||
|
||||
.REQUIREMENT Variables preSet
|
||||
LogFile, LogPath, LogPaths, ScriptName, ScriptPath
|
||||
|
||||
.REQUIREMENT Functions
|
||||
<NONE>
|
||||
|
||||
.VERSION
|
||||
Number: 2.0.0.0 / Date: 21.11.2016
|
||||
|
||||
.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."
|
||||
#>
|
||||
|
||||
[cmdletbinding()]
|
||||
|
||||
Param (
|
||||
|
||||
[Parameter(Position=0,Mandatory=$True,HelpMessage='Give the String you want to be written into the Logfile.')]
|
||||
[AllowEmptyString()]
|
||||
[String]$LogLine
|
||||
|
||||
) #end param
|
||||
|
||||
#Clear Error Variable
|
||||
$error.clear()
|
||||
|
||||
# This if / else block is only for determine the LogPath
|
||||
IF (!$LogPath) {
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "DEBUG Info: 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: Testing LogPath: $LogPath"
|
||||
$PathTest = Test-Path -PathType Container "$LogPath"
|
||||
|
||||
#Check if Path already exists
|
||||
IF ($PathTest -eq $True) {
|
||||
|
||||
Write-Host "DEBUG Info: LogPath seems already to exists: $LogPath"
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
#If Path doesnt exist, try to create it!
|
||||
Try {
|
||||
|
||||
Write-Host "DEBUG Info: Trying to create LogPath: $LogPath"
|
||||
New-Item -ItemType Directory -Path "$LogPath" -Force -ErrorAction Stop | Out-Null
|
||||
Write-Host "DEBUG Info: Trying seems to be successful!"
|
||||
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Host "DEBUG Info: 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: 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 Test seems to be successful."
|
||||
Set-Variable -Name LogPath -Value $LogPath -Scope Global -Force
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Host "DEBUG Info: Cannot write into LogPath or access denied!"
|
||||
Write-Host $Error
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host "DEBUG Info: 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: LogPath was already been set!"
|
||||
#Write-Host "DEBUG Info: 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
|
||||
|
||||
} #end try
|
||||
|
||||
Catch {
|
||||
|
||||
Write-Host "DEBUG Info: Cannot write to LogFile!"
|
||||
Write-Host "DEBUG Info: Exiting, because of this Issue."
|
||||
Write-Host $Error
|
||||
EXIT
|
||||
|
||||
} #end catch
|
||||
|
||||
} #end if
|
||||
|
||||
ELSE {
|
||||
|
||||
Write-Host "DEBUG Info: Cannot write to LogFile!"
|
||||
Write-Host "DEBUG Info: Exiting, because of this Issue."
|
||||
Write-Host $Error
|
||||
EXIT
|
||||
|
||||
} #end else
|
||||
|
||||
} #end function
|
||||
Reference in New Issue
Block a user