Skip to content

Instantly share code, notes, and snippets.

View XPlantefeve's full-sized avatar

Xavier Plantefève XPlantefeve

View GitHub Profile
@XPlantefeve
XPlantefeve / logonindex.ps1
Created March 19, 2015 16:23
logon index / find a computer's main user
$ComputerName = $env:ComputerName
$test = Import-Csv -Path "log:\computers\${ComputerName}.log" -Delimiter ' ' -header @('user','date','time')
$t2 = $test |
select user,date,@{
name='logonage';
expression={
1 / ((Get-Date) - [DateTime]$_.date).Days}
@XPlantefeve
XPlantefeve / Get-SurveyorComputer.ps1
Created March 31, 2015 13:52
Reads computer info from a surveyor database
<#
.Synopsis
Gets computer information from Surveyor
.DESCRIPTION
Returns computers from the Surveyor database. Can return information for
specific computers or a filtered subset of the DB table.
.EXAMPLE
Get-SurveyorComputer -Name MyComputerName
Returns information for the computer named MyComputerName.
.EXAMPLE
@XPlantefeve
XPlantefeve / SQLServer.ps1
Created March 31, 2015 13:56
A couple of CMDlets to interrogate a SQLServer
<#
.Synopsis
Opens a connection to a SQL server.
.DESCRIPTION
Opens a connection to a SQL server and provides a sqlConnection object.
the connection object has to be closed at the end of the processing.
.EXAMPLE
$con = Open-SQLServer -Server SQLSVR -Database MyDataBase
Opens a connection to the MyDataBase DB on SQLSVR.
.LINK
@XPlantefeve
XPlantefeve / Get-SCCMComputer.ps1
Created March 31, 2015 14:03
Gets computer information from SCCM.
<#
.Synopsis
Gets computer info from SCCM
.DESCRIPTION
Retrieves computers from SCCM, with optional targeting and filtering
.INPUTS
[System.String]
.OUTPUTS
[System.Management.ManagementObject#root\sms\site_SCM\SMS_R_System]
.EXAMPLE
@XPlantefeve
XPlantefeve / get-DomainAdminLastLogon.ps1
Created June 11, 2015 13:04
get-DomainAdminLastLogon
$domainControllers = Get-ADDomainController -Filter *
Get-ADGroupMember -Identity 'Domain Admins' -Recursive | ForEach-Object -Process {
$user = $_
$domainControllers |
ForEach-Object -Process {
Get-ADUser $user.SamAccountName -Server $_.Name -Properties lastLogon, cn, employeeNumber, accountExpires, PasswordNeverExpires, Enabled, LockedOut, pwdLastSet
} |
Sort-Object -Property LastLogon |
Select-Object -Last 1 -Property SamAccountName,
<#
.Synopsis
Gets uptime information
.EXAMPLE
Get-Uptime -ComputerName URANUS
.INPUTS
String[]
.OUTPUTS
CUSTOM.UptimeInfo
.NOTES
<#
.Synopsis
Short description
.DESCRIPTION
Long description
.EXAMPLE
Example of how to use this cmdlet
.EXAMPLE
Another example of how to use this cmdlet
#>
@XPlantefeve
XPlantefeve / keybase.md
Created March 18, 2016 05:44
Keybase proof

Keybase proof

I hereby claim:

  • I am Xplantefeve on github.
  • I am xplantefeve (https://keybase.io/xplantefeve) on keybase.
  • I have a public key whose fingerprint is BBA5 AAF0 DC6E 481C 091E A57D 8230 1914 C28F 3C6E

To claim this, I am signing this object:

# Answer to http://powershell.org/wp/2016/03/05/2016-march-scripting-games-puzzle/
Function Get-HumanReadableSize($size) {
If ( $size -lt 1KB) { Return $size }
ElseIf ( $size -lt 1MB) { Return "$([math]::Round(($size / 1KB),2))Kb" }
ElseIf ( $size -lt 1GB) { Return "$([math]::Round(($size / 1MB),2))Mb" }
ElseIf ( $size -lt 1TB) { Return "$([math]::Round(($size / 1MB),2))Gb" }
Else { Return "$([math]::Round(($size / 1TB),2)) TB" }
}
@XPlantefeve
XPlantefeve / New-Timer.ps1
Last active May 30, 2016 08:17
Creates a timer that display a progressbar and the estimated remaining time.
<#
.Synopsis
Creates a timer with display
.DESCRIPTION
Creates a timer that writes the progress of the current action and the estimated remaining time.
Suppose you have $Items, an array of items to process.
First, you create a timer initialized to the number of items in the array:
$MyTimer = New-Timer -TotalItems $Items.count -Activity 'Processing items'