CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2018
    Posts
    15

    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

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Converting powershell file to C#.

    Are you asking for help with converting the powershell code into C#?

  3. #3
    Join Date
    Dec 2018
    Posts
    15

    Re: Converting powershell file to C#.

    Quote Originally Posted by Arjay View Post
    Are you asking for help with converting the powershell code into C#?
    Yes, I am working on it but not getting desired output.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Converting powershell file to C#.

    If you post the C# code, the output you are getting and the desired output, we might be able to help. When posting the code, plase use code tags.

  5. #5
    Join Date
    Dec 2018
    Posts
    15

    Re: Converting powershell file to C#.

    Thanks for helping out. Error got cleared.

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
  •  





Click Here to Expand Forum to Full Width

Featured