Difference between revisions of "General Powershell Notes"
Jump to navigation
Jump to search
Michael.mast (talk | contribs) |
Michael.mast (talk | contribs) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<ref>https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/enable-psremoting</ref> | <ref>https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/enable-psremoting</ref> | ||
+ | |||
+ | ==Access to Exchange Online== | ||
+ | Log into exchange online. | ||
+ | <pre> | ||
+ | $livecred = get-credential | ||
+ | $session = New-PSSession -configurationname microsoft.exchange -connectionuri https://ps.outlook.com/powershell/ -credential $livecred -authentication basic -allowredirection | ||
+ | import-pssession $session | ||
+ | </pre> | ||
+ | |||
+ | ==Credentials== | ||
+ | <ref>https://blogs.technet.microsoft.com/gary/2009/07/23/creating-a-ps-credential-from-a-clear-text-password-in-powershell/</ref>To make life a little easier with service accounts, I needed to create the credential objects. | ||
+ | <pre> | ||
+ | $admin='adminuser' | ||
+ | $pass1='securepasswordstoredforyoutoread' | ||
+ | $creds=new-object system.management.automation.pscredential($admin,$pass1) | ||
+ | </pre> | ||
+ | Now I can run the scripts without typing things in all the time. | ||
+ | <pre> | ||
+ | get-aduser -credentials $creds -identity someuser | ||
+ | </pre> | ||
+ | |||
+ | ==Powershell Version== | ||
+ | <ref>https://stackoverflow.com/questions/1825585/determine-installed-powershell-version</ref> | ||
+ | <pre> | ||
+ | $PSVersionTable | ||
+ | </pre> | ||
+ | |||
+ | ==Import Excel Spreadsheets== | ||
+ | <ref>https://blogs.technet.microsoft.com/heyscriptingguy/2015/11/25/introducing-the-powershell-excel-module-2/</ref>This will save the hassle of converting to CSV all the time. | ||
+ | <pre> | ||
+ | Install-Module ImportExcel | ||
+ | |||
+ | Import-Excel '.\test.xlsx' -StartRow 3 -EndRow 5 -StartColumne 2 -EndColumne 4 | ||
+ | </pre> | ||
+ | |||
==NTFS Permissions== | ==NTFS Permissions== | ||
<ref>https://gallery.technet.microsoft.com/scriptcenter/1abd77a5-9c0b-4a2b-acef-90dbb2b84e85</ref> | <ref>https://gallery.technet.microsoft.com/scriptcenter/1abd77a5-9c0b-4a2b-acef-90dbb2b84e85</ref> | ||
<ref>https://blogs.technet.microsoft.com/fieldcoding/2014/12/05/ntfssecurity-tutorial-1-getting-adding-and-removing-permissions/</ref> | <ref>https://blogs.technet.microsoft.com/fieldcoding/2014/12/05/ntfssecurity-tutorial-1-getting-adding-and-removing-permissions/</ref> | ||
<pre> | <pre> | ||
+ | Get-Command –Module NTFSSecurity | ||
Get-NTFSAccess -path .\Contacts | Get-NTFSAccess -path .\Contacts | ||
add-ntfsaccess -path .\contacts -account first.last -accessrights read | add-ntfsaccess -path .\contacts -account first.last -accessrights read | ||
+ | </pre> | ||
+ | |||
+ | ==Passing Passwords to PSSession== | ||
+ | <ref>http://web.archive.org/web/20160822030847/http://geekswithblogs.net/Lance/archive/2007/02/16/106518.aspx</ref> 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. | ||
+ | <pre> | ||
+ | read-host -assecurestring | convertfrom-securestring | out-file C:\securestring.txt | ||
</pre> | </pre> |
Latest revision as of 11:15, 1 May 2019
Contents
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
$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
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
- ↑ https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/enable-psremoting
- ↑ https://blogs.technet.microsoft.com/gary/2009/07/23/creating-a-ps-credential-from-a-clear-text-password-in-powershell/
- ↑ https://stackoverflow.com/questions/1825585/determine-installed-powershell-version
- ↑ https://blogs.technet.microsoft.com/heyscriptingguy/2015/11/25/introducing-the-powershell-excel-module-2/
- ↑ https://gallery.technet.microsoft.com/scriptcenter/1abd77a5-9c0b-4a2b-acef-90dbb2b84e85
- ↑ https://blogs.technet.microsoft.com/fieldcoding/2014/12/05/ntfssecurity-tutorial-1-getting-adding-and-removing-permissions/
- ↑ http://web.archive.org/web/20160822030847/http://geekswithblogs.net/Lance/archive/2007/02/16/106518.aspx