Similar documents
Qlik Sense Cmdlet for PowerShell. Sokkorn CHEAV

Govindaraj Rangan Technology Strategist Microsoft India

CIS 3260 Sample Final Exam Part II

Classes in C# namespace classtest { public class myclass { public myclass() { } } }

Shell programming. Introduction to Operating Systems

Bourne Shell Reference

Convertor Binar -> Zecimal Rosu Alin, Calculatoare, An2 Mod de Functionare: Am creat un program, in Windows Form Application, care converteste un

Tutorial 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and Arithmetic

Control Structures. CIS 118 Intro to LINUX

Finding RDP sessions on servers using PowerShell

Conditional Control Structures. Dr.T.Logeswari

c122mar413.notebook March 06, 2013

and event handlers Murach's C# 2012, C6 2013, Mike Murach & Associates, Inc. Slide 1

Sub To Srt Converter. This is the source code of this program. It is made in C# with.net 2.0.

Computer Systems and Architecture

Lucrare pentru colocviu de practică

Powershell: Introduction and Practical Uses. Presentation URL:

BASH Programming Introduction

PowerShell provider for BizTalk Server 2013

Title:[ Variables Comparison Operators If Else Statements ]

Tutorial 5 Completing the Inventory Application Introducing Programming

ListBox. Class ListBoxTest. Allows users to add and remove items from ListBox Uses event handlers to add to, remove from, and clear list

Virtual DMIS Requirements

Security Considerations

Visual Studio.NET enables quick, drag-and-drop construction of form-based applications

Boulos Dib September 21, 2011

Lab 4: Shell scripting

CSC 360 Lab Assignment #6 Spring 2015 Due: March 13, 2015

Operatii pop si push-stiva

Bash scripting basics

Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects

User-Defined Controls

DRA PowerShell Usage and Examples

Computer Systems and Architecture

Linux Bash Shell Scripting

Active Directory Attacks and Detection Part -II

CS 314 Principles of Programming Languages

Inheriting Windows Forms with Visual C#.NET

Shell script. Shell Scripts. A shell script contains a sequence of commands in a text file. Shell is an command language interpreter.

The power of PowerShell

this.openfiledialog = new System.Windows.Forms.OpenFileDialog(); this.label4 = new System.Windows.Forms.Label(); this.

Shell Start-up and Configuration Files

Blank Form. Industrial Programming. Discussion. First Form Code. Lecture 8: C# GUI Development

OPERATING SYSTEMS LAB LAB # 6. I/O Redirection and Shell Programming. Shell Programming( I/O Redirection and if-else Statement)

bash Execution Control COMP2101 Winter 2019

COMP 4/6262: Programming UNIX

DAVE LIDDAMENT INTRODUCTION TO BASH

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

CS211 Programming Practicum Fall 2017

