Skip to content

Instantly share code, notes, and snippets.

View IT-Delinquent's full-sized avatar
🏠
Working from home

Mark Harwood IT-Delinquent

🏠
Working from home
View GitHub Profile
@IT-Delinquent
IT-Delinquent / powerShellAliasImportScript.ps1
Created June 15, 2022 13:36
powerShellAliasImportScript.ps1
Import-Csv "path\to\csv" | ForEach-Object {
try{
Set-ADUser -Identity $_.samaccountname -add @{Proxyaddresses=$_.Proxyaddresses -split ";"} -ErrorAction Stop
Write-Host $_.samaccountname complete! -ForegroundColor Green
}catch{
Write-Host 'Failed : ' -NoNewline
Write-Host $_.samaccountname -ForegroundColor Red
}
}
@IT-Delinquent
IT-Delinquent / tputFormattingExamples.sh
Created August 6, 2021 09:58
tputFormattingExamples.sh
#!/bin/bash
echo "
regular bold underline
$(tput setaf 1)Text $(tput bold)Text $(tput sgr0)$(tput setaf 1)$(tput smul)Text$(tput rmul)
$(tput setaf 2)Text $(tput bold)Text $(tput sgr0)$(tput setaf 2)$(tput smul)Text$(tput rmul)
$(tput setaf 3)Text $(tput bold)Text $(tput sgr0)$(tput setaf 3)$(tput smul)Text$(tput rmul)
$(tput setaf 4)Text $(tput bold)Text $(tput sgr0)$(tput setaf 4)$(tput smul)Text$(tput rmul)
$(tput setaf 5)Text $(tput bold)Text $(tput sgr0)$(tput setaf 5)$(tput smul)Text$(tput rmul)
$(tput setaf 6)Text $(tput bold)Text $(tput sgr0)$(tput setaf 6)$(tput smul)Text$(tput rmul)
@IT-Delinquent
IT-Delinquent / cSharpAsyncWatcherClass.cs
Created July 27, 2021 11:30
cSharpAsyncWatcherClass
//Used to define what is returned in the async results
public static CimAsyncMultipleResults<CimInstance> GetValues(CimSession _session) {
return _session.QueryInstancesAsync(@"root\cimv2", "WQL", "SELECT Username FROM Win32_ComputerSystem");
}
//This watches the async progress
class CimInstanceWatcher : IObserver<CimInstance> {
public void OnCompleted() {
Console.WriteLine("Done");
}
<Image Name="loadingImage" Margin="200" RenderTransformOrigin="0.5,0.5" Source="/SlickRHI;component/Assets/Images/Loading.png">
<Image.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<EventTrigger.Actions> <BeginStoryboard Storyboard="{StaticResource imageRotationStoryboard}" />
</EventTrigger.Actions>
</EventTrigger>
</Image.Triggers>
<Image.RenderTransform>
<RotateTransform Angle="0"/>
</Image.RenderTransform>
@IT-Delinquent
IT-Delinquent / repeatBackgroundMusic.cs
Created July 27, 2021 11:00
repeatBackgroundMusic
//Create a new MediaPlayer object
private static readonly MediaPlayer _backgroundMusic = new MediaPlayer();
public static void StartBackgroundMusic(){
//Open the temp WAV file saved in the temp location and called "backgroundmusic.wav"
_backgroundMusic.Open(new Uri(Path.Combine(Path.GetTempPath(), "backgroundmusic.wav")));
//Add an event handler for when the media has ended, this way
//the music can be played on a loop
_backgroundMusic.MediaEnded += new EventHandler(BackgroundMusic_Ended);
//Start the music playing
_backgroundMusic.Play();
@IT-Delinquent
IT-Delinquent / saveMusicToDiskWPF.cs
Created July 27, 2021 10:58
saveMusicToDiskWPF
public static void SaveMusicToDisk(){
//This sets up a new temporary file in the %temp% location called "backgroundmusic.wav"
using (FileStream fileStream = File.Create(Path.GetTempPath() + "backgroundmusic.wav")){
//This them looks into the assembly and finds the embedded resource
//inside the WPF project, under the assets folder
//under the sounds folder called backgroundmusic.wav
//PLEASE NOTE: this will be different to you
Assembly.GetExecutingAssembly().GetManifestResourceStream("WPF.Assets.Sounds.backgroundmusic.wav").CopyTo(fileStream);
}
@IT-Delinquent
IT-Delinquent / musicArtistsWithAlbumsList.ps1
Created June 24, 2021 09:50
musicArtistsWithAlbumsList
#A class for holding info on music artists
class MusicArtist{
[String]$Name
[Int]$Age
[Album[]]$Albums
}
#A class for holding info on music albums
class Album{
[String]$Name
@IT-Delinquent
IT-Delinquent / albumModelInPowerShell.ps1
Last active June 24, 2021 09:30
albumModelInPowerShell
class Album{
[String]$Name
[DateTime]$DateReleased
}
@IT-Delinquent
IT-Delinquent / musicArtistModelInPowerShell.ps1
Created June 24, 2021 09:18
musicArtistModelInPowerShell
class MusicArtist{
[String]$Name
[Int]$Age
[Album[]]$Albums
}
@IT-Delinquent
IT-Delinquent / personModelListInPowerShell.ps1
Created June 24, 2021 09:11
personModelListInPowerShell
#Creating a list to hold the people using the Person class
$People = New-Object 'System.Collections.Generic.List[PSObject]'
#Creating a new Person
$newPerson = [PersonClass]::new()
$newPerson.Name = "Roy Orbison"
$newPerson.Age = "24"
#Adding the new Person to the People list $People.Add($newPerson)
$People.Add($newPerson)