General Powershell Notes

From Michael's Information Zone
Jump to navigation Jump to search

[1]

Access to Exchange Online

Log into exchange online.

$livecred = get-credential
$session = New-PSSession -configurationname microsoft.exchange -connectionuri https://ps.outlook.com/powershell/ -credential $livecred -authentication basic -allowredirection
import-pssession $session

Credentials

[2]To make life a little easier with service accounts, I needed to create the credential objects.

$admin='adminuser'
$pass1='securepasswordstoredforyoutoread'
$creds=new-object system.management.automation.pscredential($admin,$pass1)

Now I can run the scripts without typing things in all the time.

get-aduser -credentials $creds -identity someuser

Powershell Version

[3]

$PSVersionTable

Import Excel Spreadsheets

[4]This will save the hassle of converting to CSV all the time.

Install-Module ImportExcel

Import-Excel '.\test.xlsx' -StartRow 3 -EndRow 5 -StartColumne 2 -EndColumne 4

NTFS Permissions

[5] [6]

Get-Command –Module NTFSSecurity
Get-NTFSAccess -path .\Contacts
add-ntfsaccess -path .\contacts -account first.last -accessrights read

Passing Passwords to PSSession

[7] Convert to secure string then call from file. This following pulls from stdin as a secure string (converts what you type), then converts that to something (I'm still new to Microsoft's ways of doing things), then stores as a file.

read-host -assecurestring | convertfrom-securestring | out-file C:\securestring.txt