Powershell

19K

Solutions

8K

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 am executing lines of a script …

foreach ($vm in $vms)
{Get-SerialPort -VM $vm | Remove-SerialPort -VM $vm }


foreach ($vm in $vms)
{Get-ParallelPort -VM $vm | Remove-ParallelPort -VM $vm }

However, I get an error message saying the parallelPort line could not run as the '{Get-SerialPort -VM $vm | Remove-SerialPort -VM $vm }' had not finished.
I added a  "Start-Sleep -Milliseconds 3000" and the serial ports and parallelports are removed without error.
But I want an alternative fix, so the the script checks that  '{Get-SerialPort -VM $vm | Remove-SerialPort -VM $vm }' is finished then proceeds to call "foreach ($vm in $vms)
{Get-ParallelPort -VM $vm | Remove-ParallelPort -VM $vm }"

How do I do that ?
0
PMI ACP® Project Management
LVL 13
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

I had this question after viewing exchange ,script.

I am new to scripting and am trying to manipulate the same script as above to have the option of it to a local folder i.e. c:\temp directory or using the send-mail option.  Any help would be good.  I'm ok with hashing out each option so don't need it to automatically asking me.

I have dabbled with out-file and I can generate a file but alas it is empty, though I can't determine if this is something else I've modified in the script.
0
I have two Microphones connected to my Windows 10 Pro (64-bit) box.

One is built into my Web Cam ( Microsoft LifeCam Cinema ) and what I've been using up until now.

Recently I purchased a much higher quality USB Microphone that does a significantly better job at filtering out background noise.

Sometimes though, I still want to use the built-in Microphone in my LifeCam Cinema WebCam.

I know how to make the change via UI methods, but it takes too many clicks for my liking, so wondered if there is a simpler way to achieve the desired result?

Change Default Mic in Windows 10 using a script of some type.
So... what I need is a batch file, script or Powershell command way of telling Windows 10 which Microphone to use by default. Something I can double-click on my desktop which will result in all of the needed changes to be made to make one or the other Mic the default in Windows 10.

Please note that I am heavily challenged when it comes to any type of coding, scripting or automating. A programmer I am not.

Using a GUI I can figure out how to do just about anything on Windows, but if I need to make changes via Powershell or similar, please include detailed instructions on how, where and why I need to run the script(s), and if doing so will have any negative effect on Windows 10 security.  It's why I stay away from using PowerShell unless an expert in it tells me exactly what to do and why! <g>

With all that said, can anyone offer a solution?

Regards, Andrew
0
Hi,


In PowerShell if in my csv file I have the date of lastlogondate in this format: 2019-01-29  10:34:10 AM

I need to get users with lastlogondate older than 90 days. My question is:

Should I compare like this:

1- Where-Object {([datetime]::($_.lastlogondate) -le (Get-Date).adddays(-90))

or Like this:

2 -Where-Object {([datetime]::FromFileTime($_.lastlogondate) -le (Get-Date).adddays(-90))
0
I am trying to create a powershell script that will update a picture library web part in Sharepoint 2010.

I have a column that contains a hyperlink that I essentially need to iterate through about 400 times to update the column to a new hyperlink value.


How do I do this?   I  have never created powershell for sharepoint.    I also would want a way to run it in a test mode as well..so I know i am not doing anything wrong before actually updating the values.
0
This one always frustrate me.  Simple command to see all the domain or forest details. And it doesn't show the list all the servers or sites.  
For example: Get-ADDomain | Format-List
Gives me
ReplicaDirectoryServers            : {server1.company.com, server2.company.com, server3.company.com, server4.company.com...}   how to get all servers?

Same for this:  Get-ADForest | Format-List

Gives me:
GlobalCatalogs        : {server1.company.com, server2.company.com, server3.company.com, server4.company.com...}  how to get all servers?
Sites                 : {site1, site2, site3, site4...} how to get all sites?

I'm probably missing something very simple.  Just annoying issue!
1
I need to clean up 20+ distribution groups with duplicates (due to nested groups) in Office365 and I am thinking the best way to manage it would be to:

  1. Use a text filter or import a CSV to target only specific groups that need this cleanup
  2. Add the Managers distribution group to the targeted list
  3. Remove any of the individual managers that are part of the targeted group.


Here is an example of the current group setup:

Managers DL: managers@email.com
manager1@email.com
manager2@email.com
manager3@email.com
manager4@email.com
manager5@email.com
manager6@email.com
manager7@email.com
manager8@email.com
manager9@email.com
manager10@email.com

Current Field site DL: Site1@email.com
user1@email.com
user2@email.com
user3@email.com
user4@email.com
user5@email.com
manager1@email.com
manager2@email.com
manager3@email.com
manager4@email.com
manager5@email.com
manager6@email.com
manager7@email.com
manager8@email.com
manager9@email.com
manager10@email.com

Here is an example of a group that I have manually edited to get the desired outcome:

Cleaned up field site DL: Site1@email.com
user1@email.com
user2@email.com
user3@email.com
user4@email.com
user5@email.com
managers@email.com

Any suggestions would be appreciated.
0
I have a Group Policy Script modified from technet (link: https://gallery.technet.microsoft.com/scriptcenter/GroupPolicy-Monitor-55f34fdd)

Purpose is to:

1.) -Create Backup of all Group Policy's
2.) -Create an XML report of the current state of all Group Policy's
3.) -Monitor Group Policy's for changes by comparing Group Policy's against the XML report then create a HTML report listing any changes made

