Skip to content

Instantly share code, notes, and snippets.

View PSingletary's full-sized avatar
🔍
Search

PSingletary PSingletary

🔍
Search
View GitHub Profile
@PSingletary
PSingletary / Export-Chocolatey.ps1
Created December 30, 2017 01:17 — forked from alimbada/Export-Chocolatey.ps1
Export installed Chocolatey packages as packages.config - thanks to Matty666
Write-Output "<?xml version=`"1.0`" encoding=`"utf-8`"?>"
Write-Output "<packages>"
choco list -lo -r -y | % { " <package id=`"$($_.SubString(0, $_.IndexOf("|")))`" version=`"$($_.SubString($_.IndexOf("|") + 1))`" />" }
Write-Output "</packages>"
@PSingletary
PSingletary / Hundred-OneLines.psm1
Last active January 12, 2018 08:40 — forked from chrdek/Hundred-OneLines.psm1
One hundred and one (one-liners) of Powershell for Computer Info.
<#
MODULE OF:
..One-Hundred-and-One one-liners of powershell..
Author: Chris Dek.
Usage: From the powershell cmdlet run the command:
Import-Module .\Hundred-OneLines.psm1
..wait for a while to load.
@PSingletary
PSingletary / Schedule-ChocoUpgradeAll.ps1
Created January 13, 2018 11:09 — forked from dstreefkerk/Schedule-ChocoUpgradeAll.ps1
PowerShell script to create a scheduled task that runs a choco upgrade all at machine startup
# See if choco.exe is available. If not, stop execution
$chocoCmd = Get-Command -Name 'choco' -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Select-Object -ExpandProperty Source
if ($chocoCmd -eq $null) { break }
# Settings for the scheduled task
$taskAction = New-ScheduledTaskAction –Execute $chocoCmd -Argument 'upgrade all -y'
$taskTrigger = New-ScheduledTaskTrigger -AtStartup
$taskUserPrincipal = New-ScheduledTaskPrincipal -UserId 'SYSTEM'
$taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8
@PSingletary
PSingletary / Get-ENVPathFolders.psm1
Created January 31, 2018 16:30
Get-ENVPathFolders Function
Function Get-ENVPathFolders {
<#
.Synopsis Split $env:Path into an array
.Notes
- Handle 1) folders ending in a backslash 2) double-quoted folders 3) folders with semicolons 4) folders with spaces 5) double-semicolons I.e. blanks
- Example path: 'C:\WINDOWS\;"C:\Path with semicolon; in the middle";"E:\Path with semicolon at the end;";;C:\Program Files;'
- 2018/01/30 by [email protected] - Created
.Link http://blogs.catapultsystems.com/chsimmons/archive/2018/01/30/parse-envpath-with-powershell/
#>
$PathArray = @()
@PSingletary
PSingletary / Get-RemoteDotNetVersion.ps1
Created February 2, 2018 10:49
PowerShell oneliner to list all the installed .NET versions on a remote computer
"v1.1.4322","v2.0.50727","v3.0","v3.5","v4\Full"|%{([Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Computer)).OpenSubKey("SOFTWARE\Microsoft\NET Framework Setup\NDP\$_").GetValue('version')}
@ECHO OFF
FOR /f "tokens=*" %%G in ('dir /b /a:d-s-l "%SystemDrive%\Users"') DO (
IF /I NOT "%%G"=="Public" (
IF NOT EXIST "%SystemDrive%\Users\%%G\%~2\%~1" md "%SystemDrive%\Users\%%G\%~2\%~1"
xcopy.exe "%~dp0%~1" "%SystemDrive%\Users\%%G\%~2\%~1" /E /C /I /Q /H /R /K /Y
)
)
#Set-BingWallpaperAsDesktop.ps1 - [email protected]
# Great help from: https://www.kittell.net/code/powershell-remove-windows-wallpaper-per-user/
#$DebugPreference = 'Continue'; #uncomment if you want to see all the steps
#region types
Add-Type @"
using System;
using System.Runtime.InteropServices;
$Credential = Get-Credential -Message User: username@DOMAIN or Domain\Username
While ($true){
write-host ""
$OldComputerName = Read-Host "What is the old computer name?"
$NewComputerName = Read-Host "What is the new computer name?"
$Restart = Read-Host "Restart the computer? Y for yes or N for no."
if ($Restart -eq "Y"){
Rename-Computer -ComputerName $OldComputerName -NewName $NewComputerName -Restart -Force -DomainCredential $Credential -verbose
<#
1> User whose password is going to Expire in X days [You set the threshold]
2> And Urgent message with High Importance! whose in within 2-3 days you can set the threshold.
3> save the script as Passwordexpiryreminder.ps1 under c:\scripts for any folder and schedule to send using task scheduler, learn how to create a task.
https://community.spiceworks.com/how_to/17736-run-powershell-scripts-from-task-scheduler
#>
$reminderdays="14" # Remind before days.
$priorityreminder="3" # set Days before you want to message with High Importance.
$outfile="c:\scripts\temp" # Output path to whom email was sent and days to expire.
$from="Emailaddress" #Enter email senders email.
#DeleteOrphanProfiles.ps1
#Performs a SID lookup for each profile in the local computer. If it can't match the SID with a real
#user, the profile gets whacked.
#Needs local admin priv.
$ALLLocalProfiles = Get-WmiObject -Class Win32_UserProfile
foreach ($ThisProfile in $ALLLocalProfiles){
$ProfileSID = $ThisProfile.sid
$ProfilePath = $ThisProfile.localpath