February 17, 2023, 2:48 pm
You can store and recall password with Windows Credential manger. Great to enter saved password to be used within batch scripts.
Base command is: cmdkey
Documentation on microsoft’s website
For Powershell use CredentialManger module
https://www.powershellgallery.com/packages/CredentialManager/2.0
February 17, 2023, 2:45 pm
Set various timeout setting for sleep, hibernate, disk, and monitor. Below will disable all timeouts. Great for VM workstations that need to run 24/7
powercfg /x -hibernate-timeout-ac 0
powercfg /x -hibernate-timeout-dc 0
powercfg /x -disk-timeout-ac 0
powercfg /x -disk-timeout-dc 0
powercfg /x -monitor-timeout-ac 0
powercfg /x -monitor-timeout-dc 0
Powercfg /x -standby-timeout-ac 0
powercfg /x -standby-timeout-dc 0
February 17, 2023, 2:44 pm
Invoke-WebRequest
Invoke-WebRequest
-Uri
https://example.com/files/myfile.exe -OutFile
$env:USERPROFILE\Downloads\
myfile.exe
February 17, 2023, 2:42 pm
These tools can be install on any workstation to administrate servers remotely. Command below will install all Window Server tools
Get-WindowsCapability -Online |? {$_.Name -like "*RSAT*" -and $_.State -eq "NotPresent"} | Add-WindowsCapability -Online
February 17, 2023, 2:40 pm
for /f %i in ('forfiles /D -12/31/2011 /c "cmd /c echo @FILE"') do @7z a Archives/%~i.7z %~i -mmt=on -sdel -stl
- Command is to be ran at same folder you want to compress every file into a single 7z.
- Forfiles /D will only select files older than specified date.
- It will place each 7z into Archives subfolder.
- Keeps the date of the file inside as archive date.
- “-sdel” Delete file when done.
February 17, 2023, 2:37 pm
Reference this documenation for more commands and options. This works only in Windows 10
https://docs.microsoft.com/en-us/powershell/module/printmanagement/?view=win10-ps
here are some example commands to add port, view printers, and update their port configurations. These are running from batch shell.
powershell -Command "Add-PrinterPort -Name "10.3.0.50" -PrinterHostAddress "10.3.0.50" -SNMP 1 -SNMPCommunity public"
powershell -Command "Add-PrinterPort -Name "10.3.0.51" -PrinterHostAddress "10.3.0.51" -SNMP 1 -SNMPCommunity public"
powershell -Command "get-printer"
powershell -Command "Set-Printer -Name CanonBW -PortName "10.3.0.51""
powershell -Command "Set-Printer -Name CanonColor -PortName "10.3.0.50""
February 17, 2023, 2:36 pm
Get-ADComputer -filter * | select name | ft
February 17, 2023, 2:35 pm
Get-ChildItem 'C:\path\to\files' | Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-7))} | Remove-Item
February 17, 2023, 2:34 pm
Function Test-ADAuthentication {
param($username,$password)
(new-object directoryservices.directoryentry "",$username,$password).psbase.name -ne $null
}
Test-ADAuthentication "dom\myusername" "mypassword"
February 17, 2023, 2:33 pm
##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