Anderson's

this tumblr is where i post random art and music that i like

fitness blog:
http://getstrongnerd.tumblr.com/

November 22, 2011 8:07 pm

Clear-Host

Get-WmiObject Win32_logicalDisk|Format-List @{E=”Description”;},@{E=”DeviceID”; L= “Drive Letter”;},@{E=”FileSystem”; L= “FileSystem”;},@{E=”FreeSpace”; L= “Available Storage (GB)”;},@{E=”Size”; L= “Storage Capacity (GB)”;};

#@{E=”Description”;},
#@{E=”FreeSpace”; L= “Available Storage (GB)”;}
#@{E=”Size”; L= “Storage Capacity (GB)”;},
#@{E=”FileSystem”; L= “FileSystem”;},
#@{E=”DeviceID”; L= “Drive Letter”;},

October 19, 2011 11:32 am

filer

file management:
“Last 10 event log entries: ” | out-file lasttenevents.txt -append
Get-Date | Out-File lasttenevents.txt -append
Get-EventLog –Logname “System” –Newest 10 | Format-Table EntryType, TimeGenerated, Message –AutoSize | out-file lasttenevents.txt -append
“———————-” | Out-File lasttenevents.txt -append
Get-Content lasttenevents.txt

    When the LastTenEvents.ps1 script is working as intended, perform these procedures:

•    From a single command line entry, create a directory called Practice below the current directory.

New-Item -Name newdir -type directory

•    From a single command line entry, copy LastTenEvents.ps1 into the Practice directory and name this new file LastTenEvents2.ps1.

Copy-Item -Path lasttenevents.txt -Destination C:\NewDir\lasttenevents2.txt


•    Modify the LastTenEvents2.ps1 script so it performs exactly as it did before except that each time the script is run any previous file content will be overwritten (Hint:  Only the first line needs to be modifies).

“Last 10 event log entries: ” | out-file lasttenevents.txt
Get-Date | Out-File lasttenevents.txt -append
Get-EventLog –Logname “System” –Newest 10 | Format-Table EntryType, TimeGenerated, Message –AutoSize | out-file lasttenevents.txt -append
“———————-” | Out-File lasttenevents.txt -append
Get-Content lasttenevents.txt

2.    Assume you want to create a Excel pie chart that shows the CPU utilization for the processes currently running on your system.  In order to do this on the PowerShell side you need to create a CSV file that contains the appropriate information.  The script you are to create will contain just two lines (although one line will be long).  Here are the specifications:
•    Line 1 will do the following:
•    A CSV file will be created that only contains a list of the process names and the CPU for processes where the ProcessName property is not equal to “svchost” and the CPU property is greater than 0.
•    Line 2 will do the following:
•    Display the content of the CSV file that was created.

get-process | select-object -property processname, cpu |Where-Object {$_.cpu -gt 0 -and $_.name -ne “scvhost”} | export-Csv lolerskates.csv
Get-Content lolerskates.csv

11:19 am

trololol

working with dates:
•    Currently it is 11:35 AM.
write-host -nonewline “The current time is ” ; ‘{0:h:mm tt}’ -f (get-date)

•    Today on March 14, 2010 the task was completed.

write-host -nonewline “Today on ” (get-date -f {MMMM d, yyyy}) ” the task was completed”

•    Right now it is 9:44 AM on Friday in the 3rd month of the year.

Write-Host “Today is” (‘{0:h:mm tt}’ -f (Get-Date)) “on” (‘{0:dddd}’ -f (Get-Date)) “in the” (‘{0:MM}’ -f (Get-Date)) “th month”


2.    Create a script that will generate Help Desk ticket that meets the following specifications:
•    Ask for a brief description of the problem and stores this into a variable
•    Generates screen the following screen output:
•    Heading:  Help Desk Ticket
•    Date of ticket entry
•    Time of ticket entry
•    Ticket description previously entered

Format:
    Help Desk Ticket
    Date:  3/19/2010
    Time:  12:37 PM
    Description:  (Whatever was entered at the start of the script)


$desc = read-host prompt “Please enter a brief description of the problem”
 
 Write-Host “Help Desk Ticket”
 write-host “Date:” (Get-Date -Format d)
 write-host “Time:” (Get-Date -Format t)
 write-host “Description:” $desc



string operators:

$path = (get-location).path
$statement = “the current directory is”
write-host $statement $path


$statement + $path

second question: print a string underlined and centered

$title = read-host -prompt “enter title”
$underline = ‘_’ * $title.length
[int]$field = (40 - $title.length/2)+ $title.length



$mask =”{0,” + $field + “:c}”

$mask -f $title
$mask -f $underline

third question: stupid barchart faggetory

clear
$list= get-process |select -property handles, processname

#longest processname
$longest = 0
foreach($proc in $list){
    if($proc.processname.length -gt $longest){
        $largest = $proc.processname.length
    }
}

$mask = “{0,” + $longest + “:s} {1:s}”

$mask -f “processname”, “handles (* = 100)”
foreach($proc in $list){
    $blob = “*” * ($proc.handles/100)
    $mask -f $proc.processname, $blob
}



arrays:

•    From a single command line entry, determine the number of elements in the $SerRun array.

$SerRun.count


•    From a single command line entry, list the first 10 elements in the $SerRun array.

$SerRun[0..9]

•    From a single command line entry, list just the 2nd and 4th elements in the $SerRun array.

$SerRun[1,3]

•    From a single command line entry, list the last 10 elements in the $SerRun array starting with the 10th to the last, then the 9th to the last, and so on to the last element.

$SerRun[($SerRun.length -10)..-1]
$serrun |select –last 10

•    From a single command line entry, list the last 10 elements in the $SerRun array in reverse order.

$SerRun[-1 ..($SerRun.length -10)]

•    From a single command line entry, list all of the elements in the $SerRun array in reverse order.

[array]::Reverse($SerRun)
$serrun[($serrun.length -1)..0]
•    From a single command line entry, list the first ten and the last ten elements in the $SerRun array.
$serrun[0..9 + -10..-1]
$serrun |select –first 10 –last 10


•    From a single command line entry, use the $SerRun array’s contents to create a new array called $SerRunNameOnly that only contains the ServiceName part for all $SerRun elements.  For example, if

April 18, 2011 10:05 pm
10:04 pm
10:04 pm
most awesome aquarium ever.

most awesome aquarium ever.

10:02 pm
10:02 pm
10:01 pm
9:59 pm