I am trying to return simply the active username to use later in a script, however I am currently hung up on having my variable populate only the username, excluding the domain.
Function Get-Username() {
$username = Get-WMIObject -class Win32_ComputerSystem | select username
return $username
}
Function Delimit-Username() {
$newUserName = $username -replace 'DOMAIN\',''
Write-Host $newUserName
}
Get-Username
Delimit-Username
$Domain,$User = (Get-WMIObject -class Win32_ComputerSystem).UserName.Split('\')