7Zip Extract Rar Files to Folder from rar Name

# To run on your computer, Install the Powershell 7 Zip Module
# https://github.com/thoemmi/7Zip4Powershell

# ==================
# Extract .rar files
# ==================
Import-Module 7zip4Powershell
$Folder = "C:\Temp\Ebooks 2013\"
$rars = Get-ChildItem "$Folder\*.rar"
#Get-ChildItem *.rar
ForEach ($rar in $rars){  
    $outputFolder = [io.path]::GetFileNameWithoutExtension("$rar")
    Write-Output "$outputFolder"
    
    Expand-7Zip -ArchiveFileName $rar -TargetPath "$Folder\$outputFolder"
    
}

 

Get Fim / Mim History runs and clear them if they older then “n” Days

#https://fimfacts.wordpress.com/2013/01/15/export-and-delete-the-fim-sync-run-history-using-powershell/
#https://social.technet.microsoft.com/Forums/en-US/04e9cf9a-74e5-44ac-b634-f6b5a5793de9/save-and-clear-run-history-in-fim-2010-r2?forum=ilm2

#Above the sites i found almost the same script. I changed it for my purpose. I hope you will give the other persons and me the credits if you use this script.
#https://kuipers.eu/get-fim-mim-history-runs-and-clear-them-if-they-older-then-n-days

    $exportDirectory ="C:\FIM_Scripts\Run-Exports\"
    $dayDiff = "31"

    $dateDelete = Get-Date

    #if the dayDiff parameter is passed, subtract it from the current day.
    If($dayDiff -ne 0)
    {
    $dateDelete = $dateDelete.AddDays(-$dayDiff)
    }
    Else
    {
    $dateDelete = $dateDelete.AddDays(1)
    }

    # Rewrite the dateDelete so it can be compared.
    $dateDelete = $dateDelete.ToString("yyyy-MM-dd")

    #if the exportDirectory parameter is passed, save the run history to that directory
    If($exportDirectory -ne “”)
    {
    Write-Host “Exporting run history, older then days definden in varable $daydiff.”
    $lstManagementAgents = @(get-wmiobject -class “MIIS_RunHistory” -namespace “root\MicrosoftIdentityIntegrationServer” -computer “.” | Sort-Object RunEndtime -Descending | where RunEndtime -LE $dateDelete)
#   $lstManagementAgent = @(get-wmiobject -class “MIIS_RunHistory” -namespace “root\MicrosoftIdentityIntegrationServer” -computer “.” | Sort-Object RunEndtime -Descending | Select-Object -First 4 | Select-Object -Skip 2)
    
    $runDetails = foreach ($lstManagementAgent in $lstManagementAgents)
    {
    $lstManagementAgent.RunDetails().ReturnValue
    }
    
    # I decided to use the $dateDelete instead of $today. Because i want to export only runs till the delete day
    $filePathName = $exportDirectory + "Runs-till-$dateDelete.xml”
    $runDetails |Out-File $filePathName

    Write-Host “Successfully exported run history to: ” $filePathName
    }

    #finally, delete the run history:
    #Define the date again, because of diffrent Date notation.
    $dateDelete = Get-Date
    $dateDelete = $dateDelete.AddDays(-$dayDiff)
    Write-Host “Deleting run history earlier than:” $dateDelete.toString(‘MM/dd/yyyy’)

    $lstSrv = @(get-wmiobject -class “MIIS_SERVER” -namespace “root\MicrosoftIdentityIntegrationServer” -computer “.”)
    Write-Host “Result: ” $lstSrv[0].ClearRuns($dateDelete.toString(‘yyyy-MM-dd’)).ReturnValue

    #——————————————————————————————————————–
    Trap
    {
    Write-Host “Error: $($_.Exception.Message)” -foregroundcolor yellow -backgroundcolor black
    Exit
    }
    #——————————————————————————————————————–

 

Get Fim / MIM MIIS_Runhistory last 9

$GetNamespace = Get-WmiObject -Class “MIIS_RunHistory” -Namespace root\MicrosoftIdentityIntegrationServer | Select-Object -First 9

$MaAgentError = @()
foreach($Namespace in $GetNamespace) {
    if($Namespace.RunStatus -eq "success"){
       $MaAgentOK = "Everything allright"
    }
    else {
       foreach($Namespace in $GetNamespace) {
        $MaAgentError += $Namespace.MaName+" "+$Namespace.RunProfile.ToString()+" "+$Namespace.RunStatus
       }
       $MaAgentError
       break
     }
}
if($MaAgentError.Count -eq 0) {
    $MaAgentOK
}

 

Get Fim / Mim MIIS_RunHistory

$UserForestMAName = "AD Source"
$ResourceForestMAName = "AD Destination"
$ResourceForestMADestination2Name = "AD Destination2"

