-
December 27th, 2018, 04:25 AM
#1
Converting powershell file to C#.
I have tried this code, will it work to convert file to C#
Code:
## DEFINE FUNCTIONS
function fcnLogEvent($strEventDescription,$strEventLevel) {$strDateTime = Get-Date -Format "MM/dd/yyyy hh:mm:ss:ffff"$strEventDescription = $strEventDescription + " "$strEventDescription = $[url removed, login to view](85,".")
$strLogLine = $strDateTime + "," + $strEventDescription + " " + $strEventLevel
try {
if ($debugLevel -eq "1") {
write-host $strLogLine
add-content ".\[url removed, login to view]" -value $strLogLine
}
} catch {
}
}
function fcnMoveFileToStage($strFile) {
$strFileName = $[url removed, login to view]
try {
Move-Item "..\inbox\$strFileName" "..\stage\$strFileName"
fcnLogEvent "Moving File $strFileName" "Information"
} catch {
fcnLogEvent "Moving File $strFileName" "Error"
}
return $strFileName
}
function fcnLaunchFileEscort($strFileName) {
try {
$strExecutable = "[url removed, login to view]"
$strArguments = "-file .\[url removed, login to view]", "$strFileName"
$objProcess = start-process $strExecutable $strArguments -PassThru -WindowStyle Hidden
fcnLogEvent "Starting file escort for $strFileName" "Information"
} catch {
fcnLogEvent "Starting file escort for $strFileName" "Error"
}
}
## SCRIPT START
fcnLogEvent "Scanning inbox" "Information"
## RENAME SPACES TO UNDERSCORES IN FILE NAMES
dir "..\inbox" | Rename-Item -NewName { $[url removed, login to view] -replace ' ','_' }
## GET FILES IN INBOX
try {
$arrFiles = Get-ChildItem -Path "..\inbox" –File
} catch {
fcnLogEvent "Unable to scan inbox" "Error"
}
## PROCESS EACH FILE
if ($[url removed, login to view] -gt 0) {
$intFileCount = $[url removed, login to view]
fcnLogEvent "Found $intFileCount files in inbox" "Information"
foreach ($objFile in $arrFiles) {
$strStageFileName = fcnMoveFileToStage $objFile
fcnLaunchFileEscort $strStageFileName
}
} else {
fcnLogEvent "Found 0 files in inbox" "Information"
}
## EXIT
fcnLogEvent "Process complete. Exiting" "Information"
Last edited by 2kaud; December 27th, 2018 at 04:28 AM.
Reason: Added code tags
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|