Archive for the ‘Windows Server’ Category.
February 17, 2023, 2:54 pm
Some reason Print Management Console is not installed by default on Windows 10 Pro and Windows 11 Pro on recent builds. Has to be manually installed. New Windows 10 & 11 Settings for printer is just garbage in my opinion. Use Print Management for real control of printer and print drivers.
DISM /online /add-capability /CapabilityName:Print.Management.Console~~~~0.0.1.0
After it is installed it can ran by searching for “Print Management” or running “printmanagement.msc”
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: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: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:18 pm
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'
February 17, 2023, 2:12 pm
$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
}
}
February 17, 2023, 2:00 pm
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"
February 17, 2023, 1:56 pm
Path has to exist for the Backup-GPO command to work.
Import-Module GroupPolicy
Backup-GPO -All -Path "C:\GPOs
February 17, 2023, 12:58 pm
Reboot will be required after adding this to registry
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender" /f /v DisableAntiSpyware /t REG_DWORD /d 0x00000001