Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x

Powershell

15K

Solutions

7K

Contributors

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

Share tech news, updates, or what's on your mind.

Sign up to Post

I'm looking for a way to improve this powershell script:

Get-Mailbox -ResultSize Unlimited -OrganizationalUnit "OU=TestOU,DC=DOMAIN,DC=COM" |Select-Object DisplayName,PrimarySmtpAddress, @{Name="EmailAddresses";Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq "smtp"}| ForEach-Object {$_.SmtpAddress}}} |Export-CSV c:\csv_exports\exportsmtp3.csv -NoTypeInformation

Open in new window


This script woks for the most part, but all the secondary smtp addresses are contained in the same block in the exported csv. What I need is to either have all the smtp addresses in their own values, or to filter and only export a specific "@domainname.com" addresses and not the rest.

This is on the Windows Server 2008 r2 with Exchange 2010

Thank you,

-Matt
0
Free Tool: Site Down Detector
LVL 10
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

how do I remove files and folders from multiple client machines using sccm 2016? do I use application or package?
I am looking to delete certain .exe files and some folders from few location on client machines.

what script should I use? do I use powershell or vbscript? and what is the installation command line for using either one?

Regards

AZ
0
I have an excel file with 2 sheets and need to convert into html and send an email using sendemail using PowerShell. I would like to send html file as an embedded email rather than attachment. I want entire script in PowerShell

Any help is appreciated.

Suresh
0
I picked up this command from EE which gives a head count per security group. Does anyone know if the following command will also factor in its count, “group members within sub groups”? Or will it only enumerate the first level of sub groups and their members? or does it keep going as far down the hierarchy as necessary.

Get-ADGroupMember -Identity <Group> -Recursive | Measure-Object | Select-Object -ExpandProperty Count


Does anyone know how it could be changed to not only give the count (of total members including sub groups), but also give the details of all members as well (including the sub groups)?
1
Hi.

I have a text file with a list (more than 10 and growing) of hostnames on a domain.

I need a script to ping each of the hostnames, perform a -arp ping, and perform a last logged on check with time with the results output to CSV.

I have a Powershell Script that does a ping test from a text file. How do I perform all of the above in one and output the results to CSV as a report?

$names = Get-content "hnames.txt"

foreach ($name in $names){
  if (Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue){
    Write-Host "$name,up"
  }
  else{
    Write-Host "$name,down"
  }
}

Open in new window

0
Hi,

