{"id":1769,"date":"2015-11-25T04:05:52","date_gmt":"2015-11-25T04:05:52","guid":{"rendered":"http:\/\/pariswells.com\/blog\/?p=1769"},"modified":"2015-11-25T04:05:52","modified_gmt":"2015-11-25T04:05:52","slug":"365-useful-commands-for-powershell-administration","status":"publish","type":"post","link":"https:\/\/pariswells.com\/blog\/random\/365-useful-commands-for-powershell-administration","title":{"rendered":"365 Useful Commands for Powershell Administration"},"content":{"rendered":"<div><strong><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-1770 img-responsive\" src=\"http:\/\/pariswells.com\/blog\/wp-content\/uploads\/2015\/11\/Office-365-New1-150x150.jpg\" alt=\"Office-365-New[1]\" width=\"150\" height=\"150\" \/>Add Permissions<\/strong><\/div><div>\u00a0<\/div><p style=\"font-family: 'Segoe UI', Arial, sans-serif; background-color: #ffffff; border: 0px; margin: 0px 0px 8px; padding: 0px; vertical-align: baseline; font-size: 15px; line-height: 1.7em; color: #333333;\"><tt style=\"font-family: 'Courier New', Courier, monospace !important; background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; line-height: 21px; overflow: auto;\">$LiveCred = Get-Credential<\/tt><\/p><p style=\"font-family: 'Segoe UI', Arial, sans-serif; background-color: #ffffff; border: 0px; margin: 0px 0px 8px; padding: 0px; vertical-align: baseline; font-size: 15px; line-height: 1.7em; color: #333333; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-position: initial initial; background-repeat: initial initial;\"><span style=\"background-color: transparent; font-family: 'Courier New', Courier, monospace; line-height: 21px;\">$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https:\/\/ps.outlook.com\/powershell\/ -Credential $LiveCred -Authentication Basic \u2013AllowRedirection<\/span><\/p><p style=\"font-family: 'Segoe UI', Arial, sans-serif; background-color: #ffffff; border: 0px; margin: 0px 0px 8px; padding: 0px; vertical-align: baseline; font-size: 15px; line-height: 1.7em; color: #333333; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-position: initial initial; background-repeat: initial initial;\"><tt style=\"font-family: 'Courier New', Courier, monospace !important; background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; font-size: 15px; line-height: 21px; overflow: auto; background-position: initial initial; background-repeat: initial initial;\">Import-PSSession $Session<\/tt><\/p><div><tt style=\"font-family: 'Courier New', Courier, monospace !important; background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; font-size: 15px; line-height: 21px; overflow: auto; background-position: initial initial; background-repeat: initial initial;\"><a>\/\/Add<\/a>\u00a0to Outlook<\/tt><\/div><div><tt style=\"font-family: 'Courier New', Courier, monospace !important; background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; font-size: 15px; line-height: 21px; overflow: auto; background-position: initial initial; background-repeat: initial initial;\">UserA to B<\/tt><\/div><div><tt style=\"font-family: 'Courier New', Courier, monospace !important; background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; font-size: 15px; line-height: 21px; overflow: auto; background-position: initial initial; background-repeat: initial initial;\">Add-MailboxPermission -identity UserB@domain.com -user UserA@domain.com -AccessRights FullAccess<\/tt><\/div><div><tt style=\"font-family: 'Courier New', Courier, monospace !important; background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; font-size: 15px; line-height: 21px; overflow: auto; background-position: initial initial; background-repeat: initial initial;\">\u00a0<\/tt><\/div><div><tt style=\"font-family: 'Courier New', Courier, monospace !important; background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; font-size: 15px; line-height: 21px; overflow: auto; background-position: initial initial; background-repeat: initial initial;\"><a>\/\/Don't<\/a>\u00a0add to Outlook<\/tt><\/div><div><tt style=\"font-family: 'Courier New', Courier, monospace !important; background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; font-size: 15px; line-height: 21px; overflow: auto; background-position: initial initial; background-repeat: initial initial;\">Add-MailboxPermission -Identity &lt;Mailbox ID1&gt; -User &lt;Mailbox ID2&gt;-AccessRights FullAccess -AutoMapping:$false<\/tt><\/div><div><tt style=\"font-family: 'Courier New', Courier, monospace !important; background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; font-size: 15px; line-height: 21px; overflow: auto; background-position: initial initial; background-repeat: initial initial;\">\u00a0<\/tt><\/div><div><span style=\"font-family: 'Courier New', Courier, monospace;\"><span style=\"font-size: 15px; line-height: 21px;\"><strong>\/\/Remove-MailboxPermission<\/strong><\/span><\/span><\/div><div>Remove-MailboxPermission<span style=\"font-family: 'Courier New', Courier, monospace; font-size: 15px; line-height: 21px;\">\u00a0-identity ian@jeppesenheaton.co.uk -user geraldine@jeppesenheaton.co.uk -AccessRights FullAccess<\/span><\/div><div><span style=\"font-family: 'Courier New', Courier, monospace; font-size: 15px; line-height: 21px;\">\u00a0<\/span><\/div><div><span style=\"font-family: 'Courier New', Courier, monospace; font-size: 15px; line-height: 21px;\"><strong><a>\/\/Viewmailbox<\/a>\u00a0Permission for Single Users\u00a0<\/strong><\/span><\/div><div>Get-MailboxPermission \u2013Identity \u201csimon\u201d | fl user, accessrights<\/div><div>\u00a0<\/div><div><strong><a>\/\/Export<\/a>\u00a0of All Permissions<\/strong><\/div><div><span style=\"font-family: 'Segoe UI', sans-serif; font-size: 10pt; background-color: #ffffff; text-align: left;\">Get-mailbox | Get-MailboxPermission | select-object FolderName,User,AccessRights,Identity, IsInherited,IsValid | export-csv -Path c:\\teste.csv<\/span><\/div><div><span style=\"font-family: 'Courier New', Courier, monospace; font-size: 15px; line-height: 21px;\">\u00a0<\/span><\/div><div><span style=\"font-family: 'Courier New', Courier, monospace; font-size: 15px; line-height: 21px;\"><strong><a>\/\/Add<\/a>\u00a0Distribution Group<\/strong><\/span><\/div><div>Add-DistributionGroupMember -Identity Support -Member James -BypassSecurityGroupManagerCheck<\/div><div>\u00a0<\/div><div>\u00a0<\/div><div><a>\/\/Password<\/a>\u00a0Never Expire<\/div><div><em style=\"background-color: #ffffff; border: 0px; font-size: 13px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; line-height: 23px; text-align: left;\">Connect-MSOLService<\/em><\/div><div><span style=\"font-family: Tahoma; font-size: xx-small;\"><span style=\"font-size: 8pt;\">Get-MSOLUser | Set-MSOLUser -PasswordNeverExpires $true<\/span><\/span><\/div><div><span style=\"font-family: Tahoma; font-size: xx-small;\"><span style=\"font-size: 8pt;\">\u00a0<\/span><\/span><\/div><div><span style=\"font-family: Tahoma; font-size: xx-small;\"><span style=\"font-size: 8pt;\"><a>\/\/Remove<\/a>\u00a0Strong Password One User<\/span><\/span><\/div><div><span style=\"color: #43515b; font-family: calibri; font-size: 15px; background-color: white; font-weight: bold;\">Set-MsolUser -UserPrincipalName\u00a0<\/span><a style=\"color: #02aced; outline: none; text-decoration: initial; font-family: calibri; font-size: 15px; background-color: #ffffff;\" href=\"mailto:user1@abc.com\"><span style=\"background-color: white; color: #0066cc; text-decoration: underline; background-position: initial initial; background-repeat: initial initial;\">user1@abc.com<\/span><\/a><span style=\"color: #43515b; font-family: calibri; font-size: 15px; background-color: white; font-weight: bold;\">\u00a0-StrongPasswordRequired $False<\/span><\/div><div><span style=\"color: #43515b; font-family: calibri; font-size: 15px; background-color: white; font-weight: bold;\">\u00a0<\/span><\/div><div><span style=\"color: #43515b; font-family: calibri; font-size: 15px; background-color: white; font-weight: bold;\"><a>\/\/Remove<\/a>\u00a0for all Users<\/span><\/div><div><div><span style=\"font-size: 11px;\">Get-MSOLUser | Set-MSOLUser\u00a0<\/span><span style=\"background-color: #ffffff; color: #43515b; font-family: calibri; font-size: 15px; font-weight: bold;\">-StrongPasswordRequired $False<\/span><\/div><div><span style=\"background-color: #ffffff; color: #43515b; font-family: calibri; font-size: 15px; font-weight: bold;\">\u00a0<\/span><\/div><div><strong style=\"font-size: 13px; border: 0px; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; margin: 0px; outline: 0px; padding: 0px; color: #333333; line-height: 16px; background-color: #ffffff;\"><a href=\"mailto:Johnwang@contoso.com\">Johnwang@contoso.com<\/a>\u00a0-&gt;<\/strong><strong style=\"font-size: 13px; border: 0px; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; margin: 0px; outline: 0px; padding: 0px; color: #333333; line-height: 16px; background-color: #ffffff;\"><a href=\"mailto:Johnwang@contoso.com\">Johnwang<\/a><\/strong><a style=\"font-size: 11px;\" href=\"mailto:TailspinCRM@forwardto.com\">@forwardto.com<\/a><span style=\"font-size: 11px;\">\u00a0<\/span><\/div><div><span style=\"background-color: #ffffff; color: #43515b; font-family: calibri; font-size: 15px; font-weight: bold;\">\u00a0<\/span><\/div><div><span style=\"background-color: #ffffff; color: #43515b; font-family: calibri; font-size: 15px; font-weight: bold;\">\/\/ Forward to contact without Mailbox<\/span><\/div><div><span style=\"font-family: Tahoma; font-size: xx-small;\"><span style=\"font-size: 8pt;\">New-MailContact <strong>John<\/strong> \u2013ExternalEmailAddress<\/span><\/span>\u00a0<strong>Johnwang@forwardto.com<\/strong><\/div><div>$obj = Get-MailContact <strong>John<\/strong><strong><br \/><\/strong><div>$obj.EmailAddresses.Add(&#8220;smtp:<strong>Johnwang@contoso.com<\/strong>&#8220;)<\/div><\/div><div>Get-MailContact <strong>John<\/strong> | Set-MailContact -EmailAddresses $obj.EmailAddresses<\/div><div><strong style=\"border: 0px; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; margin: 0px; outline: 0px; padding: 0px; color: #333333; font-size: 13px; line-height: 16px; background-color: #ffffff;\">\u00a0<\/strong><\/div><div><strong style=\"border: 0px; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; margin: 0px; outline: 0px; padding: 0px; color: #333333; font-size: 13px; line-height: 16px; background-color: #ffffff;\">Send as distribution List<\/strong><\/div><div><span style=\"border: 0px; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; margin: 0px; outline: 0px; padding: 0px; color: #333333; font-size: 13px; line-height: 16px; background-color: #ffffff;\">Create Discribution List and add user to it<\/span><\/div><div><span style=\"border: 0px; margin: 0px; outline: 0px; padding: 0px; background-color: #ffffff;\"><span style=\"color: #333333; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif;\"><span style=\"line-height: 16px;\">Set Account to\u00a0Receive\u00a0from outside\u00a0<\/span><\/span><\/span><\/div><\/div><div><span style=\"color: #010101; font-family: Calibri;\"><span style=\"font-size: 11pt;\">Add-RecipientPermission<\/span><\/span> <a href=\"mailto:newsletter@cogmotive.com\"><span style=\"color: #0000ff; font-family: Calibri;\"><span style=\"font-size: 11pt;\"><span style=\"text-decoration: underline;\">newsletter@cogmotive.com<\/span><\/span><\/span><\/a> <span style=\"color: #010101; font-family: Calibri;\"><span style=\"font-size: 11pt;\">-AccessRights SendAs -Trustee<\/span><\/span> <a href=\"mailto:alan@cogmotive.com\"><span style=\"color: #0000ff; font-family: Calibri;\"><span style=\"font-size: 11pt;\"><span style=\"text-decoration: underline;\">alan@cogmotive.com<\/span><\/span><\/span><\/a><\/div>","protected":false},"excerpt":{"rendered":"<p>Add Permissions\u00a0$LiveCred = Get-Credential$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https:\/\/ps.outlook.com\/powershell\/ -Credential $LiveCred -Authentication Basic \u2013AllowRedirectionImport-PSSession $Session\/\/Add\u00a0to OutlookUserA to BAdd-MailboxPermission -identity UserB@domain.com -user UserA@domain.com -AccessRights FullAccess\u00a0\/\/Don&#8217;t\u00a0add to OutlookAdd-MailboxPermission [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[1206,1207,1133,1163,1205,571,1208,576,1164],"class_list":["post-1769","post","type-post","status-publish","format-standard","hentry","category-random","tag-1206","tag-add-permissions","tag-commands","tag-forward","tag-office","tag-office-365","tag-password-expire","tag-powershell","tag-remove"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/1769","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/comments?post=1769"}],"version-history":[{"count":1,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/1769\/revisions"}],"predecessor-version":[{"id":1771,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/1769\/revisions\/1771"}],"wp:attachment":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/media?parent=1769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/categories?post=1769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/tags?post=1769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}