Posts

Showing posts from April, 2018

Get-LoggedinUser and Get-LoggedInUserSID

Gets the username or user SID of a local or remote computer.

Function Get-LoggedInUser {
<#
.SYNOPSIS
Gets logged in user on local or remote computers.

.NOTES
    Author:  Curtis Wright
    Email:   curtis (at) cwew.co
    Date:    05FEB2018
    PSVer:   2.0/3.0/4.0/5.0

#>
#Allowing Cmdlet Bindings
[CmdletBinding(SupportsShouldProcess=$true)]
Param(
$Computer = $env:COMPUTERNAME,
$domain = $env:userdomain
)
Write-Verbose "Computer is $Computer and domain is $domain"
#Getting the current Error Action Preference so the script can set it back after completion.
$CurrentEA = $ErrorActionPreference
Write-Verbose "Current Error action is $CurrentEA"
$ErrorActionPreference = "SilentlyContinue"
Write-verbose "Attempting to use WMI to get currently logged in user"
$ActiveProcesses = Get-WMIObject win32_process -filter 'name="explorer.exe"' -ComputerName $Computer
if (($ActiveProcesses.GetType().basetype.name) -eq "Array")

Get-OfficeVersion

PowerShell function that gets the currently installed office version and returns either the year, the office folder, the registry location, or the number.

Updated 4/25/18 to support 64 bit office. Bitness is now a returnable Value Type.


Function Get-OfficeVersion {
#Allowing Cmdlet Bindings
[CmdletBinding(SupportsShouldProcess=$true)]
param(
  [Parameter(Position=0,Mandatory=$true)]
  [Alias("Value","VT")]
  [ValidateSet("Office Year", "Office Folder", "Registry Location","Registry Number","Bitness")]
  [string]$ValueTypeReturn,
    [Parameter(Position=1,Mandatory=$false)]
  [Alias("Computer","CN")]
  [string]$ComputerName = $env:COMPUTERNAME
)
Write-Verbose "Testing connection to $ComputerName"
if(Test-Connection -Quiet $ComputerName -Count 1){
Write-Verbose "Connection Successful to $ComputerName"
Write-Verbose "Detecting software for $ComputerName"
    if ((Test-p…