Skip to content

Instantly share code, notes, and snippets.

Avatar

Gisli Gudmundsson gislig

View GitHub Profile
@gislig
gislig / PowershellSimpleClass.ps1
Created May 10, 2018
Simple way to add class to Powershell
View PowershellSimpleClass.ps1
Class Fruit {
#Set the variable
[string]$FruitName
#Create the constructor
Fruit ($FruitName) {
$this.FruitName = $FruitName
}
}
@gislig
gislig / SimpleExample1.ps1
Created May 10, 2018
Simple Powershell Example 1
View SimpleExample1.ps1
$Cars = "Tyota","Hyundai","Ford"
#Foreach within the Array
$Cars | ForEach-Object { $_ }
#Foreach within the Array simpler
$Cars | ForEach { $_ }
#Foreach within the Array much simpler
$Cars | % { $_ }
@gislig
gislig / SimpleExample2.ps1
Created May 10, 2018
Simple Powershell Example 2
View SimpleExample2.ps1
$Cars = "Tyota","Hyundai","Ford"
#Where in Array
$Cars | Where-Object { $_ -eq "Hyundai" }
#Where in Array simpler
$Cars | Where { $_ -eq "Hyundai" }
#Where in Array much simpler
$Cars | ? { $_ -eq "Hyundai" }
@gislig
gislig / UserPing.ps1
Created May 10, 2018
Ping User on the Network
View UserPing.ps1
#Script created by Gísli Guðmundsson
#Created for Aron Gauti Birgisson
#Create Objects to set info about the computers who user logged on to
function setPingUser($ComputerName, $IPAddress, $User){
New-Object psobject -Property @{
ComputerName=$ComputerName;
IPAddress=$IPAddress;
User=$User;
@gislig
gislig / PowershellWannaCryDetector.ps1
Created May 10, 2018
Run as service and detect if you have specific files on a users computer, was specifically created for wannacry virus
View PowershellWannaCryDetector.ps1
#CREATED BY GISLI GUDMUNDSSON
#GLOBAL VARIABLES
$MailTo = "admin@yourcompany.com"
$SmptServer = "yourmxserver.domain.com"
function SendInfectionMessage(){
Send-MailMessage -To $MailTo -From "$env:COMPUTERNAME" -Subject "WannaCry Infection Detected - $env:COMPUTERNAME" -Body "WannaCry Infection Was Likely Detected on Computer $env:COMPUTERNAME. Please contact Username $env:USERNAME to investigate further. The Network Was Disabled On Remote Machine" -SmtpServer $SmtpServer
View CreateUsersFromCSV.ps1
#Import the values for the users
$UserValues = Import-Csv -Path c:\UserCreation\Users.csv -Delimiter ";"#Create the user function so I will not repeat myselffunctioncreateUsers($FirstName, $LastName, $Password, $Department){
#The path for the user to be placed, in this scenario I put them in a department OU and Users
$OUPath = "OU=Users,OU=$Department,OU=Departments,DC=TSTDOMAIN,DC=COM"
#Convert the password to securestring
$AccountPassword = (ConvertTo-SecureString -AsPlainText $Password -Force)
#Create the Displayname, samaccountname, userprincipal name
$DisplayName = $FirstName+" "+$LastName
View PSLottery.ps1
#------------------
# Lottery game by Gisli Gudmundsson
# Created 13.11.2016
$ApplicationName = "PowerBalls"
$MaximumBallNumber = 20
$TotalGamePlays = 1000000
$RowWinningPercentage = 16.6667
$WinningRow = 0
$YourNumbers = "10","3","9","7","8","5"
View PowershellSnippedCS.ps1
#The C# Code starts with @ sign and ends with @ sign.
$CSharpCode = @"
public class ExampleCSharp
{
public string ReturnTheString(string returnString)
{
string Combine = "Your awesome text is : " + returnString;
return Combine;
}
View DEPMSSQLActions.psm1
#----------------------------------------------------------------------#
#
# Module Name : DEPMSSQLActions.psm1
# Created : 27.10.2016
# Created by : Gisli Gudmundsson
# LinkedIN : https://is.linkedin.com/in/gisli-gudmundsson-11a77639
# License Usage :
# This code can be used for private use only
# You may modify this code and distribute
#
View DEPMSSQLActions.psm1
#----------------------------------------------------------------------##
# Module Name : DEPMSSQLActions.psm1
# Created : 27.10.2016
# Created by : Gisli Gudmundsson
# LinkedIN : https://is.linkedin.com/in/gisli-gudmundsson-11a77639# License Usage :
# This code can be used for private use only# You may modify this code and distribute
##----------------------------------------------------------------------#
#Import the SQL Server Powershell Module
Import-Module SqlServer
You can’t perform that action at this time.