Skip to content

Instantly share code, notes, and snippets.

@justinloring
justinloring / ConvertDocxToPDF.ps1
Created April 27, 2020 17:54
Convert DOCX to PDF
$Word = New-Object -ComObject Word.Application
$Doc = $Word.Documents.Open("$logfilepath\$logfile.docx")
$Name = ($Doc.FullName).replace('docx', 'pdf')
$Doc.SaveAs($Name, 17)
$Doc.Close()
$statusbar1.Text = "PDF has been save to C:\RSItemp\$Name"
@justinloring
justinloring / ConvertTo-OSCWord.ps1
Created April 27, 2020 17:54
Convert TXT to DOCX
Function ConvertTo-OSCWord
{
<#
.SYNOPSIS
ConvertTo-OSCWord is an advanced function which can be used to covert txt file to Word document file.
.DESCRIPTION
ConvertTo-OSCWord is an advanced function which can be used to covert txt file to Word document file.
.PARAMETER Path
Specifies the path of Word document.
.EXAMPLE
@justinloring
justinloring / Send-MessageWithWait.bat
Created March 10, 2020 18:22
MSG.exe w/Wait for OK button
ping 127.0.0.1 -n 5
MSG console /W "TEST MESSAGE"
ping 127.0.0.1 -n 5
@justinloring
justinloring / RobocopyTransfer.ps1
Created January 20, 2020 16:17
Robocopy Transfer
New-Item -ItemType Directory -Path C:\Drivers\WIN -Force
Invoke-Command -ScriptBlock {Robocopy .\Thunderbolt C:\Drivers\WIN\Thunderbolt /MIR}
Invoke-Command -ScriptBlock {Robocopy .\Thunderbolt C:\Drivers\WIN\Thunderbolt_FW /MIR}
Invoke-Command -ScriptBlock {MSIEXEC /I C:\Drivers\WIN\Thunderbolt\Setup.msi /Q}
@justinloring
justinloring / Send-TextAlert.ps1
Created January 13, 2020 13:56
Send-TextAlert.ps1
Read-Host "Make sure email list has been created before pressing enter."
$ver = "@vtext.com"
$att = "@txt.att.net"
$spr = "@messaging.sprintpcs.com"
$tmo = "@tmomail.net"`
#Send-MailMessage -From "s7@republicservices.com" -To "8155308515@vtext.com" -Subject "DP HDD Storage Alert" -SmtpServer "relay.repsrv.com" -Body "D-721-01 has dropped below storage threshold."
Send-MailMessage -From "s7@republicservices.com" -To "2193063146@txt.att.net" -Subject "DP HDD Storage Alert" -SmtpServer "relay.repsrv.com" -Body "D-721-01 has dropped below storage threshold."
@justinloring
justinloring / Get-DeploymentStatusByCollection.ps1
Last active December 10, 2019 19:12
SCCM App Deployment Collection Status - Powershell
function Get-DeploymentStatusByCollection
{
$CollectionName = Read-Host "Enter Collection Name"
$SiteServer = "Prodcmapp01.repsrv.com "
$SiteCode = "EPM"
$SiteDrive = $SiteCode + ":"
Import-Module (Join-Path -Path (($env:SMS_ADMIN_UI_PATH).Substring(0, $env:SMS_ADMIN_UI_PATH.Length - 5)) -ChildPath "\ConfigurationManager.psd1") -Force
if ((Get-PSDrive $SiteCode -ErrorAction SilentlyContinue | Measure-Object).Count -ne 1)
@justinloring
justinloring / PrinterMigration.ps1
Created September 12, 2019 18:00
PrinterMigration
#Export Printers
New-Item -ItemType Directory -Path C:\RSItemp\mystore -Force
Invoke-Command -scriptblock {cmd /c "C:\Windows\System32\spool\tools\Printbrm.exe /b /f C:\RSItemp\mystore\backup.printerExport"} -ComputerName <PCNAME>
#Import Printers
Invoke-Command -scriptblock {cmd /c "C:\Windows\System32\spool\tools\Printbrm.exe /r /f C:\RSItemp\mystore\backup.printerExport"} -ComputerName <PCNAME>
@justinloring
justinloring / Get-ActiveNICUptime.ps1
Created July 30, 2019 13:05
Active Network Interface Uptime
Get-CimInstance Win32_networkadapter | Where NetEnabled -eq $true | ft Name,TimeOfLastReset -auto
@justinloring
justinloring / Create-EncryptionKeyandCredential.ps1
Created July 17, 2019 13:46
Create Encryption Key/Credential
$Key = New-Object Byte[] 32
[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($Key)
$Key | out-file '\\srilcredev01\c$\RSICode\StoredCreds\aes.key'
$credential = Get-Credential
$credential.Password | ConvertFrom-SecureString -key (get-content '\\srilcredev01\c$\RSICode\StoredCreds\aes.key') | Set-Content '\\srilcredev01\c$\RSICode\StoredCreds\LogOnAsBatch.txt'
@justinloring
justinloring / Create-LogOnAsBatchScheduledTask.ps1
Created July 17, 2019 13:45
Create LogOnAsBatch Scheduled Task w/Hidden Password
$encrypted = Get-Content '\\srilcredev01\c$\RSICode\StoredCreds\LogOnAsBatch.txt' | ConvertTo-SecureString -Key (Get-Content '\\srilcredev01\c$\RSICode\StoredCreds\aes.key')
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($encrypted)
$UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
$Action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-ExecutionPolicy Bypass -File "C:\RSItemp\RunMe.ps1"'
$Trigger = New-ScheduledTaskTrigger -At "07/17/2019 08:47" -Once
$Settings = New-ScheduledTaskSettingsSet -StartWhenAvailable
$Principal = New-ScheduledTaskPrincipal -UserID "repsrv\svc-sccmtask" -LogonType ServiceAccount -RunLevel Highest
$Password = "$UnsecurePassword"
$UserName = "repsrv\svc-sccmtask"
$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings -Principal $Principal