Skip to content

Collapsing code not working correctly #1661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DanrwAU opened this issue Dec 18, 2018 · 2 comments
Closed

Collapsing code not working correctly #1661

DanrwAU opened this issue Dec 18, 2018 · 2 comments
Labels

Comments

@DanrwAU
Copy link

DanrwAU commented Dec 18, 2018

Issue Description

I am experiencing a problem with collapsing code of functions.

Collapsing a function seems to be collapsing to a random point in the middle of the function.

See code below and a screenshot of how it is collapsed

Function ConvertToLocal {

    Param (
        [Parameter(Position = 0, Mandatory)]
        [string]$User,

        [Parameter ()]
        [string]$UpdateFile = "C:\Temp\GTRUSRAD.txt",

        [Parameter ()]
        [string]$LogPath = 'C:\Temp',

        [Parameter ()]
        [string] $SMTPServer = ""

    )
   
    $Result = @()

    Write-Verbose -Message 'Connecting to Office 365'

    Connect-Office365

    Write-Verbose -Message "Searching for User"
    
    If (-not $User) {
        $User = (Read-Host -Message 'Enter User is UPN Format (eg. [email protected])')
    }

    Try {
        $365User = Get-MSOLUser -UserPrincipalName $User
    }
    Catch {
        Throw "User not found in Office 365. Check input and try again."
    }

    $NewPwd = Get-Password

    $ADUserParams = @{
        Name              = $365User.DisplayName
        DisplayName       = $365User.DisplayName
        GivenName         = $365User.FirstName
        Surname           = $365User.LastName
        UserPrincipalName = $365User.UserPrincipalName
        EmployeeID        = $365User.AlternateMobilePhones[0]
        SamAccountName    = $365User.UserPrincipalName.Split('@')[0]
        Email             = $365User.UserPrincipalName
        Path              = "OU=.NewUsers, OU=Employee, OU=Accounts, DC=domain, DC=com, DC=au"
        Enabled           = $True
        AccountPassword   = (ConvertTo-SecureString -AsPlainText $NewPwd -Force)
        ErrorVariable     = "ErrorMessage"
        ErrorAction       = "SilentlyContinue"
             
    }

    Write-Verbose -Message "Creating On-Prem account"

    New-ADUser @ADUserParams

    If ($ErrorMessage) {
        $UserObj = [pscustomobject]@{
            Name              = $365User.DisplayName
            GivenName         = $365User.FirstName
            Surname           = $365User.LastName
            UserPrincipalName = $365User.UserPrincipalName
            EmployeeID        = $365User.AlternateMobilePhones[0]
            SamAccountName    = $365User.UserPrincipalName.Split('@')[0]
            Status            = 'Error'
            ErrorDetails      = "$ErrorMessage"
        } 
        $Result += $UserObj 

        Throw "Error Creating user $ErrorMessage"
    }
    Else {
        $UserObj = [pscustomobject]@{
            Name              = $365User.DisplayName
            GivenName         = $365User.FirstName
            Surname           = $365User.LastName
            UserPrincipalName = $365User.UserPrincipalName
            EmployeeID        = $365User.AlternateMobilePhones[0]
            SamAccountName    = $365User.UserPrincipalName.Split('@')[0]
            Path              = "OU=.NewUsers, OU=Employee, OU=Accounts, DC=ksgroup, DC=com, DC=au"
            Enabled           = $True
            Password          = $NewPwd
            Domain            = 'ksgroup.com.au'
            Status            = 'OK'
            ErrorDetails      = ''   
        }
        
        $Result += $UserObj 
    
        Write-Verbose -Message "Assigning E3 License"

        Set-MSOLUserLicense -UserPrincipalName $User -AddLicenses $E3SKU -RemoveLicenses $F1SKU
        Add-ADGroupMember -Identity 'O365-License-E3' -Members $UserObj.SamAccountName

        Remove-MsolGroupMember -GroupObjectId $ObjectID -GroupMemberObjectId ($365User | Select-Object ObjectID).ObjectID
    }


    ForEach ($Line in $Result) {
        If ($Line.Status -eq "OK") {
            $Export += "cbr=detupd, detnumber=""$($Line.EmployeeID)"", detemailad=""$($Line.Emailaddress)"","
            $Export += "cbr=edeupd, detnumber=""$($Line.EmployeeID)"", edeadpass=""$($Line.Password)"","
            $Export += "cbr=usradd, usrlogonid=""$($Line.EmployeeID)"", usrlogonnm=""$($Line.FirstName) $($Line.Surname)"", usrlogname=""$($Line.EmailAddress)"", usrempno=""$($Line.EmployeeID)"", usremailcd=""PASS"", usraccck[1]=""hr21"", usrmenurol[1]=""MYHRE"", usrworkg[1]=""SSERVIC1"", usrdomain=""$($Line.domain)"", usrextauth=""Y"", usremailad=""$($Line.emailaddress)"", usrmenlogn=""STD"","
        }
    }

    $Export | Out-File -FilePath $UpdateFile -Force -Encoding utf8


    #Export Results to CSV for Emailing to HR 
    $Result | Export-CSV -Path "$LogPath\Results.csv" -NoTypeInformation -Force

    Write-Verbose -Message "Complete - Sending Emails."
    $MailParams = @{
        SMTPServer  = $SMTPServer
        From        = '[email protected]'
        To          = $Recipients
        Priority    = 'High'
        Subject     = 'Staff Conversion Results - CloudToOnPrem'
        Body        = 'Staff Conversion Results - Convert to On-Prem User'
        Attachments = "$Logpath\Results.csv" , $UpdateFile
        BodyAsHtml  = $True 
    }

    Send-MailMessage @MailParams

    Write-Verbose -Message "Conversion Completed"
    Write-Verbose -Message "$Result"
    Write-Warning "Please ensure user status is 'Synced with Active Directory' in Office 365. This Process can take up to 1 hour."

}

This collapses to the below in the editor

image

I've confirmed the closing brace is attached to the opening of the function and highlights the opening brace correctly when selected.

Any thoughts?

Environment Information

Visual Studio Code

Name Version
Operating System Windows_NT x64 10.0.17763
VSCode 1.30.0
PowerShell Extension Version 1.10.1

PowerShell Information

Name Value
PSVersion 5.1.17763.134
PSEdition Desktop
PSCompatibleVersions 1.0 2.0 3.0 4.0 5.0 5.1.17763.134
BuildVersion 10.0.17763.134
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Visual Studio Code Extensions

Visual Studio Code Extensions(Click to Expand)
Extension Author Version
PowerShell ms-vscode 1.10.1
team ms-vsts 1.144.1
vscode-icons robertohuertasm 8.0.0
@AdamGrossTX
Copy link

I'm seeing the same. It seems related to using [pscustomobject]@{} inside a function for me.

2018-12-18_8-26-02

@SydneyhSmith
Copy link
Collaborator

@DanrwAU @AdamGrossTX Thanks for reporting this issue! We are tracking the issues with code folding at issue #1631 so I am going to close this one as a duplicate but please track the issue there. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants