If you need to export all available Windows Event Logs, especially in the Windows Server Core edition (without GUI), you can utilize this PowerShell script:
Ansible/Packer over WinRM can experience UAC Elevated rights issues if logged over the network.
To fix the issue:
# Set LocalAccountTokenFilterPolicy to 1
$token_path = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"
$token_prop_name = "LocalAccountTokenFilterPolicy"
$token_key = Get-Item -Path $token_path
$token_value = $token_key.GetValue($token_prop_name, $null)
if ($token_value -ne 1) {
Write-Host "Setting LocalAccountTokenFilterPolicy to 1"
if ($null -ne $token_value) {
Remove-ItemProperty -Path $token_path -Name $token_prop_name
}
New-ItemProperty -Path $token_path -Name $token_prop_name -Value 1 -PropertyType DWORD > $null
}
To better protect those users who are members of the local Administrators group, we implement UAC restrictions on the network. This mechanism helps prevent against loopback attacks. This mechanism also helps prevent local malicious software from running remotely with administrative rights.
In case you want to get maximal value without rounding/flooring – to be exact you should not use Measure-Object. You need to enumerate array (which is also faster).
In case you need to determine what language was Windows OS/Server installed run following script in powershell:
Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language" | Select-Object InstallLanguage
Compare returned HEX value from powershell with this table:
Example of the Powershell script which can modify IE LAN Proxy Exception List to keep current settings (for example pulled by GPO) and extend with custom exception list.Most important is to modify first line.
This guide explains how to download latest camera record available on UniFi NVR server via Powershell through the REST API with SSL self-signed certificate.
Script which will scan all DHCP scopes and report in which is MAC address located (if any).
# MAC Address to search:
$MacAddress = "E4-A4-71-4E-21-77"
Import-Module DhcpServer -ErrorAction Stop
Get-DhcpServerv4Scope | ForEach-Object {
# To make static lease uncomment "#" in "#| Add-DhcpServerv4Reservation"
Get-DhcpServerv4Lease -ScopeId $_.ScopeId | Where-Object { $_.ClientId -eq $MacAddress } #| Add-DhcpServerv4Reservation
}
If you wish to make static lease for MAC address, uncomment the “ | Add-DhcpServerv4Reservation”.
Example how to split text into 2 part with Powershell version 2+.
Example 1:
#Simple text split based on delimiter
$text = "Left Part;Right Part"
$pos = $text.IndexOf(";")
$leftPart = $text.Substring(0, $pos)
$rightPart = $text.Substring($pos+1)
Write-Output $leftPart
Write-Output $rightPart
Example 2:
This article contains Powershell script which will backup Active Directory Group Policy Objects.
#-----User variables to modify-----#
$Path = "C:\Backups\GPO-Backup" #Destination backup folder
$Days = "30" #How many days to keep in backup $Path folder
#----------------------------------#
#--Execution code (do not touch)---#
$ActualDate = (Get-Date -Format d.M.yyyy__H_mm_s) #Actual date for folder creation
$sw = [system.diagnostics.stopwatch]::startNew()
If ((Test-Path -Path $Path)) {
If (Get-Module -ListAvailable -Name GroupPolicy) {
$sw.Start()
Import-Module GroupPolicy -ErrorAction Stop
New-Item -Path "$Path\$ActualDate" -ItemType directory
Start-Transcript -Path "$Path\$ActualDate\TranscriptLog.txt" #To Keep GpoId and Id history to better identify GPOs
Backup-GPO -All -Path "$Path\$ActualDate"
$DeleteFolders = (Get-ChildItem -Path $Path | Where-Object PSIsContainer -eq "True" | Where-Object CreationTime -le (Get-Date).AddDays(-$Days) ) | Remove-Item -Force -Recurse
$sw.Stop()
Write-Output "Finished! Removed backup GPO folders based on '$Days' days retention period. Elapsed time: $($sw.Elapsed.Seconds) seconds."
Stop-Transcript
}#EndIf
Else {
Write-Warning "Script stopped! GroupPolicy module is not installed on this machine!"
}#EndElse
}#EndIf
Else {
Write-Warning "Script stopped! Provided path '$Path' does not exist!"
}#EndElse
#----------------------------------#
Tip how to schedule with Tasks Scheduler Powershell script which contains function we need to run and parameters.
Scenario:
Our scheduled task will contain in tab Actions following action: