Skip to content

Instantly share code, notes, and snippets.

#Import CSV file, commas as separators, headers are Path, Username
$Csv = Import-Csv C:\temp\file.csv
#Separate headers
foreach ($Line in $Csv) {
#Separate Path header for old user home folder
$UserHome_old = $Line.Path
#Separate Username header for new home folder location
@jonimattila
jonimattila / ADFS-AD-Group-ConventionalMapping.ps1
Created January 25, 2018 12:47
ADFS federation with AWS using AD Groups
Import-Module ADFS
Add-ADFSRelyingPartyTrust -Name "Amazon Web Services & AD Groups" -MetadataURL "https://signin.aws.amazon.com/static/saml-metadata.xml" -MonitoringEnabled:$true -AutoUpdateEnabled:$true
$ruleSet = New-AdfsClaimRuleSet -ClaimRuleFile ((pwd).Path + "\claims-AD-Groups.txt")
$authSet = New-AdfsClaimRuleSet -ClaimRuleFile ((pwd).Path + "\auth.txt")
Set-AdfsRelyingPartyTrust -TargetName "Amazon Web Services & AD Groups" -IssuanceTransformRules $ruleSet.ClaimRulesString -IssuanceAuthorizationRules $authSet.ClaimRulesString
@jonimattila
jonimattila / Firefox_Deploy-Application.ps1
Created February 22, 2018 10:31
Firefox uninstall and install script to be used with psappdeploytoolkit
#Remove from user folder
$UserDir = "C:\Users"
$Folders = Get-ChildItem -Path $UserDir
ForEach ($Folder in $Folders)
{
if (Test-Path "$Userdir\$folder\AppData\Local\Mozilla Firefox\uninstall\helper.exe")
{
Execute-Process -Path "$Userdir\$folder\AppData\Local\Mozilla Firefox\uninstall\helper.exe" -Parameters '-ms' -ContinueOnError $True
}
}
@jonimattila
jonimattila / SCCM detection rule.ps1
Created May 23, 2018 11:57
Windows 10 Disk Cleanup SCCM detection rule
if( ( (test-path 'C:\windows.old','C:\$WINDOWS.~BT','C:\$Windows.~WS') -eq $true).Count -and (test-path 'C:\windows.old','C:\$WINDOWS.~BT','C:\$Windows.~WS' -OlderThan (Get-Date).AddHours(-10) ))
{
}
else
{
Write-Host "Installed"
}
@jonimattila
jonimattila / deploy-application.ps1
Last active May 25, 2018 05:40
Windows 10 automatic disk cleanup if windows temp folders older than 10 hours
if( ( (test-path 'C:\windows.old','C:\$WINDOWS.~BT','C:\$Windows.~WS') -eq $true).Count -and (test-path 'C:\windows.old','C:\$WINDOWS.~BT','C:\$Windows.~WS' -OlderThan (Get-Date).AddHours(-10) )){
& cscript /nologo "$dirfiles\AutomatedDiskCleanup.vbs"
}
If (Test-Path -LiteralPath 'C:\$WINDOWS.~BT') {
Remove-Item 'C:\$WINDOWS.~BT' -Recurse -Force
Write-Log -Message 'C:\$WINDOWS.~BT deleted' -Source $deployAppScriptFriendlyName
}
If (Test-Path -LiteralPath 'C:\$Windows.~WS') {
$User = gwmi win32_computersystem -Property Username
$UserName = $User.UserName
$UserSplit = $User.UserName.Split("\")
$OneDrive = "$env:SystemDrive\users\" + $UserSplit[1] +"\appdata\local\microsoft\onedrive\onedrive.exe"
# Parameter to Log
if ((test-path "$OneDrive") -and ((Get-Item $OneDrive).VersionInfo.FileVersion -gt '19'))
{
Write-Host "Installed"
}
Else
#CSV example name, username
# Import AD Module
import-module ActiveDirectory
# Import CSV
$MoveList = Import-Csv -Path "C:\temp\moveusers.csv"
# Specify target OU.This is where users will be moved.
$TargetOU = "OU=moveou,OU=users,DC=subdomain,DC=local"
# Import the data from CSV file and assign it to variable
Start-Process -FilePath "${env:Windir}\System32\SFC.EXE" -ArgumentList '/scannow' -Wait -Verb RunAs
Repair-WindowsImage -Online -scanhealth
Repair-WindowsImage -Online -checkhealth
if ($ComputerProperties = Repair-WindowsImage -Online -checkhealth | Select-Object ImageHealthState | Where-Object {($_.ImageHealthState -notlike "Healthy")}) {
Repair-WindowsImage -Online -RestoreHealth}
Start-Process -FilePath "${env:Windir}\System32\SFC.EXE" -ArgumentList '/scannow' -Wait -Verb RunAs