Skip to content

Instantly share code, notes, and snippets.

View XPlantefeve's full-sized avatar

Xavier Plantefève XPlantefeve

View GitHub Profile
@XPlantefeve
XPlantefeve / PXENextBoot-Dell.ps1
Last active August 29, 2015 14:15
Gets a computer to boot on PXE at next boot, clears the flag, or retrieve the information. For Dell systems with the Sysman WMI layer installed.
<#
Gets a computer to boot on PXE at next boot, clears the flag,
or retrieve the information.
Works for Dell systems with the Sysman WMI layer installed.
LAST UPDATED: 18/02/2015
AUTHOR : Xavier Plantefève
#>
@XPlantefeve
XPlantefeve / ConvertTo-Csave.ps1
Last active August 29, 2015 14:15
Rewriting of the ConvertTo-CSV CMDlet, as an exercise.
<#
.SYNOPSIS
Converts objects into a series of comma-separated value (CSV) variable-length strings.
.DESCRIPTION
The ConvertTo-CSV cmdlet returns a series of comma-separated (CSV) strings that represents the objects that you submit. You can then use the ConvertFrom-CSV cmdlet to re-create
objects from the CSV strings. The resulting objects are CSV versions of the original objects that consist of string representations of the property values and no methods.
You can also use the T:Microsoft.PowerShell.Commands.Export-Csv and T:Microsoft.PowerShell.Commands.Import-Csv cmdlets to convert objects to CSV strings (and back). Export-CSV is the
same as ConvertTo-CSV, except that it saves the CSV strings in a file.
@XPlantefeve
XPlantefeve / ConvertFrom-Csave.ps1
Last active August 29, 2015 14:15
Rewriting of ConvertFrom-Csv, as an exercise. Quickly done and unfinished.
Function ConvertFrom-Csave {
[CmdletBinding(DefaultParameterSetName='UseDelimiter')]
Param (
[Parameter(Position=2,ParameterSetName='UseDelimiter')]
[char]$Delimiter = ',',
# FIXME
[string[]] $Header,
[Parameter(Mandatory=$True,Position=1,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$true)]
[PSObject] $InputObject,
[Parameter(Mandatory=$True,Position=2,ParameterSetName='UseCulture')]
@XPlantefeve
XPlantefeve / test.ps1
Last active August 29, 2015 14:16
Exercise: answer to an old forum question.
<#
.LINK
https://social.technet.microsoft.com/Forums/scriptcenter/en-US/bfe66e89-e6ea-48e8-bcab-6f260493944e/powershell-listing-of-all-files-and-owner-to-csv
#>
# version 1. Note that "-Attributes" was not available in 2010 (PoSh2)
Get-ChildItem -Recurse -Attributes !Directory |
ForEach-Object { Add-Member -InputObject $_ -NotePropertyName Acl -NotePropertyValue (Get-Acl $_.FullName) -PassThru } |
Select-Object DirectoryName,Name,length,@{Name='Owner';Expression={$_.acl.Owner}}
@XPlantefeve
XPlantefeve / Convert-GrisbiToCsv.ps1
Last active August 29, 2015 14:16
Conversion of a Grisbi personal finance file to csv. #Raw
function Convert-Currency ($transaction)
{
If ($transaction.Exb -eq '1') {
return [math]::Round([decimal]$transaction.Am /
[decimal]$transaction.Exr,2) + $transaction.exf
} else {
return [math]::Round([decimal]$transaction.Am *
[decimal]$transaction.Exr,2) + $transaction.exf
}
}
$test=@(
'LastName1, FirstName1',
'ShortName1',
'LastName2, FirstName2',
'ShortName2',
'LastName3, FirstName3',
'ShortName3'
)
$odd = $true
@XPlantefeve
XPlantefeve / ModuleAsObject.ps1
Created March 19, 2015 16:18
Module as object
function New-Dog {
param(
[Parameter(Mandatory=$true)]
[string]$Name,
[Parameter(Mandatory=$false)]
[ValidateSet('small', 'medium','large', $null)]
[string]$size,
[Parameter(Mandatory=$false)]
[string]$color
)
@XPlantefeve
XPlantefeve / Get-FaultyAdmAccounts.ps1
Created March 19, 2015 16:21
Get faulty ADM accounts ('adm-username' for which there's no 'username')
Function Get-ADReferent ($user)
{
$user = $user -replace '^adm-',''
Try {
$test = Get-ADUser $user
$test.SamAccountName
} Catch {
''
}
}
@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