$GetNamespace = Get-WmiObject -Class “MIIS_RunHistory” -Namespace root\MicrosoftIdentityIntegrationServer

# 00 Destination2 Delta Import 
$RunProfileName00 = $GetNamespace[0].RunProfile.ToString()
$RunStatusInfo00 = $GetNamespace[0].RunStatus
$ResourceForestMATradingName+” $RunProfileName00 “+$RunStatusInfo00

# 01 Destination2 Export 
$RunProfileName01 = $GetNamespace[1].RunProfile.ToString()
$RunStatusInfo01 = $GetNamespace[1].RunStatus
$ResourceForestMATradingName+” $RunProfileName01 “+$RunStatusInfo01

# 02 Destination2 Delta Sync 
$RunProfileName02 = $GetNamespace[2].RunProfile.ToString()
$RunStatusInfo02 = $GetNamespace[2].RunStatus
$ResourceForestMATradingName+” $RunProfileName02 “+$RunStatusInfo02

# 03 Destination Delta Import
$RunProfileName03 = $GetNamespace[3].RunProfile.ToString()
$RunStatusInfo03 = $GetNamespace[3].RunStatus
$ResourceForestMAName+” $RunProfileName03 “+$RunStatusInfo03

# 04 Destination Export
$RunProfileName04 = $GetNamespace[4].RunProfile.ToString()
$RunStatusInfo04 = $GetNamespace[4].RunStatus
$ResourceForestMAName+” $RunProfileName04 “+$RunStatusInfo04

# 05 Destination Delta Sync
$RunProfileName05 = $GetNamespace[5].RunProfile.ToString()
$RunStatusInfo05 = $GetNamespace[5].RunStatus
$ResourceForestMAName+” $RunProfileName05 “+$RunStatusInfo05

# 06 Source Delta Sync
$RunProfileName06 = $GetNamespace[6].RunProfile.ToString()
$RunStatusInfo06 = $GetNamespace[6].RunStatus
$UserForestMAName+” $RunProfileName06 “+$RunStatusInfo06

# 07 source Delta Import
$RunProfileName07 = $GetNamespace[7].RunProfile.ToString()
$RunStatusInfo07 = $GetNamespace[7].RunStatus
$ResourceForestMAName+” $RunProfileName07 “+$RunStatusInfo07

# 08 Source Delta Import
$RunProfileName08 = $GetNamespace[8].RunProfile.ToString()
$RunStatusInfo08 = $GetNamespace[8].RunStatus
$UserForestMAName+” $RunProfileName08 “+$RunStatusInfo08

# some variables and files
$jetzt = get-date -uformat "%Y-%m-%d %H:%M:%S"

# Script will send an email at the end. Needed Parameters
$myServer = "$env:computername.$env:userdnsdomain" # Name of the Maschine
$emailFrom = "$myServer <mail adres of the server>" # Servername und Verteilerliste
$emailBetreff = (get-date -uformat %Y-%m-%d)+" Some Run Fimprofiles no Succes."

$emailTo = "mail@domain.come" # testing

$emailServer = "your mail releay server here" # INFO: server that runs script must be allowed in FW, on mailrelay and in McAfee Virus Console outgoing connection to port 25 must be allowed!

# create email
$emailBody = "`r`n $ResourceForestMADestination2Name $RunProfileName00 $RunStatusInfo00`
                 `r`n $ResourceForestMADestination2Name $RunProfileName01 $RunStatusInfo00`
                 `r`n $ResourceForestMADestination2Name $RunProfileName02 $RunStatusInfo00`
                 `r`n $ResourceForestMAName $RunProfileName03 $RunStatusInfo00`
                 `r`n $ResourceForestMAName $RunProfileName04 $RunStatusInfo00`
                 `r`n $ResourceForestMAName $RunProfileName05 $RunStatusInfo00`
                 `r`n $UserForestMAName $RunProfileName06 $RunStatusInfo00`
                 `r`n $ResourceForestMAName $RunProfileName07 $RunStatusInfo00`
                 `r`n $UserForestMAName $RunProfileName08 $RunStatusInfo00`
                  `r`n"

 
If (`
$RunStatusInfo00 -ne "success"`
 -or $RunStatusInfo01 -ne "success"`
 -or $RunStatusInfo02 -ne "success"`
 -or $RunStatusInfo03 -ne "success"`
 -or $RunStatusInfo04 -ne "success"`
 -or $RunStatusInfo05 -ne "success"`
 -or $RunStatusInfo06 -ne "success"`
 -or $RunStatusInfo07 -ne "success"`
  -or $RunStatusInfo08 -ne "success"`
) {Send-MailMessage -From $emailFrom -To $emailTo -Subject $emailBetreff -SmtpServer $emailServer -Body $emailBody}

Enable / Disable Logon on Terminal Server

