Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

18 April 2018

Remove TFS Code Search

When you install Microsoft Team Foundation Server (TFS) it will by default put TFS Code Search on the same server as TFS Application Tier.

PowerShell 5 does not have the CmdLet Remove-Service. Then any service must be removed using WMI.
It can be done with a PowerShell script like this:

'Stop TFS Code Search service (ElasticSearch)...'
$CodeSearchSvc = Get-WmiObject -Class Win32_Service -Filter "Name='$((Get-Service "elastic*").Name)'"
$Return = $CodeSearchSvc.StopService()
if ($Return.ReturnValue -eq 0)
{ '  Service stopped.' }
else
{ throw "Could not stop TFS Code Search service. Return value = '$($Return.ReturnValue)'. Check documentation on StopService method of the WMI Win32_Service class." }

'Delete TFS Code Search service...'
$Return = $CodeSearchSvc.Delete()
if ($Return.ReturnValue -eq 16)
{ '  The service is being removed from the system.' }
else
{ throw "Could not delete TFS Code Search service. Return value = '$($Return.ReturnValue)'. Check documentation on Delete method of the WMI Win32_Service class." }

'Delete files for TFS Code Search...'
Remove-Item -Path 'C:\TfsData\Search' -Recurse -Force


The folder holding the TFS Code Search files are in the default position in the script above. If you have placed the TFS Code Search files in another position then just alter the script.

Then the Java installation must be removed. Also remember to clean up in Windows environment variables like JAVA_HOME. This task is more individual and this is why it is not in the script above.

5 March 2018

Environment class with PowerShell


Getting information about the local Windows installation and some simple info on the physics is usually done through Windows environmental variables.  There is a somewhat old blog post (link) on the subject from the Microsoft PowerShell Team.

But using the .NET Environment class gives you a lot more than the environmental variables.

This is some examples of usage of the static elements of the Environment class:

[System.Environment]::CommandLine

[System.Environment]::CurrentDirectory

[System.Environment]::CurrentManagedThreadId

[System.Environment]::ExitCode

[System.Environment]::HasShutdownStarted

[System.Environment]::Is64BitOperatingSystem

[System.Environment]::Is64BitProcess

[System.Environment]::MachineName

[System.Environment]::NewLine

[System.Environment]::OSVersion | Format-List -Property *

[System.Environment]::ProcessorCount

[System.Environment]::StackTrace

[System.Environment]::SystemDirectory

[System.Environment]::SystemPageSize

[System.Environment]::TickCount

[System.Environment]::UserDomainName

[System.Environment]::UserInteractive

[System.Environment]::UserName

[System.Environment]::Version | Format-List -Property *

[System.Environment]::WorkingSet

[System.Environment]::Equals($null, $true)

[System.Environment]::Exit(42)

[System.Environment]::ExpandEnvironmentVariables('%ComSpec%')
[System.Environment]::ExpandEnvironmentVariables('%Path%').Split(';')

[System.Environment]::FailFast('Boom!')

[System.Environment]::GetCommandLineArgs()

[System.Environment]::GetEnvironmentVariable('ComSpec')

[System.Environment]::GetEnvironmentVariables(


[System.Enum]::GetNames([System.Environment+SpecialFolder])[System.Environment]::GetFolderPath('SystemX86') | Get-ChildItem

[System.Environment]::GetFolderPath([System.Environment+SpecialFolder])


[System.Environment]::GetLogicalDrives()[0]

[System.Environment]::ReferenceEquals($null, $true)



When I find some new details this will be updated.