We help IT Professionals succeed at work.
Private

Embedding code from Visual Studio Code indenting issue when replying to thread, not when creating?

205 Views
Last Modified: 2020-02-25
To Whom it may concerns,

I notice that when I copy paste a script into the thread, recently it does HTML formatting and breaks all of the indentings. See the below for example.

$ListOfServers = Get-ADComputer -Filter {Enabled -eq $True -and OperatingSystem -like "*Server*"} -SearchBase "DC=Domain,DC=com"
# If you want in in a text files containing server list or names    
#$ListOfServers = Get-Content "c:\temp\serv.txt"

Foreach ($Server in $ListOfServers) {
    Invoke-Command -ComputerName $Server -ScriptBlock {
        # Get Certificate list and assign to a variable
        $Certs = Get-ChildItem "Cert:\LocalMachine\My" -Recurse

        #To get a list of all cert storage locations.
        #(Get-ChildItem -Path "Cert:" -Recurse | Where-Object {($_).GetType().Name -eq 'X509Store'}).Name        

        # Loop through each object in $Certs
        Foreach ($Cert in $Certs) {
            # If The objects property "NotAfter" is older than the current time, delete
            If ($Cert.NotAfter -lt (Get-Date)) {
                $Cert | Remove-Item -WhatIf # Remove the -WhatIf to make it run for real.
            }
        }
    }
}

Open in new window


Can anyone please suggest if this is a known issue in the new EE website or this is an issue in the Visual Studio code?
Comment
Watch Question

Senior IT System EngineerSenior Systems Engineer
CERTIFIED EXPERT

Author

Commented:

This is when I reply from VS code with the same clipboard content:


Code below is embedded with the proper [code][/code] tags:


$ListOfServers   =   Get-ADComputer   - Filter {Enabled -eq   $True   -and  OperatingSystem -like   "*Server*" } - SearchBase "DC=Domain,DC=com"
# If you want in in a text files containing server list or names    
#$ListOfServers = Get-Content "c:\temp\serv.txt"
Foreach  ( $Server   in   $ListOfServers ) {
    Invoke-Command   - ComputerName $Server   - ScriptBlock {
        # Get Certificate list and assign to a variable
        $Certs   =   Get-ChildItem   "Cert:\LocalMachine\My"   - Recurse
        #To get a list of all cert storage locations.
        #(Get-ChildItem -Path "Cert:" -Recurse | Where-Object {($_).GetType().Name -eq 'X509Store'}).Name        
        # Loop through each object in $Certs
        Foreach  ( $Cert   in   $Certs ) {
            # If The objects property "NotAfter" is older than the current time, delete
            If  ( $Cert.NotAfter   -lt  ( Get-Date )) {
                $Cert   |   Remove-Item   - WhatIf # Remove the -WhatIf to make it run for real.
            }
        }
    }
}


Software Tead Lead / Business Analyst / System Analyst / Data Engineer / Applications Consultant
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer / Applications Consultant
CERTIFIED EXPERT

Commented:

Test with Beta:


$ListOfServers = Get-ADComputer -Filter {Enabled -eq $True -and OperatingSystem -like "*Server*"} -SearchBase "DC=Domain,DC=com" # If you want in in a text files containing server list or names     #$ListOfServers = Get-Content "c:\temp\serv.txt"  Foreach ($Server in $ListOfServers) {     Invoke-Command -ComputerName $Server -ScriptBlock {         # Get Certificate list and assign to a variable         $Certs = Get-ChildItem "Cert:\LocalMachine\My" -Recurse          #To get a list of all cert storage locations.         #(Get-ChildItem -Path "Cert:" -Recurse | Where-Object {($_).GetType().Name -eq 'X509Store'}).Name                  # Loop through each object in $Certs         Foreach ($Cert in $Certs) {             # If The objects property "NotAfter" is older than the current time, delete             If ($Cert.NotAfter -lt (Get-Date)) {                 $Cert | Remove-Item -WhatIf # Remove the -WhatIf to make it run for real.             }         }     } } 
Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer / Applications Consultant
CERTIFIED EXPERT

Commented:

I think the text from code is copied properly (as I can saw it in Notepad+ displayed nicely) but somehow the new Beta version of Code doesn't work so well at this moment (I also facing some indent and alignment issues by using the Beta's Code feature)

Senior IT System EngineerSenior Systems Engineer
CERTIFIED EXPERT

Author

Commented:

Yes, it seems this is server-side issue, not my browser (Client side issue).

Senior Consultant
CERTIFIED EXPERT
Awarded 2017
Distinguished Expert 2019
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Senior IT System EngineerSenior Systems Engineer
CERTIFIED EXPERT

Author

Commented:
$ListOfServers   =   Get-ADComputer   - Filter { Enabled -eq   $True   -and  OperatingSystem -like   "*Server*"  } - SearchBase "DC=Domain,DC=com"
# If you want in in a text files containing server list or names    
#$ListOfServers = Get-Content "c:\temp\serv.txt"
Foreach  ( $Server   in   $ListOfServers ) {
    Invoke-Command   - ComputerName $Server   - ScriptBlock {
        # Get Certificate list and assign to a variable
        $Certs   =   Get-ChildItem   "Cert:\LocalMachine\My"   - Recurse
        #To get a list of all cert storage locations.
        #(Get-ChildItem -Path "Cert:" -Recurse | Where-Object {($_).GetType().Name -eq 'X509Store'}).Name        
        # Loop through each object in $Certs
        Foreach  ( $Cert   in   $Certs ) {
            # If The objects property "NotAfter" is older than the current time, delete
            If  ( $Cert.NotAfter   -lt  ( Get-Date )) {
                $Cert   |   Remove-Item   - WhatIf # Remove the -WhatIf to make it run for real.
            }
        }
    }
}



There was no "clean" pop up?

Senior IT System EngineerSenior Systems Engineer
CERTIFIED EXPERT

Author

Commented:
thanks!
it is definitely a bug in the beta version.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.