Skip to content

Instantly share code, notes, and snippets.

$servers = Get-Content C:\temp\serverlist.txt
function Report-Printer {
param ($server = $env:computername)
$printers = Get-Printer -ComputerName $server
$drivers = Get-PrinterDriver -ComputerName $server
foreach ($printer in $printers) {
$ver = $drivers | where {$_.name -eq $printer.drivername} | select -first 1 | select -expand DriverVersion
$rev = $ver -band 0xffff
$build = ($ver -shr 16) -band 0xffff
@pstakuu
pstakuu / Change-HKCUasAdmin.ps1
Created November 1, 2022 15:02
HKCU changes as admin - specifically this one for hiding ads in Outlook
$loggedonUser = get-wmiobject -Class win32_computersystem |select username
$objuser = new-object System.Security.Principal.NTAccount($loggedonUser.username)
$userdata = $objuser.Translate([System.Security.Principal.SecurityIdentifier])
Set-ItemProperty "registry::hkey_users\$($userdata.value)\Software\Microsoft\Office\16.0\Common\TargetedMessagingService\MessageMetadata\*MsgId:BizBar" -Name AppIdOnAction -Value 6
Set-ItemProperty "registry::hkey_users\$($userdata.value)\Software\Microsoft\Office\16.0\Common\TargetedMessagingService\MessageMetadata\*MsgId:BizBar" -Name SetUserAction -Value 2
#current user changes as admin: https://stackoverflow.com/questions/66066661/how-to-edit-hkcu-values-with-powershell#:~:text=When%20running%20an%20elevated%20PowerShell%2C%20the%20user%20specific,SID%3E....%20For%20example%3A%20Get-ItemProperty%20-Path%20%22registry%3A%3Ahkey_users%24%20%28%24strSID.Value%29SoftwarePoliciesMicrosoftWindowsControl%20PanelDesktop%22
#reg settings: https://community.spiceworks.com/topic/2276
#Function to Get Permissions on a particular on List, Folder or List Item
Function Get-PnPPermissions([Microsoft.SharePoint.Client.SecurableObject]$Object)
{
#Determine the type of the object
Switch($Object.TypedObject.ToString())
{
"Microsoft.SharePoint.Client.ListItem"
{
If($Object.FileSystemObjectType -eq "Folder")
{
@pstakuu
pstakuu / OutFileUTF8NoBom.ps1
Created August 12, 2022 14:15
outputs UTF-8 files to Linux format with no BOM
<#
.SYNOPSIS
Outputs to a UTF-8-encoded file *without a BOM* (byte-order mark).
.DESCRIPTION
Mimics the most important aspects of Out-File:
* Input objects are sent to Out-String first.
* -Append allows you to append to an existing file, -NoClobber prevents
overwriting of an existing file.
* -Width allows you to specify the line width for the text representations
@pstakuu
pstakuu / Set-AutoAttendantAudioFile.ps1
Created August 12, 2022 14:14
allow you to record a message with sound recorder in windows, convert to mp3, upload to an auto-attendant in MSFT Teams; requires VLC
function Set-AutoAttendantAudioFile {
Param (
$originalAudioFile = "C:\Sound recordings\Recording (8).m4a",
$autoAttendantName = “Teams Testing”,
$VLCInstall = 'C:\Program Files\VideoLAN\VLC\vlc.exe'
)
if (!(Test-Path $VLCInstall)) {
"Need to install VLC or specify different install directory for VLC.exe"
}
@pstakuu
pstakuu / Resolve-IPs.ps1
Created August 12, 2022 14:12
resolve IP address list to hostnames
$IPs = import-csv C:\Scripts\Input\Dev_IPs_Final.csv
$zones = Get-DnsServerZone
#decided to use function instead of adding the results to an array
#when I did the array and tried to export to csv, it was all pissy because CSV needed objects and it kept outputting the line length
function Resolve-IPs{
param (
$IPs,
$zones
@pstakuu
pstakuu / Create-PerUserFirewallPolicy.ps1
Created August 12, 2022 14:10
Can create per-user firewall policies on windows - needed for adding firewall rules to profiles for apps, like Airtame
# Description: Installs Windows Firewall Exceptions for the portable airtame.exe application.
# Rules will be dynamically installed for each user that is currently logged into the machine.
#
$FWRuleDisplayName = "airtame portable exe"
$FWRuleDescription = "airtame.exe"
$ProgramPath = "appdata\local\temp\airtame-portable\airtame.exe"
Write-Verbose -Message "Getting all firewall rules that have exceptions for: $($ProgramPath)"
$CurrentRules = Get-NetFirewallApplicationFilter -Program "*$ProgramPath" -PolicyStore PersistentStore -ErrorAction Ignore | Get-NetFirewallRule -ErrorAction Ignore
@pstakuu
pstakuu / Parse-RADIUSLogs.ps1
Created August 12, 2022 14:09
used to parse RADIUS log files
$files= Get-childitem Y: | select -last 90
function Process-RADIUSLogs () {
[CmdletBinding()]
param(
$file,
[switch]$onlyAccepted
)
if ($onlyAccepted) {Write-Verbose "Processing only authenticated attempts"}
@pstakuu
pstakuu / Join-Object.ps1
Created August 12, 2022 14:08
Can't remember where I got this either... but it's been useful for combining like SQL
function AddItemProperties($item, $properties, $output)
{
if($item -ne $null)
{
foreach($property in $properties)
{
$propertyHash =$property -as [hashtable]
if($propertyHash -ne $null)
{
$hashName=$propertyHash[“name”] -as [string]
@pstakuu
pstakuu / ConvertTo-MP3.ps1
Created August 12, 2022 14:02
converts other sound formats to mp3 - can't remember where I grabbed this from but put it together and requires VLC
function ConvertToMp3( $file, [string] $vlc = 'C:\Program Files\VideoLAN\VLC\vlc.exe') {
PROCESS {
$codec = 'mp3';
$oldFile = Get-Item $file;
$newFile = $oldFile.FullName.Replace($oldFile.Extension, ".$codec");
&"$vlc" -I dummy "$oldFile" ":sout=#transcode{acodec=$codec,vcodec=dummy}:standard{access=file,mux=raw,dst=$newFile}" vlc://quit | out-null;
#Only remove source files when you are sure that the conversion works as you want