Check-GroupMembership

I recently needed a quick way to get group membership of a user or group and didnt want to install the active directory module on a computer so i wrote a simple function for this.

Function Check-GroupMembership{
param(
[parameter(Mandatory=$true)]
[ValidateSet("User", "Computer")]
[string]$GroupType,


[String]$GroupName

)


switch ($grouptype)
{
 'User' {
 
 If ($PSBoundParameters.ContainsKey('GroupName'))
 {
 [Security.Principal.WindowsIdentity]::GetCurrent().Groups | % { if ($_.Translate([Security.Principal.NTAccount]) -imatch $GroupName){$true;break}}
 }
 Else 
 {
 [Security.Principal.WindowsIdentity]::GetCurrent().Groups | %{$_.Translate([Security.Principal.NTAccount])}|sort
 }
 }
 'Computer' {
 If ($PSBoundParameters.ContainsKey('GroupName'))
 {
 ([adsisearcher]"(&(objectCategory=computer)(cn=$env:COMPUTERNAME))").FindOne().Properties.memberof -replace '^CN=([^,]+).+$','$1' | %{if($_ -imatch $GroupName){$true;break}}
 }
 Else
 { 
 ([adsisearcher]"(&(objectCategory=computer)(cn=$env:COMPUTERNAME))").FindOne().Properties.memberof -replace '^CN=([^,]+).+$','$1'|sort}
 } 
}

}

Top40 from C89.5 changes emailed to you with PowerShell

I live in the Seattle, WA and love listening to 89.5 which plays great dance music. They have a list of Top40 songs which i liked to look through once a week and listen to on spottily. The problem I was havining was not knowing which songs are new since they are rated 1 to 40. So I the only way I could think of, which was to simply parse out the html and email me once a week.

To get this working for yourself:
Copy all code below as and save it into a .ps1 file.
Update the code for your email address and password.
Create a scheduled task that runs the script once a week and you will receive an email when ever they update the page.

I found that they update the site usually on Sundays so i have mine running at 7:30 PM.

c89

Enjoy!



<#

This is a script that will notify me when there is new song in the top 40 list.

http://www.c895.org/music/ 
#>

FUNCTION Get-ScriptPath { Split-Path $myInvocation.ScriptName}
$scriptpath = Get-ScriptPath

$top40url = 'http://www.c895.org/music/'

$results = Invoke-WebRequest -URI $top40url
$tables = $results.AllElements | Where-Object -Property class -Match "tablesorter"
$top40 = ( $tables[0].innertext -split '[\r\n]') |? {$_} 

$myfile = join-path $scriptpath "mylist.txt"
$newfile = join-path $scriptpath "newlist.txt"
New-Item -ItemType file -path $newfile -Force | Out-Null
if (!(Test-Path $myfile)){new-item -ItemType file -Path $myfile | Out-Null}

$mylist = Get-Content $myfile


Foreach ($unit in $top40)
{
$firstchar = $unit.Substring(0,1)
$secondchar = $unit.Substring(0,2)
if ([bool]($firstchar -as [int]))
{
 if ([bool]($secondchar -as [int]))
 {
 $unit.Substring(2).trim() | Out-File $newfile -Append
 
 }
 else
 {
 $unit.Substring(1).trim() | Out-File $newfile -Append
 }
}
else
 {
 Write-host "$unit is not a song" -ForegroundColor Yellow
 }
}


$newlist = Get-Content $newfile


$newsongfinds = @()

if ($mylist -ne $Null){
$difference = Compare-Object -ReferenceObject $mylist -DifferenceObject $newlist | ? {$_.SideIndicator -eq '=>'}

 foreach ($diff in $difference)
 {
 $d = $diff.InputObject -as [string]
 $d | Out-File $myfile -Append
 $newsongfinds += $d
 Write-Host "Found new song: $d" -ForegroundColor Green
 }
}
else
{
$newlist | Out-File $myfile
}

if ( $newsongfinds.count -ge 1)
{
$n = $null
$newsongfinds | % {$n += "$_`n"}

$body = @"
New song(s) added to C89.5 Top 40 list http://www.c895.org/music/

$n
"@

$Username = "[email protected]"
$Password = ConvertTo-SecureString ‘P@ssword!’ -AsPlainText -Force

$Livecred = New-Object System.Management.Automation.PSCredential $Username, $Password
 
Send-MailMessage -smtpServer 'smtp.gmail.com' `
 -credential $Livecred `
 -from '[email protected]' `
 -to '[email protected]'`
 -subject 'New song(s) added to C89.5 Top 40 list!' `
 -body "$body " `
 -UseSsl `
 -port 587 `
 -Bcc '[email protected]'
}