Lidt Powershell til at ryde op i mapper som ikke har haft file ændringer i x antal dage.
med mulighed hvor at definere antallet af dage via Registry value
#Days where nochanges have been in the folder. $Days = (get-date).AddDays(-7) # Time is used for Script test $Time = (get-date).AddMinutes(-10) $key = 'HKLM:\SOFTWARE\Policies\nethelp\Outlook' $key = 'HKLM:\SOFTWARE\nethelp\Outlook' $key = 'HKCU:\SOFTWARE\nethelp\Outlook' if(test-path $key) { $DaysTemp = (Get-ItemProperty -Path $key -Name DirAge).DirAge if ($DaysTemp) { $Days = (get-date).AddDays($DaysTemp) Write-host "Using Registry Value Calculated time" Write-Host "Compair date : " $Days } else { Write-host "Using deault Calculated time" Write-Host "Compair date : " $Days } } #Get-ChildItem C:\outlook | where-object {$_.lastwritetime -le $Days} $CleanupFolders = Get-ChildItem C:\outlook foreach($Userdir in $CleanupFolders) { Write-Host "Looking for changed Files in " $Userdir.FullName #$obj = Get-ChildItem $Userdir.FullName -Recurse | where-object {$_.lastwritetime -ge $Time} $obj = Get-ChildItem $Userdir.FullName -Recurse | where-object {$_.lastwritetime -ge $days} if ($obj) { Write-Host " Any File changed since " $time $obj } else { $obj Write-Host "Dir has not been used within defined time periode" $Days Write-Host "Removing Dir : " $Userdir.FullName # Remove-Item $Userdir.FullName -Recurse -Force } }
Et lille stykke powershell kode, da jeg havde behov for at holde en "offline" caching dir på C:\ i sync med brugere der have en profile på en maskine.
Såfremt at der ikke er en mappe af samme navn under CompairSource slettes denne på CompairTarget
$CompairSource = Get-ChildItem -path C:\users $CompairTarget = Get-ChildItem -path C:\outlook $DirConpair = Compare-Object -ReferenceObject $CompairSource -DifferenceObject $CompairTarget #$DirConpair | Where-Object {$_.SideIndicator -eq "=>"} $DirConpair | foreach { if($_.SideIndicator -eq "=>") { Write-host "=>" #$_.InputObject | gm remove-item $_.InputObject.FullName -Force -Recurse # $_ | GM } }
Et par powershell commandoer til smide en pc's mac adresse op i ad, praktisk i forhold til f.eks et WOL script
Import-Module ActiveDirectory
$mac="11:22:33:44:55:66"
Set-ADComputer -Identity <computernavn> -add @{'networkAddress'=$mac}
Fjern data lagt i "netwokAddress" attributten
Set-ADComputer -Identity <computernavn> -clear networkAddress
Data kan ses via
get-ADComputer <computernavn> -Properties networkAddress
Men husk at der går lidt tid før det er replikeret rundt i AD.
Lidt Powershell script for at hente (un)install informationer ud af Registry på en windows maskine
I tilfælde af en 32 bit maskine, vil det hele ligge her.
$RegPath="HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
foreach ( $key in dir $RegPath ) {(get-itemproperty -path registry::$key).DisplayName}
På 64 bit maskiner vil det meste ligger herunder, samt lidt I ovenstående også.
$RegPath6432="HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
foreach ( $key in dir $RegPath6432) {(get-itemproperty -path registry::$key) | ft DisplayName, Uninstallstring}
hvis man vil "cd" rundt I registry kan det klares via CD HKCU: eller CD HKLM: for at skifte til at browse I registry.
Et lille Powershell Script til at rydde op i TDCPlay's træls brandings i filer.
Param
(
[parameter(mandatory=$true,HelpMessage="Angiv RootPath til mappe med filer, ok?")][ValidateNotNullOrEmpty()]$RootPath
)
$AllFiles = Get-ChildItem $RootPath -recurse
foreach ($item in $AllFiles) {
$Ext = $item.Extension
Switch($Ext)
{
".mp3" {
$OldName = $item.FullName
$NewFilePath = $item.DirectoryName.Replace("TDCPLAY_","")
if (( Test-Path $NewFilePath) -ne $true )
{
New-Item $NewFilePath -type directory
}
$NewFileName = $item.name.Replace("TDCPLAY_","")
$New = $NewFilePath + "\" + $NewFileName
Copy-Item $OldName $New
}
".wma" {$item.Delete}
".m3u" {$item.Delete}
}
}
}
Page 2 of 2