It is working well with how it is setup per below code for monitoring all GPO's objects that show on Client Domain Controllers when this command is run.  (Get-ADOrganizationalUnit -Filter 'gpLink -gt "*"' | Get-GPInheritance)

This command is under the Execution section of the script.

However, the command above does not list "Default Domain Policy" or the Group Policy Objects under the Root Domain Container. So I would very much appreciate some help with getting a Powershell Query to include these missing Group Policy objects so they are also backed up and monitored and including it in the script.



#---------------------------------------------------------[Modules]---------------------------------------------------------
Import-Module ActiveDirectory,GroupPolicy

#--------------------------------------------------------[Variables]--------------------------------------------------------
$watchedOU = Get-ADOrganizationalUnit -filter 'Name -like "*"'| select -ExpandProperty DistinguishedName
$rootDN = Get-ADDomain | select -ExpandProperty 

Open in new window

1
i've been having the hardest time using PowerShell v6.1, which I downloaded after already having a 5.1 install.

When I launched powershell via the command line (by typing powershell), the 5.1 kept coming up.

I finally went and manually deleted one of the entries in the path leaving only the path to v 6 and then typed the command powershell and it said command not found.

Finally then, after looking around, it seems I have to now type pwsh vs. powershell (because there no longer is a powershell.exe?)

When did this change?
1
How can I view the Recipient information in an Output file like a csv file when using Get-Queue -id server\Submission | Get-message -IncludeRecipientInfo |Select FromAddress,Rec*,Status



Here is what I get Recipient Column  "Microsoft.Exchange.Data.QueueViewer.RecipientInfo[]"

Any thoughts?
1
JavaScript Best Practices
LVL 13
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Hello-

I have a little local intranet website which creates <temp>.tmp files on the system.  Those files contain simple powershell commands which are to be run against the system.  What i want to do is monitor the c:\temp directory on the webserver and when it sees a file in there, process those files running the commands one at a time in powershell with elevated privileges.  I have this working now using another powershell script which watches the directory, but it fails when a bunch of files are put in there all at once and is generally flaky.  I am fine with a commercial product to be used to watch the directory, but haven't found anything that works well in Windows 2012 Server.  Essentially the powershell should only fire when a file is "changed" as the website creates the temp file, then adds the commands to it, then saves it.  It all happens with a second or so, but I would want to be sure the file is complete before processing it.  Can anyone help?  I would also like to log the transactions to a file upon processing.
1
Hi Team,

Wanted some help with a PowerCLI script posted in https://communities.vmware.com/docs/DOC-14180

I'm not able to understand the instructions of this script on how to provide the inputs required. Need some help with it.

Thanks.

Below is a snippet of the code

# *************************************************************************
# Copyright 2010 VMware, Inc.  All rights reserved.
# *************************************************************************/

#
# This script exports the compliance status information in csv format
#
# PARAMETERS
#	$1 - InventoryItems
#		The inventory items for which the compliance status will be exported
#	$2 - Path
#		Absolute path to the folder, where the csv files to be saved
#
# USAGE
#	The following example exports the compliance status of all VM Hosts against attached baselines.
#	The format of  the output is csv. Depending of the type of the attached baselines a different type of csv files
#	will be created.
#
# Connect-VIServer <ip_address>
# $vmHosts = Get-VMHost
# ExportCompliance.ps1 $vmHosts "C:\MyReports\"
#

Param([VMware.VimAutomation.ViCore.Types.V1.Inventory.InventoryItem[]] $inventoryItems, [System.String] $path)

