Skip to content

Instantly share code, notes, and snippets.

@kbostick88
Created February 28, 2020 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbostick88/c0d8c4c9f3a260b1ff5014d00fd0f2b0 to your computer and use it in GitHub Desktop.
Save kbostick88/c0d8c4c9f3a260b1ff5014d00fd0f2b0 to your computer and use it in GitHub Desktop.
$WW = "C:\Users\$CurrentUser\Desktop\Wolverine\Maize\WolverineWins.txt"
$SW = "C:\Users\$CurrentUser\Desktop\Wolverine\Sparty\Green\SpartyWins.txt" #Replace with whatever file you want to do this to.
$CurrentUser = $env:UserName #User account to grant permisions too.
$Rights = "Read, ReadAndExecute, ListDirectory" #Comma seperated list.
$InheritSettings = "Containerinherit, ObjectInherit" #Controls how permissions are inherited by children
$PropogationSettings = "None" #Usually set to none but can setup rules that only apply to children.
$RuleType = "Allow" #Allow or Deny.
function ChangePermWW
{
$acl = Get-Acl $WW
$perm = $CurrentUser, $Rights, $InheritSettings, $PropogationSettings, $RuleType
$rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $perm
$acl.SetAccessRule($rule)
$acl | Set-Acl -Path $WW
}
function ChangePermSW
{
$acl = Get-Acl $SW
$perm = $CurrentUser, $Rights, $InheritSettings, $PropogationSettings, $RuleType
$rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $perm
$acl.SetAccessRule($rule)
$acl | Set-Acl -Path $SW
}
clear
$CurrentUser = $env:UserName
New-Item -Path "C:\Users\$CurrentUser\Desktop\" -Name "Wolverine" -ItemType "directory" -Force
New-Item -Path "C:\Users\$CurrentUser\Desktop\Wolverine" -Name "Maize" -ItemType "directory" -Force
New-Item -Path "C:\Users\$CurrentUser\Desktop\" -Name "Sparty" -ItemType "directory" -Force
New-Item -Path "C:\Users\$CurrentUser\Desktop\Sparty" -Name "Green" -ItemType "directory" -Force
Import-Module "C:\Users\$CurrentUser\Desktop\ChangePerm.psm1"
foreach($line in Get-Content -Path "C:\Users\$CurrentUser\Desktop\SchoolbySchoolScores.txt") {
#Split the line of the file to scores of Michigan and MSU
$arr = $line.split(",")
$team = $arr[0].length - 2
$team2 = $arr[1].length - 5
#Extract the actual score values from the scores of Michigan and MSU
$Result = $arr[0].Substring(2,$team)
$Result2 = $arr[1].Substring(5,$team2)
#Values are in String, we need to convert them to integer for comparision purposes
$Score = [convert]::ToInt32($value,10)
$Score2 = [convert]::ToInt32($value2,10)
if($Score -gt $Score2){
#Write the output to the michigan win.txt file in the correct sub dir
Write-Output ('** Michigan wins over MSU ' + $($Score) + '-' + $($Score2) + ' **') | Out-File -Append -FilePath C:\Users\$CurrentUser\Desktop\Wolverine\Maize\MichiganWins.txt
}
else{
#Writing the output to the to the msu win file in the correct sub dir
Write-Output ('** MSU beats Michigan ' + $($Score) + '-' + $($Score2) + ' **') >> C:\Users\$CurrentUser\Desktop\Sparty\Green\SpartyWins.txt
}
#Re-initializing the output for using again in the loop
$arr = @()
$Result = 0
$Result2 = 0
$Score = 0
$Score2 = 0
}
$compressW = @{
LiteralPath= "C:\Users\$CurrentUser\Desktop\Wolverine"
CompressionLevel = "Fastest"
DestinationPath = "C:\Users\$CurrentUser\Desktop\Wolverine.zip"
}
Compress-Archive @compressW -Force
$compressS = @{
LiteralPath= "C:\Users\$CurrentUser\Desktop\Sparty"
CompressionLevel = "Fastest"
DestinationPath = "C:\Users\$CurrentUser\Desktop\Sparty.zip"
}
Compress-Archive @compressS -Force
MSU, vs Michigan, 30, :28
Michigan, vs MSU, 28, :14
MSU, vs Michigan, 42, :21
MSU, vs Michigan, 42, :28
Michigan, vs Broncos, 55, :10
MSU, vs Michigan, 49, :30
Michigan, vs MSU, 32, :16
MSU, vs Michigan, 7, :2
FightingIrish, vs Michigan, 24, :17
MSU, vs Michigan, 35, :33
Michigan, vs MSU, 32, :28
Michigan, vs MSU, 32, :30
MSU, vs Michigan, 9, :7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment