0% found this document useful (0 votes)
3 views26 pages

Profiles and Advance Scripting

Module 12 covers advanced Windows PowerShell techniques, including string and date manipulation, creating profile scripts, and using alternative credentials. It includes demonstrations and exercises to practice these skills, emphasizing the importance of security when handling profile scripts and credentials. The module concludes with a course evaluation to gather feedback on the learning experience.

Uploaded by

suresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views26 pages

Profiles and Advance Scripting

Module 12 covers advanced Windows PowerShell techniques, including string and date manipulation, creating profile scripts, and using alternative credentials. It includes demonstrations and exercises to practice these skills, emphasizing the importance of security when handling profile scripts and credentials. The module concludes with a course evaluation to gather feedback on the learning experience.

Uploaded by

suresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Module 12

Using Profiles and Advanced


Windows PowerShell
Techniques
Module Overview

Using Advanced Windows PowerShell


Techniques
Creating Profile Scripts
• Working with Alternative Credentials
Lesson 1: Using Advanced Windows
PowerShell Techniques

Manipulating String Values


Manipulating Date Values
Working with WMI and CIM Dates
Advanced Operators
Demonstration: Strings, Dates, and
Operators
Setting Default Parameter Values
Demonstration: Setting Default Parameter
Values
• Running External Commands
Manipulating String Values

• Strings are objects of the type


System.String
• Run "x" | Get-Member to see the type’s
property and methods
• These methods are used for string
manipulation
• The shell also offers three operators for
string manipulation:
• –Replace
• –Split
• –Join
• These all duplicate functionality of
System.String methods
Manipulating Date Values

• Dates are objects of the type


System.DateTime
• Run Get-Date | Get-Member to see the
type’s properties and methods
• The methods are used for date manipulation
• The properties extract portions of a date or time

• Use the [datetime] type accelerator to


convert string date representations to a
System.DateTime
• [datetime]$mydate = '1/1/2000'
Working with WMI and CIM Dates

• Common Information Model (CIM) dates


are in System.DateTime form
• Windows Management Instrumentation
(WMI) dates are in an internal date format
• All WMI objects have a ConvertToDateTime()
method that converts the internal format to a
System.DateTime
• They also have a ConvertFromDateTime()
that converts a System.DateTime to WMI date
format
Advanced Operators

• –In and –Contains test a collection to see


if it contains an object

• –Match compares a string to a regular


expression

• –As converts objects to a specified type


Demonstration: Strings, Dates, and
Operators

In this demonstration, you will see several


advanced Windows PowerShell techniques
• Manipulate string data
• Manipulate dates
• Manipulate WMI date information
• Use advanced operators
Setting Default Parameter Values

• Set default parameter values in


$PSDefaultParameterValues
• <command-name>:<parameter-
name>=<value>

• Use a hash table to redefine the variable


completely
• Use Add() and Remove() methods to
manipulate individual defaults
• Override defaults by manually specifying
parameters when running a command
Demonstration: Setting Default Parameter
Values

• In this demonstration, you will see how to


create and use default parameter values
Running External Commands

• Most external commands run correctly in


Windows PowerShell
• If a command’s syntax uses Windows
PowerShell special characters, it might not
run correctly
• Use --% before the command’s arguments
to force the shell to run the command
without trying to interpret the special
characters

ICACLS.EXE --% C:\TEST /GRANT USERS:


(F)
Lesson 2: Creating Profile Scripts

What is a Profile Script?


Profile Script Locations
Profile Security Concerns
• Demonstration: Creating a Profile Script
What is a Profile Script?

• Scripts that load and run automatically


each time a new shell session is opened
• Implemented by the host application, not
by the Windows PowerShell engine
• Different hosts may define different profile script
locations
• Some hosts may not load profile scripts at all

• Use to define aliases, load modules, and


configure the shell environment to meet
your needs
Profile Script Locations

• Each host application defines the script


files it will load and the order in which it
loads them
• The console and ISE host applications
share certain profile scripts, and define
other scripts that are unique to each

• Easy to remember: \Documents\


WindowsPowerShell\profile.ps1
Profile Security Concerns

• Profile scripts are local text files that can


be modified by any process running under
your user credentials, even non-elevated
credentials
• But profile scripts typically run under
elevated credentials, making them a
potential security risk

• Be aware of the security risks


• To provide better security, use a
completely different account to open
Windows PowerShell sessions
Demonstration: Creating a Profile Script

In this demonstration, you will see how to


create an all-host, current-user profile
Lesson 3: Working with Alternative
Credentials

What Is a Credential?
Creating and Using a Credential
Persisting Credentials
• Demonstration: Creating and Using a
Credential
What Is a Credential?

• Provide alternate credentials to commands


that have a –Credential parameter
• Allows the command to perform its task
using that credential rather than the one
you used to open the shell
• You will be prompted for the password by
means of a dialog box
• You can also create a reusable credential
object that includes both the user name
and the password
Creating and Using a Credential
Persisting Credentials

• It is possible to store a password to disk in


an encrypted form
• That password can be read from disk and
used to create a credential object, without
prompting for the credential password

• However, this approach is not


recommended because the password is not
stored in a form that is protected from
accidental discovery or disclosure
• Stored passwords are compromised
passwords
Demonstration: Creating and Using a
Credential

• In this demonstration, you will see how to


create and use a credential object
Lab: Practicing Advanced Techniques

Exercise 1: Using Advanced Techniques


Exercise 2: Using Alternative Credentials
• Exercise 3: Create a Profile Script

Logon Information

Virtual Machines: 10961B-LON-DC1, 10961B-LON-C


User Name: ADATUM\Administrator
Password: Pa$$w0rd

Estimated Time: 75 minutes


Lab Scenario

You have to practice how to use several


advanced Windows PowerShell features.
This includes date and string manipulation,
advanced comparison operators, and
alternative credentials. You also have to
create a profile script.
Lab Review

If your user profile is redirected to a network


location, will profile scripts still work?
• How can you quickly obtain a list of
methods and properties for a string object
or for a date object?
Module Review and Takeaways

Real-world Issues and Scenarios


• Common Issues and Troubleshooting Tips
Course Evaluation

• Your evaluation of this course will help


Microsoft understand the quality of your
learning experience.
• Please work with your training provider to
access the course evaluation form.
• Microsoft will keep your answers to this
survey private and confidential and will use
your responses to improve your future
learning experience. Your open and honest
feedback is valuable and appreciated.

You might also like