Skip to content

Commit

Permalink
Add 'VM-Add-To-Path' function to common.vm
Browse files Browse the repository at this point in the history
  • Loading branch information
emtuls committed Dec 20, 2023
1 parent b39570d commit 3947cae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/common.vm/common.vm.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>common.vm</id>
<version>0.0.0.20231123</version>
<version>0.0.0.20241220</version>
<description>Common libraries for VM-packages</description>
<authors>Mandiant</authors>
</metadata>
Expand Down
22 changes: 22 additions & 0 deletions packages/common.vm/tools/vm.common/vm.common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1334,3 +1334,25 @@ function VM-Clean-Up {
Write-Host "[+] Clearing up free space. This may take a few minutes..." -ForegroundColor Green
VM-Clear-FreeSpace
}

function VM-Add-To-Path {
param (
[string]$pathToAdd
)
# Get the current user's Path environment variable
$currentPath = [System.Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)

# Check if the path already exists in the variable
if ($currentPath -notlike "*$pathToAdd*") {
# Add the new path to the current Path environment variable
$newPath = $currentPath + [IO.Path]::PathSeparator + $pathToAdd

# Set the new Path environment variable for the user
[System.Environment]::SetEnvironmentVariable("Path", $newPath, [System.EnvironmentVariableTarget]::Machine)

Write-Host "[+] Path added successfully." -ForegroundColor Green
}
else {
Write-Host "[+] The path is already in the Environment Variable." -ForegroundColor Green
}
}

0 comments on commit 3947cae

Please sign in to comment.