namespace Tst_Form { private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container ^components;

York University AS/AK/ITEC INTRODUCTION TO DATA STRUCTURES. Midterm Sample I. Examiner: S. Chen Duration: One Hour and 30 Minutes

Essentials for Scientific Computing: Bash Shell Scripting Day 3

Shell Programming (Part 2)

(Refer Slide Time: 01:12)

Indian Institute of Technology Kharagpur. PERL Part II. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T.

A layman s guide to PowerShell 2.0 remoting. Ravikanth Chaganti

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

CS Unix Tools & Scripting

Linux shell programming for Raspberry Pi Users - 2

Flag Quiz Application

Building Powerful Workflow Automation with Cherwell and PowerShell

Introduction to Linux Basics Part II. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala

Lampiran B. Program pengendali

CSCI 211 UNIX Lab. Shell Programming. Dr. Jiang Li. Jiang Li, Ph.D. Department of Computer Science

CSE 374 Midterm Exam 11/2/15. Name Id #

Pupil Name. Year. Teacher. Target Level. Key Stage 3 Self-Assessment Year 9 Python. Spelling Test No 3. Spelling Test No 2. Spelling Test No 1

Shell Script Example. Here is a hello world shell script: $ ls -l -rwxr-xr-x 1 horner 48 Feb 19 11:50 hello* $ cat hello #!/bin/sh

Bash shell programming Part II Control statements

;;; Determines if e is a primitive by looking it up in the primitive environment. ;;; Define indentation and output routines for the output for

Python Boot Camp. Day 3

Polymorphism. Polymorphism. CSC 330 Object Oriented Programming. What is Polymorphism? Why polymorphism? Class-Object to Base-Class.

Python Programming Exercises 1

How to Design Programs

1. Windows Forms 2. Event-Handling Model 3. Basic Event Handling 4. Control Properties and Layout 5. Labels, TextBoxes and Buttons 6.

Smart Flows. Productivity Suite. Smart Flows

CSc 520. Principles of Programming Languages 7: Scheme List Processing

Shell Programming (bash)

Python lab session 1

BASIC ELEMENTS OF A COMPUTER PROGRAM

UNIX shell scripting

A Brief Introduction to Scheme (II)

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

LOG ON TO LINUX AND LOG OFF

CSc 520 Principles of Programming Languages. Examining Lists. Constructing Lists... 7: Scheme List Processing

CS 1101 Exam 3 A-Term 2013

11 and 12 Arithmetic Sequence notes.notebook September 14, 2017

Introduction to XQuery. Overview. Basic Principles. .. Fall 2007 CSC 560: Management of XML Data Alexander Dekhtyar..

Command Interpreters. command-line (e.g. Unix shell) On Unix/Linux, bash has become defacto standard shell.

Product: DQ Order Manager Release Notes

Web Services in.net (2)

The PROFESSIONAL LANDLORD

Powershell. Working With Data COMP2101 Fall 2017

A Big Step. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

Linux Shell Scripting. Linux System Administration COMP2018 Summer 2017

PowerShell. Scripting in Windows Environments Gergő Ládi

CSE 374 Midterm Exam 11/2/15 Sample Solution. Question 1. (10 points) Suppose the following files and subdirectories exist in a directory:

Scripting. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

Fundamentals of Leveraging PowerShell

On Premise Multi-Server Support Guide

This is the start of the server code

Transcription:

<# Variables.PS1 Demonstrates the use of Variables sansell@rm.com #> $Date = Get-Date -uformat %A $Name = Read-Host Please enter your name

Write-Host Hello $Name, today is $Date <# Variables.PS1 Demonstrates the use of Variables sansell@rm.com

#> $Global:Date = Get-Date -uformat %A $Global:Name = Read-Host Please enter your name Write-Host Hello $Name, today is $Date <# This is the first line comment This is the second line comment #>

<# IllegalFiles.PS1 This script will search a path for file types sansell@rm.com #> Where Gets objects where the property matches { Encloses the filter $_.CommandType The property to be filtered by. Always prefaced by $_. -eq Equals. This could be like (Like) or ne (Does not equal). Other comparison operators are available Cmdlet One of the available property types, the other was Application

[System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") #Create Form $form = New-Object System.Windows.Forms.Form $form.text = "A.NET Form" $form.size = New-Object System.Drawing.Size(400,130)

#== Instruction Label $InstructionlabelBox = new-object System.Windows.Forms.Label $InstructionlabelBox.Font = new-object System.Drawing.Font("New Times Roman",9,[System.Drawing.FontStyle]::Bold) $InstructionlabelBox.location = new-object System.Drawing.Size(10,10) $InstructionlabelBox.size = new-object System.Drawing.Size(375,20) $InstructionlabelBox.text = "Click the Engage button" $form.controls.add($instructionlabelbox) #== Run Button $RunButton = new-object System.Windows.Forms.Button $RunButton.Location = new-object System.Drawing.Size(10,43) $RunButton.Size = new-object System.Drawing.Size(375,25) $RunButton.Text = "Engage!" $RunButton.Add_Click($Execute) $form.controls.add($runbutton)

#== Close Button $cabutton = new-object System.Windows.Forms.Button $cabutton.location = new-object System.Drawing.Size(300,75) $cabutton.size = new-object System.Drawing.Size(85,25) $cabutton.text = "Close" $cabutton.add_click({$form.close()}) $form.controls.add($cabutton) $Execute =

{ $Message = "This works" $Title = "Error" [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [void] [System.Windows.Forms.MessageBox]::Show("$Message","$title") } $Execute = { $Date = Get-Date $Message = "$Date" $Title = "The date and time is:" [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [void] [System.Windows.Forms.MessageBox]::Show("$Message","$title") } <# Form - 1- Message Box.PS1 This script will search a path for file types sansell@rm.com v0.1

#> $Execute = { $Message = "This works" $Title = "A.NET Message Box" [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [void] [System.Windows.Forms.MessageBox]::Show("$Message","$title") } [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") #Create Form $form = New-Object System.Windows.Forms.Form $form.text = "A.NET Form" $form.size = New-Object System.Drawing.Size(400,130) #== Instruction Label $InstructionlabelBox = new-object System.Windows.Forms.Label $InstructionlabelBox.Font = new-object System.Drawing.Font("New Times Roman",9,[System.Drawing.FontStyle]::Bold) $InstructionlabelBox.Location = new-object System.Drawing.Size(10,10) $InstructionlabelBox.size = new-object System.Drawing.Size(375,20) $InstructionlabelBox.Text = "Click the Engage button" $form.controls.add($instructionlabelbox) #== Run Button $RunButton = new-object System.Windows.Forms.Button $RunButton.Location = new-object System.Drawing.Size(10,43) $RunButton.Size = new-object System.Drawing.Size(375,25) $RunButton.Text = "Engage!" $RunButton.Add_Click($Execute) $form.controls.add($runbutton) #== Close Button $cabutton = new-object System.Windows.Forms.Button $cabutton.location = new-object System.Drawing.Size(300,75) $cabutton.size = new-object System.Drawing.Size(85,25) $cabutton.text = "Close" $cabutton.add_click({$form.close()}) $form.controls.add($cabutton)

#== Credit Label $CreditLabelBox = new-object System.Windows.Forms.Label $CreditLabelBox.Location = new-object System.Drawing.Size(10,78) $CreditLabelBox.size = new-object System.Drawing.Size(260,20) $CreditLabelBox.Text = "Just messing around with forms - sansell@rm.com" $form.controls.add($creditlabelbox) $form.topmost = $true $form.add_shown({$form.activate()}) $form.showdialog()

<# IllegalFiles.PS1 This script will search a path for file types sansell@rm.com v0.1 #> Get-ChildItem C:\Data Recurse Include *.AVI <# IllegalFiles.PS1 This script will search a path for file types sansell@rm.com v0.1 - Hard coded v0.2 - Path and file type variables added #>

$Path = Read-Host "Enter the path you wish to search" $FileType = Read-Host "Enter the file type you want to search for. Example *.txt" Get-ChildItem $Path Recurse Include "$FileType" <# IllegalFiles.PS1 This script will search a path for file types sansell@rm.com v0.1 - Hard coded v0.2 - Path and file type variables added v0.3 - Output sent to log file

#> $Path = Read-Host "Enter the path you wish to search" $FileType = Read-Host "Enter the file type you want to search for. (Example *.txt)" $LogName = Get-Date -uformat %d%m%y_%h%m%s $LogPath = Read-Host "Enter the log path" Get-ChildItem $Path Recurse Include "$FileType" Out-File $LogPath\$logName.log <# IllegalFiles.PS1 This script will search a path for file types sansell@rm.com v0.1 - Hard coded v0.2 - Path and file type variables added v0.3 - Output sent to log file #> $Path = Read-Host "Enter the path you wish to search"

$FileType = Read-Host "Enter the file type you want to search for. (Example *.txt)" $LogName = Get-Date -uformat %d%m%y_%h%m%s $LogPath = Read-Host "Enter the log path" $ServerName = Hostname $Date = Get-date $Date Out-File $LogPath\$LogName.log $ServerName Out-File $LogPath\$LogName.log -Append Get-ChildItem $Path Recurse Include "$FileType" Out-File $LogPath\$LogName.log - Append

# Command to run when the execute button is clicked $Execute =

{ $Path = $txtpath.text $FileType = $txtfiletype.text $LogName = Get-Date -uformat %d%m%y_%h%m%s $LogPath = $txtlogpath.text $ServerName = Hostname $Date = Get-date $Date Out-File $LogPath\$LogName.log $ServerName Out-File $LogPath\$LogName.log -Append Get-ChildItem $Path Recurse Include "$FileType" Select Directory,Name,Length Out- File $LogPath\$LogName.log -Append } [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") #Create Form $form = New-Object System.Windows.Forms.Form $form.text = "IllegalFiles" $form.size = New-Object System.Drawing.Size(400,350)

#== Instruction Label $InstructionlabelBox = new-object System.Windows.Forms.Label $InstructionlabelBox.Font = new-object System.Drawing.Font("New Times Roman",9,[System.Drawing.FontStyle]::Bold) $InstructionlabelBox.Location = new-object System.Drawing.Size(10,10) $InstructionlabelBox.size = new-object System.Drawing.Size(375,40) $InstructionlabelBox.Text = "Enter the Source Path, File Type to search for and the Log Path then click Engage" $form.controls.add($instructionlabelbox) #== Search Path $txtpath = new-object System.Windows.Forms.TextBox $txtpath.location = new-object System.Drawing.Size(110,50) $txtpath.size = new-object System.Drawing.Size(200,30) $form.controls.add($txtpath) $lblpath = new-object System.Windows.Forms.Label $lblpath.location = new-object System.Drawing.Size(10,53) $lblpath.size = new-object System.Drawing.Size(100,20) $lblpath.text = "Search Path:" $form.controls.add($lblpath) #== Run Button $RunButton = new-object System.Windows.Forms.Button $RunButton.Location = new-object System.Drawing.Size(10,143) $RunButton.Size = new-object System.Drawing.Size(375,25) $RunButton.Text = "Engage!" $RunButton.Add_Click($Execute) $form.controls.add($runbutton)

$cabutton = new-object System.Windows.Forms.Button $cabutton.location = new-object System.Drawing.Size(300,175) $cabutton.size = new-object System.Drawing.Size(85,25) $cabutton.text = "Close" $cabutton.add_click({$form.close()}) $form.controls.add($cabutton)

$PathExists = Test-Path $Path If ($PathExists -eq $False) {$Message = "Search path does not exist, please check path!" $Title = "Error" [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [void] [System.Windows.Forms.MessageBox]::Show("$Message","$title") } else{ $LogPathExists = Test-Path $LogPath If ($LogPathExists -eq $False)

{$Message = "Log path does not exist, please check path!" $Title = "Error" [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [void] [System.Windows.Forms.MessageBox]::Show("$Message","$title") } } <# IllegalFiles.PS1 This script will search a path for file types sansell@rm.com v0.1 - Hard coded v0.2 - Path and file type variables added v0.3 - Output sent to log file v0.4 - Selections added v1.0 -.NET form added. v1.1 - Basic error reporting added #> # Command to run when the execute button is clicked $Execute = { #Variables $Path = $txtpath.text $FileType = $txtfiletype.text $LogName = Get-Date -uformat %d%m%y_%h%m%s $LogPath = $txtlogpath.text $ServerName = Hostname $Date = Get-date $Date Out-File $LogPath\$LogName.log $ServerName Out-File $LogPath\$LogName.log -Append #Basic error reporting $PathExists = Test-Path $Path If ($PathExists -eq $False) {$Message = "Search path does not exist, please check path!" $Title = "Error" [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

[void] [System.Windows.Forms.MessageBox]::Show("$Message","$title") } else{ $LogPathExists = Test-Path $LogPath If ($LogPathExists -eq $False) {$Message = "Log path does not exist, please check path!" $Title = "Error" [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") [void] [System.Windows.Forms.MessageBox]::Show("$Message","$title") } } #Command Get-ChildItem $Path Recurse Include "$FileType" Select Directory,Name,Length Out- File $LogPath\$LogName.log -Append } [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") #Create Form $form = New-Object System.Windows.Forms.Form $form.text = "IllegalFiles" $form.size = New-Object System.Drawing.Size(400,230) #== Instruction Label $InstructionlabelBox = new-object System.Windows.Forms.Label $InstructionlabelBox.Font = new-object System.Drawing.Font("New Times Roman",9,[System.Drawing.FontStyle]::Bold) $InstructionlabelBox.Location = new-object System.Drawing.Size(10,10) $InstructionlabelBox.size = new-object System.Drawing.Size(375,40) $InstructionlabelBox.Text = "Enter the Source Path, File Type to search for and the Log Path then click Engage" $form.controls.add($instructionlabelbox) #== Search Path $txtpath = new-object System.Windows.Forms.TextBox $txtpath.location = new-object System.Drawing.Size(110,50) $txtpath.size = new-object System.Drawing.Size(200,30) $form.controls.add($txtpath) $lblpath = new-object System.Windows.Forms.Label $lblpath.location = new-object System.Drawing.Size(10,53) $lblpath.size = new-object System.Drawing.Size(100,20) $lblpath.text = "Search Path:" $form.controls.add($lblpath)

#== Log Path $txtlogpath = new-object System.Windows.Forms.TextBox $txtlogpath.location = new-object System.Drawing.Size(110,80) $txtlogpath.size = new-object System.Drawing.Size(200,30) $form.controls.add($txtlogpath) $lbllogpath = new-object System.Windows.Forms.Label $lbllogpath.location = new-object System.Drawing.Size(10,83) $lbllogpath.size = new-object System.Drawing.Size(100,20) $lbllogpath.text = "Log Path:" $form.controls.add($lbllogpath) #== File Type $txtfiletype = new-object System.Windows.Forms.TextBox $txtfiletype.location = new-object System.Drawing.Size(110,110) $txtfiletype.size = new-object System.Drawing.Size(80,30) $form.controls.add($txtfiletype) $lblfiletype = new-object System.Windows.Forms.Label $lblfiletype.location = new-object System.Drawing.Size(10,113) $lblfiletype.size = new-object System.Drawing.Size(100,20) $lblfiletype.text = "File Type:" $form.controls.add($lblfiletype) $lblfiletype1 = new-object System.Windows.Forms.Label $lblfiletype1.location = new-object System.Drawing.Size(210,113) $lblfiletype1.size = new-object System.Drawing.Size(150,20) $lblfiletype1.text = "Example: *.txt OR *.exe" $form.controls.add($lblfiletype1) #== Run Button $RunButton = new-object System.Windows.Forms.Button $RunButton.Location = new-object System.Drawing.Size(10,143) $RunButton.Size = new-object System.Drawing.Size(375,25) $RunButton.Text = "Engage!" $RunButton.Add_Click($Execute) $form.controls.add($runbutton) #== Close Button $cabutton = new-object System.Windows.Forms.Button $cabutton.location = new-object System.Drawing.Size(300,175) $cabutton.size = new-object System.Drawing.Size(85,25) $cabutton.text = "Close" $cabutton.add_click({$form.close()}) $form.controls.add($cabutton)

#== Credit Label $CreditLabelBox = new-object System.Windows.Forms.Label $CreditLabelBox.Location = new-object System.Drawing.Size(10,178) $CreditLabelBox.size = new-object System.Drawing.Size(260,20) $CreditLabelBox.Text = "IllegalFiles.PS1 v1.1 by sansell@rm.com" $form.controls.add($creditlabelbox) $form.topmost = $true $form.add_shown({$form.activate()}) $form.showdialog()

<# OldComputers.PS1 This script will search for computers that have not logged on for x days sansell@rm.com v1.0 #> #Import the Active Directory Module Import-Module ActiveDirectory #Get the current system time $Date = Get-Date #Get the number of days to subtract from the current system time $Days = Read-Host "Enter the number of days since last logon" #Create the $Time variable $Time = $Date.AddDays(-$Days) #Find all computer with a logon time older than $Time and display in a grid Get-ADComputer -Filter * Get-ADObject -Properties LastLogonTimeStamp where{(([datetime]::fromfiletime($_.lastlogontimestamp) - ([system.datetime]$time)).totaldays) -lt 0} select-object Name,@{Name="Last Logon"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}} Out-GridView