Skip to content

Instantly share code, notes, and snippets.

View Dan1el42's full-sized avatar

Daniel Krebs Dan1el42

View GitHub Profile
# Sample data
$systemData = @{
'System1' = @(
'Person1'
'Person2'
'Person3'
)
'System2' = @(
'Person1'
'Person3'
[DscResource()]
class SampleResourceStandalone {
[DscProperty(Key)]
[string] $Name
# Gets the resource's current state.
[SampleResourceStandalone] Get() {
return $this
}
$Events = Get-WinEvent -LogName Security -MaxEvents 10
foreach ($Event in $Events) {
$MessageLineArray = $Event.Message -split "`r`n"
if ($MessageLineArray.Count -ge 1) {
$MessageLineArray[0]
}
}
$Params = @{
Query = "SELECT [CERTIFIED & UNASSESSED SKILL] FROM master where [CERTIFIED & UNASSESSED SKILL] LIKE '%Citrix%'"
ServerInstance = 'dc2012\sqlexpress'
Database = 'final'
}
Invoke-Sqlcmd @Params | ForEach-Object { $_['CERTIFIED & UNASSESSED SKILL'] -split ',' } | Where-Object { $_ -like '*Citrix*' }
$filePath = "C:\Temp"
$selectPropertyList = @(
@{n='FileName';e={$_.Name.ToUpper()}}
@{n='Length (MB)';e= {($_.Length/1MB).ToString('N2')}}
)
$files = Get-ChildItem -Path $filePath -File -Recurse -Force |
Select-Object -Property $selectPropertyList |
Sort-Object -Property 'Length (MB)' -Descending | Out-GridView
$filePath = "C:\Temp"
$selectPropertyList = @(
@{n='FileName';e={$_.Name.ToUpper()}}
@{n='Length (MB)';e= {[System.Decimal]::Round($_.Length/1MB, 2)}}
)
$files = Get-ChildItem -Path $filePath -File -Recurse -Force |
Select-Object -Property $selectPropertyList |
Sort-Object -Property 'Length (MB)' -Descending | Out-GridView
@Dan1el42
Dan1el42 / linkedin-profile-interest.ps1
Last active August 6, 2016 03:00
LinkedIn Profile Interests
$Interests = @(
'Automation'
'AWS'
'Amazon Web Services'
'Cloud Computing'
'Chef'
'Puppet'
'Docker'
'Containers'
'Red Hat Enterprise Linux'
# Script Disk Space
$users = “xxxxxxxx” # List of users to email your report to (separate by comma)
$fromemail = “xxxxxxxxx”
$server = “xxxxxxx” #enter your own SMTP server DNS name / IP address here
$list = "C:\Powershell Script\list.txt" #This accepts the argument you add to your scheduled task for the list of servers. i.e. list.txt
$computers = Get-Content -Path $list #grab the names of the servers/computers to check from the list.txt file.
$mydate = Get-Date
# Set free disk space threshold below in percent (default at 10%)
[decimal]$thresholdspace = 10
if ($Event[0].Message -match 'sequence number (?<SequenceNumber>\d+)')
{
'Sequence number found: {0}' -f $Matches.SequenceNumber
}
# Option 1: Access the capture group (\d+) by number.
if ($Event[0].Message -match 'sequence number (\d+)')
{
$Number = $Matches[1]
}
# Option 2: Access the number using the named capture group "Number"
if ($Event[0].Message -match 'sequence number (?<Number>\d+)')
{
$Number = $Matches.Number