powershell

  • Welcome to ITBible, we're your #1 resource for enterprise or homelab IT problems (or just a place to show off your stuff).
  1. WizardTux

    PowerShell Delete files older than x amount of days from Downloads

    Pretty simple script, this just remove files from your downloads folder that are older than x amount of days (by default its set to 60). $Paths = @( "%userprofile%\Downloads\" ) $Days = 60 $limit = (Get-Date).AddDays(-$Days) foreach ($Path in $Paths) { # Delete files older than the...
  2. Andy

    PowerShell Execution Policy & Profile Impact

    After writing about prompt customizations, I realized that I likely need to address a common issue that pops up when users are first configuring their PowerShell (PS) environment. If you have not read that post yet, I would start there before continuing with this one. As we discussed in that...
  3. Andy

    PowerShell Customizing PowerShell Prompt & Profile Tips

    I have a thing about command line prompts. I like tweaking and customizing. The prompt is such a simple thing, but impacts experience dramatically. Once I learned about prompt customization, I found a general format that works for me and can be replicated across multiple environments and...
  4. WizardTux

    PowerShell Create URL Shortcuts

    Just a quick script on creating URL Shortcuts, defaults to the Public user desktop and has support for custom icons. param ( [string]$Path, [Parameter(Mandatory=$true)] [string]$Name, [Parameter(Mandatory=$true)] [string]$URL, [string]$IconUrl, [string]$IconPath =...
  5. WizardTux

    PowerShell Enable AD Recycle Bin

    This was quick and dirty / probably needs some more work I'll add it to GitHub later. Import-Module ActiveDirectory if ((Get-ADOptionalFeature -Identity 'Recycle Bin Feature').EnabledScopes) { Write-Host "AD Recycle Bin Enabled" } else { try { $domain = Get-WmiObject...
  6. WizardTux

    PowerShell Clear Stuck Print Jobs

    Just a way to clear print jobs that may be stuck "printing" or if they are in error status. $PrintJobs = get-wmiobject -class "Win32_PrintJob" -namespace "root\CIMV2" -computername "." foreach ($job in $PrintJobs) { $pos = ($job.Name).IndexOf(",") $printerName =...
  7. WizardTux

    PowerShell Hard Link AD Sync User

    The process of hard linking AD objects to AAD objects for when you get errors during an AD Sync. On the domain controller run: Get-ADUser username | Select-Object UserPrincipalName, objectGUID, @{Name = 'ImmutableID'; Expression = {...
  8. WizardTux

    PowerShell Get process that is holding a port open

    Pretty simple script that will answer to what process is using a port. param( [Parameter(Mandatory=$true)] [string]$port #e.g. 443 ) # Pull PID from TCP Connections and then outputs process name(s) $pids = (Get-NetTCPConnection | Where-Object { $_.LocalPort -eq $port }) |...
  9. WizardTux

    PowerShell Microsoft365 - Check users without litigation hold being enabled.

    This is a pretty simple one, but it gives you a list of users where litigation hold is not enbaled. Connect-ExchangeOnline -UserPrincipalName <global-admin-account> Get-Mailbox | Where-Object { $_.LitigationHoldEnabled -eq $false }
  10. WizardTux

    PowerShell Check Application Version

    Simple way to get the version of an application via PowerShell. Param( [Parameter(Mandatory=$true)] $ApplicationName ) $InstalledSoftware = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall" if($ApplicationName -ne $null) { foreach($obj in...
  11. WizardTux

    PowerShell Clear Print Jobs

    Have you ever wanted to run a script that would just clear the user's errored print queue? With this you can put it in your RMM and have it run against a users machine and the print server (so it clears out anything that is errored). $PrintJobs = get-wmiobject -class "Win32_PrintJob" -namespace...
  12. WizardTux

    PowerShell StorCLI

    Battery Status This will return an error if something is wrong otherwise it will return "Healthy." param( [string]$StorCLILocation = 'C:\Program Files (x86)\MegaRAID Storage Manager\StorCLI.exe', # Path to StorCLI [string]$StorCliCommand = "/c0 /bbu show status j" ) try {...
  13. WizardTux

    PowerShell Dell Open Manage

    The base for each of these snippets were written over at CyberDrain and I've modified them for running other commands / providing the output that we need. Battery Status This will return an error if something is wrong otherwise it will return "Healthy." $cmd = (&"C:\Program...
  14. WizardTux

    PowerShell Run Exe from Web

    So there are times that you may need to run an exe across many devices, and maybe those devices are across several organizations or not on a Windows Domain. With this script you can upload the file to a central web server and the script will download the file and run it on devices. Note: This...