Author Archive

Exchange Online – Import deleted mailbox into a new mailbox

##Log into Exchange Online
Connect-ExchangeOnline
 
##Must be deleted inbox, view all deleted inboxes with `Get-Mailbox -SoftDeletedMailbox`
$from = "bogus@email.com"
 
##Must be normal exhcange inbox.
$to = "new-bogus@email.com"
 
##Getting Exhcange Object IDs
$fromID = Get-Mailbox -SoftDeletedMailbox -Identity $from  | select ExchangeObjectId
$toID = Get-Mailbox -Identity $to | select ExchangeObjectId
 
##Uncomment to run. be sure you have all the above information correct!
#New-MailboxRestoreRequest -SourceMailbox $fromID -TargetMailbox $toID -TargetRootFolder "Imported"
#New-MailboxRestoreRequest -SourceMailbox $fromID -TargetMailbox $toID 
 
##Verify/Monitor copy progress.
$ident = Get-MailboxRestoreRequest | select Identity
Get-MailboxRestoreRequestStatistics $ident.Identity
 
##good to disconnect
Disconnect-ExchangeOnline

Windows – Edit Printer configuration CLI

You can do various thing with prnmgr.vbs. Built-in VBS script since windows vista. https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/prnmngr

Delete a Printer:

cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -d -p "Send To OneNote 2013"\

Install Driver into Driver Store:

pnputil.exe -i -a \\bwl-dc-01\NETLOGON\BrotherPrintDriver\32_64\BRPRM13A.INF


Install Printer Driver into Print Store: 

cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs -a -m "Brother MFC-L2700DW series" -h "\\server\path-to-driver\BrotherPrintDriver\32_64" -i "\\server\path-to-driver\BrotherPrintDriver\32_64\BRPRM13A.INF"

For non-servers use ` rundll32 printui.dll PrintUIEntry`   https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/ee624057(v=ws.10)?redirectedfrom=MSDN

Delete a Printer:

rundll32 printui.dll,PrintUIEntry /dl /n "Name of Printer"


Install a Printer Driver from INF:

rundll32 printui.dll,PrintUIEntry /ia /m "Name of Driver referenced in INF File" /K /h "3" /v "3" /f "Path\to\inf\file.inf"


Update printer driver:

rundll32 printui.dll,PrintUIEntry /Xs /n "Name of Printer" DriverName "Name of Driver referenced in INF File"


Add SMB printer for all users (per computer):

rundll32 printui.dll PrintUIEntry /ga /n\\print-server\SMASH

Windows – C:\ disk usage stats over CLI/Powershell

Useful with resource monitor wont load due to excessive load. Runs over PSremote or psexec with “powershell -Command” prefixed.

$counters = (Get-Counter -List PhysicalDisk).PathsWithInstances | Select-String 'C:';foreach($counter in $counters){Get-Counter -Counter $counter}

To view only specific counters

Get-Counter -Counter '\PhysicalDisk(0 C:)\% Disk Time'
Get-Counter -Counter '\PhysicalDisk(0 C:)\Avg. Disk sec/Transfer'
Get-Counter -Counter '\PhysicalDisk(0 C:)\Current Disk Queue Length'
Get-Counter -Counter '\PhysicalDisk(0 C:)\% Disk Time'
Get-Counter -Counter '\PhysicalDisk(0 C:)\Avg. Disk Queue Length'

Windows – Clean up all users Appdata Local Temp Folders

Could easily expand for other folders within user directory for better clean up. A simple btch one liner.

for /D %a in (C:\users\*) do del /S /Q %a\appdata\local\temp
for /D %a in (C:\users\*) do del /S /Q "%a\AppData\Local\Google\Chrome\User Data\Default\Cache"

Windows AD – Get list of groups and members and output to csv

$Report = "C:\Temp\report.CSV"
$STR = "Group, Member, Enabled"
Clear-Content $Report
Add-Content $Report $STR
 
$groups = get-adgroup -filter * | sort name | select Name
Foreach ($group in $groups) 
{
$curgroup = $group.name
$members = Get-AdGroupMember -identity $group.name | select name
Foreach ($member in $members)
{
$name = $member.name
$enabled = Get-ADUser -Filter {name -eq $name} -Properties * | Select-Object Enabled
$STRNew = $curgroup+","+$name+","+$enabled.Enabled
Add-Content $Report $STRNew
}
 
}

Microsoft 365 – Get password age for all users

Connect-MsolService
Get-MsolUser -All  | select DisplayName, LastPasswordChangeTimeStamp,@{Name=”PasswordAge”;Expression={(Get-Date)-$_.LastPasswordChangeTimeStamp}}

Run MSI installer on a remote PC with psexec

This will require psexec. You can get it from microsoft. Works best with Windows AD where user running command is an administrator granting access to remote workstation and file server path where MSI install resides.

psexec.exe \\remote-pc-hostname -d -s cmd /c "msiexec /I "\\remote-server\path\to\installer.msi" /quiet /qn /norestart"

Windows AD – Backup all GPOs with PowerShell.

Path has to exist for the Backup-GPO command to work.

Import-Module GroupPolicy
Backup-GPO -All -Path "C:\GPOs

Windows 10 – Disable Auto update of sponsored apps (e.g. Candy Crush)

Windows 10 Sponsored apps suck. Depending on your OEM some are worse than others. This wont fix all sponsored crud, but its a start.

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\CloudContent" /f /v DisableWindowsConsumerFeatures /t REG_DWORD /d 0x00000001

Windows – Get serial number of PC / Workstation

Great way to get SN used to for warranty and support lookup on OEM PCs

wmic bios get serialnumber