function GetPatchBaselineComplianceReport([VMware.VumAutomation.Types.PatchBaselineCompliance[]] $compliances){
	$patchBaselineComplianceReport = @()
	
	foreach ($compliance in $compliances) {
		$compliance.GetType().GetProperties() | where {$_.PropertyType.FullName -eq 

Open in new window

1
Hi,


We had an issue because of affected pc and all AD users was locked. How can I set account never locked out for  just some users like admin account?

Thanks
0
This is what I am using to get a Mobile Device report from our Office 365 server. I get Identity in the report, but it looks like this and is not easy to work with.

SERVER.PROD.OUTLOOK.COM/Microsoft Exchange Hosted Organizations/company365.onmicrosoft.com/Display Name/ExchangeActiveSyncDevices/Android?androidc97397597
SERVER.PROD.OUTLOOK.COM/Microsoft Exchange Hosted Organizations/company365.onmicrosoft.com/Display Name/ExchangeActiveSyncDevices/iPhone?7YHLOI8DER5HCN01HYHY8UDEC

This is the power shell I am running:

$Mailboxes = Get-Mailbox -Identity $_.UserPrincipalName -RecipientTypeDetails UserMailbox -ResultSize Unlimited
$Devices = $Mailboxes | %{Get-ActiveSyncDeviceStatistics -Mailbox $_.Identity} | `?{$_.LastSuccessSync | export-csv PATH

I need to get the email address, UPN, or even the user's display name in a column.

Any help much appreciated.
1
Hi,

I have problem to check if a user has really quit the company (except asking HR:-)) because by checking the lastlogon attribute in AD is not enough. If a user just uses his email the lastlogon is not completely accurate. Also the LastLogonTime  in O365 mailbox is not accurate at all (many things can change that value).

Mailbox activity report from O365 can't be manipulate by Powershell...have to download manually. I need something that I can code.

So what do you think I check lastlogon and pwdLastSet attributes? Like if both values are over 90 days then the user is really gone.
0
Hi,


How can I import this csv file path. Is it like this?:

$UserslogonFile = "users.csv"

$Users = Import-csv -Path ""C:\temp\$($UserslogonFile)"
1
My goal is to set up a limited domain user with access to create RemoteMailbox objects from a remote computer using powershell.

Steps I've taken:
  • I gave a limited domain user the "Recipient Management" role to create RemoteMailbox objects.
  • I added this user to the "Remote Management" local group on the Exchange Server.

The command to create the powershell session (
New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://$ExchangeServerDns/PowerShell/"

Open in new window

) produces an access denied error. How do I resolve this?
1
Hey Experts.  I've tried putting together a PS script to delete user profiles that are not related to the default user accounts (local admin, etc).  The environment is Win 7 Enterprise and will be applied to the training room computers which have been getting killed by user profiles eating up drive space.  Your time/help is appreciated.
0
I am trying to permanently delete a SharePoint online Site Collection and unable to do so using Powershell.  I keep getting a message that displays "Remove-SPODeletedSite : Unable to find the deleted site: https://XXX.sharepoint.com/sites/Site_1.

The command that I'm using is:
Remove-SPODeletedSite -Identity https://XXX.sharepoint.com/sites/Site_1

When I try to find the deleted sites using command Get-SPODeletedSite nothing displays.  I can see the site collection in the recycle bin.

Not sure what I'm doing wrong, any suggestions?

I've already tried the suggestions listed here:  https://docs.microsoft.com/en-us/powershell/module/sharepoint-online/remove-spodeletedsite?view=sharepoint-ps
0
Why Diversity in Tech Matters
LVL 13
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

How do update a group mailbox for an established group in Microsoft teams? Preferably without using PowerShell but will do it if necessary. Any help would be appreciated. Thanks!
0
what powershell command should i run on office 365 to
 check to see if any of our mail groups uses  members.routine@domain.com as an alias?
0
Hi,


How to read with PowerShell a csv file with header name containing space?

Like:
Display Name, Last Logon Date

I don't want to reformat the header name all the time.
1
Hi,

Ii it possible that the "last activity date in the Office 365" for mail activity is wrong? I just export the csv file and it shows my last activity date is last Friday but I have sent email Saturday.

What MS considers as last activity date?

Thanks
0
Hi,

In O365 a shared mailbox does need a license but is there any limit to create a shared mailbox?

Like can we create a shared mailbox for x number of users?

Thanks
1
Hi,

I know in O365 if we delete a mailbox the default retention is 30 days but can we change it for 90 days?

I think 30 days is too short if we need to restore mailbox.

Thanks
0

Powershell

19K

Solutions

8K

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.