This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get cert on local computer by thumbprint | |
$thumbprint = '89D3FC64B6405E161EDC7A4CF14E111F5F6895AA' | |
$Cert = Get-ChildItem Cert:\LocalMachine\My | Where-Object { $_.Thumbprint -eq $thumbprint } | |
################################################### | |
# Manage private key of CAPI cert | |
################################################### | |
# Find private key | |
$privKey = $Cert.PrivateKey.CspKeyContainerInfo.UniqueKeyContainerName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$File = 'C:\Users\miles.gratz\desktop\Dark Console Light Editor default.StorableColorTheme.ps1xml' | |
$Content = Get-Content $file | |
$Results = @() | |
$Index = 0 | |
foreach ($line in $content) | |
{ | |
if ($line -match "\<string\>") | |
{ | |
$key = (($line -split "<string>")[1] -split "</string>")[0] | |
$object = New-Object PSCustomObject |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Replace individual rows in a CSV | |
(if there are no multiline rows) | |
Define example input file | |
City Zipcode | |
---- ------- | |
Phoenix, AZ 85001 | |
Little Rock, AR 72201 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$FirstHop = "Server1" | |
$SecondHop = "Server2" | |
$Cred = Get-Credential | |
Function Run-CustomFunction { | |
param( | |
$FirstHop, | |
$SecondHop, | |
$Cred | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Run-CustomFunction { | |
param($ComputerName) | |
# Create a job for tracking results | |
Start-Job -Name $ComputerName -ScriptBlock { | |
# Run the command on the remote Computer | |
Invoke-Command -ComputerName $args[0] -ScriptBlock { | |
Get-ChildItem "C:\Temp" | |
} | |
} -ArgumentList $ComputerName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Potential input | |
# ------------------------------------- | |
# Test File With Spaces.txt | |
# Test_File_With_Underscores.txt | |
# Weird_Chars##$%@1.txt | |
$badFiles = Get-ChildItem "C:\temp\irregular files" | |
foreach ($file in $badFiles) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#--------------------------------------------------- | |
# Let's find all registry keys beneath specific path | |
#--------------------------------------------------- | |
# Define root of registry query | |
$topLayer = "HKLM:\SOFTWARE\Microsoft\.NETFramework" | |
# Define empty array for all layers | |
$allLayers = @() | |
$allLayers += $topLayer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$CabPath = "C:\temp" | |
$CabFiles = Get-ChildItem $CabPath\*.cab | |
# Expand Cabs into folder based on their Name | |
foreach ($Cab in $CabFiles){ | |
$Directory = New-Item -Path $CabPath\$($Cab.BaseName) -ItemType Directory -Force | |
expand $Cab.FullName -F:* $Directory.FullName | |
} | |
# Install drivers inside each cab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Search for stale computers | |
$StaleComputers = Get-ADComputer -Filter { | |
Enabled -eq $true -and OperatingSystem -like "*Windows*" -and OperatingSystem -notlike "*Server*" | |
} -Properties LastLogonDate,Description,Location,OperatingSystem,CanonicalName |` | |
Where-Object { ((Get-Date) - ($_.LastLogonDate)).TotalDays -gt 45 } | |
# Export results to C:\temp | |
$StaleComputers | Export-Csv C:\temp\Stale-Computers.csv -NoTypeInformation | |
# Uncomment to disable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Source = "txt","csv","pdf","xlsx","docx" | |
$Find = "csv","pdf" | |
$Source | ForEach-Object { | |
# does not work | |
# -match cannot find item in array | |
If ($_ -match $Find) | |
{ | |
$_ |
NewerOlder