You recognize the Situation loged on to a Terminal server to install Programms and disabled users to logon to the Terminal server till you finished and logged of before enabling users o logon to the Terminalserver again. Then use the following command to enable it in the registry.
psexec \\machinename change logon /enable
This will write value 0 in HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\WinStationDisabled

Enable Remote Desktop on Remote PC with PSExec

PSExec is part of the Sysinternal Suite and can be downloaded from http://technet.microsoft.com/en-US/sysinternals

psexec \\machinename reg add “hklm\system\currentcontrolset\control\terminal server” /f /v fDenyTSConnections /t REG_DWORD /d 0
psexec \\machinename netsh firewall set service remoteadmin enable
psexec \\machinename netsh firewall set service remotedesktop enable
Use ipadress instead of machinename. Change 0 to 1, to deactivate RDP.

Get Expiring Certificate from Website

$minimumCertAgeDays = 60
$timeoutMilliseconds = 10000
$urls = @(
"https://meet.domain.local"
"https://anywebsite.domain.com"
)
#disabling the cert validation check. This is what makes this whole thing work with invalid certs…
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
foreach ($url in $urls)
{
$req = [Net.HttpWebRequest]::Create($url)
$req.Timeout = $timeoutMilliseconds
try {$req.GetResponse() |Out-Null} catch {}
function Convert-StringToDateTime
{
param
(
[Parameter(Mandatory = $true)]
[String] $DateTimeStr
)
# Change Date pattern to German
$DateFormatParts = (Get-Culture).DateTimeFormat.ShortDatePattern -split ‘/|-|\.’
$Month_Index = ($DateFormatParts | Select-String -Pattern ‘MM’).LineNumber – 1
$Day_Index = ($DateFormatParts | Select-String -Pattern ‘dd’).LineNumber – 1
$Year_Index = ($DateFormatParts | Select-String -Pattern ‘yyyy’).LineNumber – 1
$DateTimeParts = $DateTimeStr -split ‘/|-|\.| ‘
$DateTimeParts_LastIndex = $DateTimeParts.Count – 1
$DateTime = [DateTime] $($DateTimeParts[$Month_Index] + ‘/’ + $DateTimeParts[$Day_Index] + ‘/’ + $DateTimeParts[$Year_Index] + ‘ ‘ + $DateTimeParts[3..$DateTimeParts_LastIndex] -join ‘ ‘)
return $DateTime
}

$expiration = Convert-StringToDateTime $req.ServicePoint.Certificate.GetExpirationDateString()

[int]$certExpiresIn = ($expiration – $(get-date)).Days
$certName = $req.ServicePoint.Certificate.GetName()
$certPublicKeyString = $req.ServicePoint.Certificate.GetPublicKeyString()
$certSerialNumber = $req.ServicePoint.Certificate.GetSerialNumberString()
$certThumbprint = $req.ServicePoint.Certificate.GetCertHashString()
$certEffectiveDate = $req.ServicePoint.Certificate.GetEffectiveDateString()
$certIssuer = $req.ServicePoint.Certificate.GetIssuerName()
if ($certExpiresIn -gt $minimumCertAgeDays)
{Write-Host ========================================================================`r`nCert for site $url expires in $certExpiresIn days [on $expiration] `r`n========================================================================`r`n -ForegroundColor Green}
else
# Following lines for testing to get Output on screen
#{Write-Host Cert for site $url expires in $certExpiresIn days [on $expiration] Threshold is $minimumCertAgeDays days. Check details:`n`nCert name: $certName`nCert public key: $certPublicKeyString`nCert serial number: $certSerialNumber`nCert thumbprint: $certThumbprint`nCert effective date: $certEffectiveDate`nCert issuer: $certIssuer -f Yellow `r`n}
#{Write-Host ========================================================================`r`nCert for site $url expires in $certExpiresIn days [on $expiration] Threshold is $minimumCertAgeDays days. Check details:`n========================================================================`nCert name: $certName`nCert Expires on:$expiration`nCert serial number: $certSerialNumber`nCert thumbprint: $certThumbprint`nCert effective date: $certEffectiveDate`nCert issuer: $certIssuer `r`n========================================================================`r`n -ForegroundColor Yellow} 
{$OutputToWrite = "========================================================================`r`nCert for site $url expires in $certExpiresIn days [on $expiration] Threshold is $minimumCertAgeDays days. Check details:`r`n========================================================================`r`nCert name: $certName`r`nCert Expires on:$expiration`r`nCert serial number: $certSerialNumber`r`nCert thumbprint: $certThumbprint`r`nCert effective date: $certEffectiveDate`r`nCert issuer: $certIssuer `r`n========================================================================`r`n"}
$OutputToWrite | Out-File C:\temp\ssl.txt -Encoding utf8

#Remove Variabel
rv req
rv expiration
rv certExpiresIn
}