This is a motivational test document.
This has very beautiful meaning
Check list of hotfix installed on list of servers
$computers = get-content -Path ./servers.txt
$patches = get-content -path ./kb.txt
foreach ($computer in $computers){
$computer = $computer.trim()
$computer
$name=(Get-WmiObject Win32_OperatingSystem -ComputerName $computer).caption
$bit=(Get-WmiObject Win32_OperatingSystem -ComputerName $computer).OSArchitecture
foreach ($patch in $patches){
$patch = $patch.trim()
$results = Get-HotFix -id $patch -ComputerName $computer -OutVariable results -ErrorAction
SilentlyContinue
$results
if ($results -ne $null) {
Add-content "$Patch is Present in $computer, $name, $bit" -path ./$($patch)Present.txt
}
else {
Add-content "$Patch is not Present in $computer, $name, $bit" -path ./$($patch)notpresent.txt
}
$results = ""
}
}
File System Management
Inheritance disabled on remote path
https://www.petri.com/identify-folders-with-blocked-inheritance-using-powershell
dir \\cdc1-v-rdssh5\c$\test -Directory -recurse | get-acl |
Where {$_.AreAccessRulesProtected} |
Select @{Name="Path";Expression={Convert-Path $_.Path}},AreAccessRulesProtected | ft –
AutoSize
recursively File copy using include function
# https://stackoverflow.com/questions/22728174/how-to-copy-file-names-matching-a-regex-in-
powershell?rq=1 - working
$source = '\\cdc1-v-rdssh3\c$\Vulnerability'
$Comp = "CDC1-V-RDSSH2","CDC1-V-RDSSH4"
foreach ($comp1 in $comp) {
$to = "\\$comp1\c$\Vulnerability"
#$destination = '\\cdc1-v-rdssh4\c$\Vulnerability'
$filter = [regex] "x64"
$bin = Get-ChildItem -Recurse -Path $source | Where-Object {$_.Name -match $filter}
foreach ($item in $bin) {
$newDir = $item.DirectoryName.replace($source,$to)
md $newDir -ea 0
Copy-Item -Path $item.FullName -Destination $newDir
}
}
recursively File copy using Exclude function
# https://techblog.dorogin.com/powershell-how-to-recursively-copy-a-folder-structure-excluding-some-
child-folders-and-files-a1de7e70f1b
$from = '\\cdc1-v-rdssh3\c$\Vulnerability'
$Comp = "CDC1-V-RDSSH2","CDC1-V-RDSSH4"
foreach ($comp1 in $comp) {
$to = "\\$comp1\c$\Vulnerability"
#$to = '\\cdc1-v-rdssh2\c$\Vulnerability'
$exclude = @("main.js")
$excludeMatch = @("x86", "app2", "app3")
[regex] $excludeMatchRegEx = ‘(?i)‘ + (($excludeMatch |foreach {[regex]::escape($_)}) –join “|”) + ‘’
Get-ChildItem -Path $from -Recurse -Exclude $exclude |
where { $excludeMatch -eq $null -or $_.FullName.Replace($from, "") -notmatch $excludeMatchRegEx} |
Copy-Item -Destination {
if ($_.PSIsContainer) {
Join-Path $to $_.Parent.FullName.Substring($from.length)
} else {
Join-Path $to $_.FullName.Substring($from.length)
}
} -Force -Exclude $exclude
}