This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$sourceDir = 'C:\SourceDir\' | |
$targetDir = 'C:\DestDir\' | |
Get-ChildItem $sourceDir -Filter "*" -Recurse |` | |
Where-Object {$_.LastWriteTime -gt (Get-Date).addDays(-1) -and -not $_.PSIsContainer} |` | |
foreach { | |
$targetFile = $targetDir + $_.FullName.SubString($sourceDir.Length); | |
New-Item -ItemType File -Path $targetFile -Force; | |
Copy-Item $_.FullName -destination $targetFile | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reset Windows COM port settings | |
# 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\COM Name Arbiter' ComDB | |
$path='HKLM:\SYSTEM\CurrentControlSet\Control\COM Name Arbiter' | |
Set-ItemProperty -Path $path -Name Test -Value ([byte[]](0x01)) -Verbose | |
# 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports' | |
$path='HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports' | |
Get-ItemProperty $path | Get-Member -MemberType NoteProperty | where Name -like 'COM*' | foreach { Remove-ItemProperty -Path $path -Name $_.Name -Verbose } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# check GPO files on SYSVOL for every .adm and .admx file has a correspondant resource .adml file in language sub dir. | |
# https://learn.microsoft.com/en-us/troubleshoot/windows-server/group-policy/create-central-store-domain-controller | |
# | |
$p='\\ad.contoso.local\sysvol\ad.contoso.local\Policies\PolicyDefinitions' | |
$langdirs= Get-ChildItem -Path $p -Directory -Filter '*-*' | |
Set-Location -Path $p | |
$adm = Get-ChildItem -Path $p -File |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$LogPath='C:\Temp' | |
$LogPath+='\' | |
$LogFilename='Filename.log' | |
# Use RegEx named capture groups for automatic PropertyName e.g. (?<GroupName>.+) | |
$LogPattern='^(?<date>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2},\d{3})\s(?<level>[A-Z]+)\s(?<component>\[[\w.]+\])\s\((?<object>\S+)\)\s(?<exception>[\w\s:.\(\)]+)\s\[(?<eceptionid>\d+)\]\s(?<error>\w+)\s(?<errorid>[-\d]+)' | |
$A=Select-String -Pattern $LogPattern -Path $LogPath$LogFilename | |
$Output = @() | |
foreach ($M in $A.Matches) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Lists all active local TCP ports and ask which to check for connections | |
# https://gist.github.com/winkler-winsen/f8f7ac2d25bae2c92b05ce20389b2d1a | |
(Get-NetTCPConnection -State Established | | |
Where-Object -FilterScript { $_.LocalAddress -notlike '127.0.0.1' -and $_.LocalAddress -notlike '::1' } | | |
Sort-Object -Unique LocalPort | | |
Select-Object @{L="Proto"; E={"TCP"}}, | |
LocalAddress, | |
LocalPort, | |
@{L="Connections"; E={((Get-NetTCPConnection -State Established -LocalPort $_.LocalPort).Count)}}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# source: https://devblogs.microsoft.com/scripting/use-powershell-to-work-with-any-ini-file/ | |
# alternatively you can use PsINI Module https://www.powershellgallery.com/packages/PsIni/3.1.2 | |
function Get-IniContent ($filePath) | |
{ | |
$ini = @{} | |
switch -regex -file $FilePath | |
{ | |
“^\[(.+)\]” # Section | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://learn.microsoft.com/en-us/sql/powershell/download-sql-server-ps-module?view=sql-server-ver16 | |
$creddi=Get-Credential # DB user credentials | |
$sqlsrv='ITK-AG2' # DB server | |
$dbnames='itkh_*' # DB table search pattern or just the name | |
$share='\\PC7231\Freigabe\' # Network share for backup place. SQL server must have write rights onto it | |
$now=Get-Date -Format 'yyyymmdd_HHmmss' | |
Get-SqlDatabase -ServerInstance $sqlsrv | | |
Where-Object -FilterScript { $_.Name -like $dbnames} | | |
ForEach-Object { | |
Backup-SqlDatabase -Credential $creddi -ServerInstance $sqlsrv -Database $_.Name -CopyOnly -BackupFile "$share$now.$sqlsrv.$($_.Name).sqlbak" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(Get-NetUDPEndpoint | | |
Select-Object @{L="Proto"; E={"UDP"}}, | |
LocalAddress, | |
LocalPort, | |
OwningProcess, | |
@{L="Process"; E={((Get-Process -ID $_.OwningProcess).Name)}}, | |
@{L="Path"; E={((Get-Process -ID $_.OwningProcess).Path)}}) + | |
(Get-NetTCPConnection -State Listen | | |
Select-Object @{L="Proto"; E={"TCP"}}, | |
LocalAddress, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Path='C:\' | |
$SearchFiles=@( | |
'.exe', | |
'.dll' | |
) | |
Write-Host "Suche Dateien..." | |
Write-Host "--------- GCI -------------" | |
Measure-Command { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$LogPath = "E:\" | |
$LogMaxDays = -30 | |
$CurrentDate = Get-Date | |
$DateToDelete = $CurrentDate.Date.AddDays($LogMaxDays) | |
Get-ChildItem -Path $LogPath -File -Filter '*.log' | Where-Object LastWriteTime -LT $DateToDelete | Remove-Item -Confirm | |
NewerOlder