We have an organogram which is searchable (web based, don't know what  is running below). I'd like to search through it via Powershell then showing me the result.
F.e. John Doe gives a result in the webpage http://ourcompany/organogram (when entering a search box)
I'd like to have get-organogram -user 'John Doe'. Searched source code for this page but did not found enter or 'first name' ...


How could I achieve this?
J.
0
I have been using powershell to service workstation on our network.  The other day I figured I would try some new thing so I was playing with the new-pssession command.  The first time I tried it the session froze.  I could not connect to anything to check or correct errors. Dummy me I started to look up fixes but I made it worse.  Now I think I may have changed the whole networks powershell to use https.  I am now getting permission errors.  Is there a way to reset powershell defaults? Can I make an accross the board change to correct the network problem?
0
Need to run a Powershell script on AD that will extract all  users that have not logged in past over 120 days. I need to get when the account was created , the last time they logged in if any and the number of days past 120 days ., then export this into a csv file
0
I need help with the middle portion of this script...

"""foreach ($Man in $managerusers2)
    {
    $managerusers = $managerusers + Get-ADUser $Man -Properties * | Select-Object samaccountname, mail
    }"""

I have a group called "Test_Department_Manager" and in the group I have a few managers. I need to send an email to them that list each employee that they are a direct report for and who has access to their employees mailbox..
Import-module activedirectory
Import-Module MSOnline

$Username = "user@domain.com"
$Password = ConvertTo-SecureString Password97 -AsPlainText -Force

$LiveCred = New-Object System.Management.Automation.PSCredential $Username, $Password
$senderemail="user@domain.com"
$subject="Your Direct Reports and Permission"

$managerusers2=Get-ADGroupMember -identity "Test_Department_Manager"



foreach ($Man in $managerusers2)
    {
    $managerusers = $managerusers + Get-ADUser $Man -Properties * | Select-Object samaccountname, mail
    }




Foreach ($manager in $managerusers)
 {
	# Find all direct user reporting to manager	
	
	$directreportusers=Get-ADUser -Identity test_director -Properties directreports | Select-Object -ExpandProperty directreports |  Get-ADUser -Properties mail |  Select-Object SamAccountName, mail
	
	#$directreportusers=Get-ADDirectReports -Identity $manager.SamAccountName
	
	$manageremail=$manager.mail
	
	Foreach ($user in $directreportusers)
		{
		
		$Session = New-PSSession -ConfigurationName Microsoft.Exchange 

Open in new window

0
Hi Guys,

when assigning a license out of an accountsku to a user, you can limit the given functionality with -disabledPlans.
Is there a way to turn the logic upside down and work with "EnabledPlans" ?

Thank you for helping out,

Grtz
0
NFR key for Veeam Backup for Microsoft Office 365
LVL 1
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Hi Experts

Am having a small issue with PowerShell when using a DatagridView in Windows Forms.

The DatagridView is being added to the form, but when the form is shown for the first time, it is "blank".  Or better said, the DatagridView is a White box.

Here is the code I use:

Add-Type -AssemblyName System.Windows.Forms

$objFrm = New-Object System.Windows.Forms.Form
$dgv_Info = New-Object System.Windows.Forms.DataGridView

$objFrm.Size = New-Object System.Drawing.Size(722, 563)
$objFrm.MinimumSize = New-Object System.Drawing.Size(722, 563)

$dgv_Info.Location = New-Object System.Drawing.Point(13, 342)
$dgv_Info.Size = New-Object System.Drawing.Point(681, 145)
$dgv_Info.Anchor = $AnchorStyle_BottomLeftRight
$dgv_Info.ColumnHeadersVisible = $true
$dgv_Info.RowHeadersVisible = $true
$dgv_cbCellSQLInst = New-Object System.Windows.Forms.DataGridViewComboBoxCell
$dgv_cbCellSQLInst.DataSource = $SQLInstanceNumbers
$outvar = $dgv_Info.Columns.Add($dgv_cbCellSQLInst)
$dgv_Info.Columns[0].Name = "Header 1"
$dgv_Info.Columns[0].AutoSizeMode = 'Fill'
$dgv_Info.Sort($dgv_Info.Columns[0], [System.ComponentModel.ListSortDirection]::Ascending)
$dgv_cbCellDrv = New-Object System.Windows.Forms.DataGridViewComboBoxCell
$dgv_cbCellDrv.DataSource = $DrvLetters
$outvar = $dgv_Info.Columns.Add($dgv_cbCellDrv)
$dgv_Info.Columns[1].Name = "Header 2"
$dgv_Info.Columns[1].AutoSizeMode = 'Fill'
$dgv_DBDisk = New-Object System.Windows.Forms.DataGridViewTextBoxCell
$outvar = 

Open in new window

0
Hi, I wonder if someone could help

Need run a report that identifies users that have expired passwords in AZURE AD and have licenses for apps assigned

Thanks in Advance

John
0
Hi,

We have an internal url at work where I can navigate to using chrome and view the pdf and download without any issue. When I try to do the same thing in powershell using code like below I get an unauthorised error. I don't understand the security part to well so trying to work out why I'm blocked through powershell but not through chrome. Do I need to send my credentials through some way? or do something else so powershell uses the same settings as the browser

$Url = "https://server/file.pdf"
$Path = "c:\temp\file.pdf"
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$webClient = new-object System.Net.WebClient
$webClient.DownloadFile( $Url, $Path )
0
Hello,

I have a powershell script which essentially "works" but with one caveat.

This script queues all the mailboxes to export immediately (i.e. if my text file contains a list of 15 mailboxes then the script queues all 15 mailboxes to export immediately).

The problem I have found is that when the server is trying to export more than one mailbox concurrently, some of the mailbox exports fail.

So I would like a way to either:

1. Modify the script to only perform one export at a time or
2. Configure some setting in Exchange so that only one New-MailboxExportRequest is executed at a time (I've had a look at the settings for this cmdlet and cannot see an option to do this)

$Export = Get-Content C:\Mailboxes.txt
foreach ($i in ($Export)) {New-MailboxExportRequest -ContentFilter {(Received -lt '01/09/2017')} -BadItemLimit 200 -AcceptLargeDataLoss -Mailbox $i -Filepath "\\SERVER\Mail\$($i).pst" }

Open in new window


Thank you
0
Hello EE,

I am looking for some help with a powershell script or template to help me get started.
I have 5 machines named test1, test2....test5 where I need to copy a file from a network share g:\copy
to each of these machines startup folder.

Any help would be great.  This can't be just manual.
0
People,

I’m running Exchange Server 2013 SP1, I’d like to convert normal Exchange Mailbox called HR into Shared mailbox while retaining the same permission and the data content.

How can I do it without impacting the current users and no data loss?
If I do it during the business hours, what is the impact?

Thanks in advance.
0
Hi I am running the below script which searches all users in AD for specific properties and exports the results to csv.

$date = get-date -format MMddyy
$getallusers = get-aduser -filter * -properties name, givenname, surname, employeeid, emailaddress, enabled, lastlogondate, created, passwordlastset, passwordneverexpires, passwordexpired, msds-userpasswordexpirytimecomputed, msExchRecipientTypeDetails | select-object name, givenname, surname, employeeid, emailaddress, enabled, lastlogondate, created, passwordlastset, passwordneverexpires, passwordexpired, @{Name="PasswordExpirationDate";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}}, msExchRecipientTypeDetails | export-csv -notypeinformation "D:\Scripts\CAI\Active Directory\ADAccountsReport_SecTeam\ADAccountsReport_$date.csv"

The above works, I get all the information I want but the results for msExchRecipientTypeDetails is the decimal value. I can go into Excel and convert the value to words easily but I wanted to know if Powershell can do the same.

Example msExchRecipientTypeDetails returns 2147483648 for remote user mailbox while 34359738368
is for remoted shared mailbox. Instead of exporting the decimal value to csv I want to export remote user mailbox for 214483648 and remoted shared mailbox for 34359738368.

Is this possible?
0
hello,

i need to delete some folder on server (windows 2008 or 2012).
but some times process blocked some folder or file to be deleted.

i need a script or command to check if any process is use specific folder and kill them so i can delete the folder.

i need a script because i have many folder to delete every day.

thanks for help
0
Hello All,

I've written a script ( just a beginner in Powershell ) for updating manager attribute in AD with a CSV of HR.
But, this CSV isn't up to date. I mean, some users or managers doesn't work anymore for our company.
So some users/managers doesn't exist or are disabled.
So I got errors in my powershell script.

My script:
 $users = import-csv  C:\Users\adm_velvnsar\Downloads\usersmanagers.csv

 ForEach ($user in $users) {
 $displaynameCSV = $user.Name
 $managerCSV = $user.Manager


$CurrentADUsersWithManager = Get-ADUser -filter {DisplayName -like $displaynameCSV} -properties * | Select-Object displayname,manager,SamAccountName 
$GetManagerSamAccountName = Get-ADUser -Filter {DisplayName -like $managerCSV} -Properties * | select-object SamAccountname


    If(!($CurrentADUsersWithManager.manager)) {
        If(!($GetManagerSamAccountName.SamAccountname)) {
            Set-ADUser $CurrentADUsersWithManager.SamAccountName -Manager $GetManagerSamAccountName.SamAccountname

      }
    }
 }

Open in new window


Maybe my script isn't written well, but it works..
But I want all users that doesn't exist anymore or disabled in a textfile, is it possible?
0
Technology Partners: We Want Your Opinion!
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Hi All,

I have this very basic dsc script when i run it it fails:

Configuration Testconfig {

Node localhost {

    File Test5 {


    DestinationPath = 'C:\TestdscPush.txt'
    Ensure = 'Present'
    Contents = 'Hello DSC World'


    }

                }

    




                        }

Testconfig

Open in new window


7      Job7            Configuratio... Failed        True            localhost            Start-DscConfigu...


please help!
0
Hello Experts,

I wonder if someone could help me to write a simple PowerShell script to collect information about computer and user logged, and export that information to a flag file.

This flag file should be saved into a location under c:\temp\%USERNAME%.flg, depending on the user logged and then copy the flag file from location above to a network share. i.e \\servername\ssharedfolder.

The information that we need to obtain is, essentially network drives map, ports in the PC[used or not], logontime and date, details on the user, and identify the OU where this computer resides on the WIndows 2012 domain. As well as PC details. See example below



LogonTime: 8:10:49 AM
LogonDate: 7/22/2015
USER DETAILS:
sAMAccountname: JDOE
UserDN: CN=doe\, John O,OU=company Administrators,DC=company,DC=com

Primary Security Group: NETWORK

PC DETAILS:
Computer: XXXXX
PC_DN: CN=XXXX,OU=Windows 8 ,OU=Windows 8 Test,OU=Test,DC=COMPANY,DC=com
Office OU: Windows 8 - WKS GPOs
HomeServer Name:
Serial Number:000794654057
ModelSurface Book
Drive XXXXXX
Drive G: = \\company.com\group\Chicago\CIS
Drive H: = \\company.com\user\Chicago corporate\jdoe
Drive P: = \\company.com\data\PUBLIC
Drive Z: = \\company.com\data\PUBLIC\jdoe\Folders\2017\Telecom

Port WebEx Document Loader Port = WebEx Document Loader
Port nul: = Send To OneNote 2016
Port IP_10.101.35.112 = yyyyyy
Port IP_10.101.35.120 = zzzzz
Port PORTPROMPT: = Microsoft XPS Document Writer
Port PORTPROMPT: = …
1
Hello All,

Below script is working fine. the script is to Set-ADAccountExpiration and set logon deny. post execution of script account expiry should be the date when script script executes against the ADuser. but the I am getting is Post script exection When i look for account expiry it is one day before stamped from the date of script execute.

Same script working fine as expected  in my test environement but not in prodution. Thanks in advance


Import-Module activedirectory

$tdate = Get-Date -Format "dd-MM-yyyy"
[byte[]]$hours = @(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
$users = get-content "C:\input.txt"

foreach ($user in $users) {
$UserSet = get-aduser $user
Set-ADAccountExpiration $userset -DateTime $tdate
Set-ADUser $UserSet -Replace @{Logonhours = [Byte[]]$Hours}}

Open in new window

0
Experts,

In regards to a Meterpreter session, is that occuring over Powershell?

Or is it the module that was used such as use exploit/windows/smb/psexec  that is powershell?
0
Hi

I am working on office migrating exchange 2007 to O365 and the staged migration document says:
The on-premises user account that you use to connect to your on-premises Exchange organization (also called the migration administrator) must have the necessary permissions to access the on-premises mailboxes that you want to migrate to Office 365.  This user account is used when you Connect Office 365 to your email system later in this procedure.

4. To migrate the mailboxes, the admin must have one of the following permission sets:
Be assigned the FullAccess permission for each on-premises mailbox and be assigned the Write Property permission to modify the TargetAddress property on the on-premises user accounts.

I have now created and migrationadmin user account  and he is member of the domain administrator group. To assign  FullAccess permission for each on-premises mailbox- I right click  the users mailboxes- Manage Full Access Permission- Add the migrationadmin and click manage- Finish,

But not sure how to assign  Write Property permission to the "migrationadmin"  so that he can have the required permissions to migrate users mailboxes to O365 .

Any help would be great. Thanks
0
One of my users accidentally deleted 2 items in a sharepoint document library, when he tried to restore them in sharepoint recycle bin he gets a correlation ID. We tried to restore older deleted items and got getting the same error newly deleted items seem to work though when restoring it.

NOTE:
Tried to use different computer and browsers
Sharepoint library is not synced in onedrive so I can't restore it from the local recycle bin

Is there a powershell comand that can restore these items?
0

Powershell

15K

Solutions

7K

Contributors

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.