[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

Powershell

18K

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 would like to modify a CSV file found at ..

C:\users\user\Desktop\file.csv
A sample of the data is found below.
However there could be thousands of lines.


"Data1","Qty1","Qty2"
"ABC1234","0","0"
"ZDG123","525012","0"
"JKL432","0","0"
"TYI00121-1","0","0".
"No of Items","4",""


I want to modify it using a Script so that it searches through the file and when it sees ZDG123, or any other numbers that I will specify in position 1, that it will take the Quantity showing and divide it by 1000, and then re-write the file with the correct changed data.   For example for line shown above as:  "ZDG123","525012","0",  it will then become:   "ZDG123","525.01","0"

Would this be possible, using a scipt?
0
Angular Fundamentals
LVL 12
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Have clients who want a policy pushed to their systems/mailboxes that will create an Outlook (O365) quick step that is basically a Send Secure email with Send Secure in the subject line.  There are roughly 300 users, and they do not want to manually create the step, they want us - their outsourced IT, to push a policy or package that will do this.  This link is exactly what they want https://louisville.edu/security/files/SENDSECUREHowtocreateaQuickStepButton.pdf but we need to either push via script or another way.  Definitely open to suggestions.
0
PowerShell Gurus,

I have a slight issue.  We are attempting to use PowerShell to automate the application of secure RDP SSL certificates to our RDSH hosts.

PS C:\WINDOWS\system32> $PSVersionTable

Name                           Value                                                                                                                                                          
----                           -----                                                                                                                                                          
PSVersion                      5.1.17134.407                                                                                                                                                  
PSEdition                      Desktop                                                                                                                                                        
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                        
BuildVersion                   10.0.17134.407                                                                                                                                                 
CLRVersion                     4.0.30319.42000                                                                                                   

Open in new window

0
I have chocolatey installed on my remote Windows 10 client where I want to run the following command, and I want to run this command remotely with powershell remoting:
choco install rsat -y

Normally, I can run commands like these via powershell remoting, but this installation requires elevated administrator privileges.
How can I get around this, or how can I run a remote powershell session in elevated powershell so that this installation will work?
0
Which command would make more sense or be more efficient. The commands are the same except the first example i have it configured with 3 separate commands, whereas the second example i combined the 2nd and 3rd lines into 1 command.

This
$msgs = Get-TransportService | ? {$_.Name -like "ffus*" -or $_.Name -like "ffny*" –or $_.Name -like "ffusvpf2013*" –or $_.Name -like "ffnyvpf2013*"}
$msgslogs = $msgs | Invoke-Command {Get-MessageTrackingLog -ResultSize Unlimited -Start (Get-Date).AddMonths(-1)}
$msgslogs | ? {$_.EventId -like "DELIVER" -and $_.OriginalClientIP -ne "10.80.190.45" -and $_.OriginalClientIP -ne "10.80.209.29"} | measure-object


$msgs = Get-TransportService | ? {$_.Name -like "ffus*" -or $_.Name -like "ffny*" –or $_.Name -like "ffusvpf2013*" –or $_.Name -like "ffnyvpf2013*"}
$msgs | Invoke-Command {Get-MessageTrackingLog -ResultSize Unlimited -Start (Get-Date).AddMonths(-1)} | ? {$_.EventId -like "DELIVER" -and $_.OriginalClientIP -ne "10.80.190.45" -and $_.OriginalClientIP -ne "10.80.209.29"} | measure-object
0
How would you dump ALL the results and attributes from the Get-Mailbox and Get-MailboxStatistics commands via PowerShell to a CSV?

I thought there would be something out there... strangely, I haven't found anything.

Thanks.
0
Hello Experts Exchange,

I need to write a script for Emails send and receive for Exchange 2016. I have total 12 Exchange servers - 6 is in active and 6 are in passive servers.
Please let me know the syntax and how to start the script for Queue details, top 50 users every 2-3hrs monitor the User Email address,CSV format to send Emails the status and below details.  

Top 50 users per day and per hr.
Display Name
Email address
Server Name
No.of Mails Send/Recieve
Internal and External Emails
0
Hi,

I am trying to export users from about 300 groups to CSV. What is the best way and command to do this? DO I need to create a file before hand for the command to recognize the group names?
0
In the query below, i am try to import AD dist groups(both distribution and security groups)  from a CSV, and would like to return the user name and email address and indicate whether the groups is regular distribution or a security group.  Is it possible to get these results?

Get-ADGroupMember "dist.grp" | select samaccountname | %{Get-ADUser $_.samaccountname -Properties mail} | %{write-output "$($_.samaccountname) `t`t  $($_.mail)"}

TIA!
1
Using the below Powershell command, I am trying to change the drive but it fails with error: "drive is in used"
is there a way to force it to change as we can change in the Windows Dick Management Console
Get-Partition -DiskNumber 1 | Set-Partition -NewDriveLetter G

Open in new window


Thanks.... ;)
0
Discover the Answer to Productive IT
Discover the Answer to Productive IT

Discover app within WatchGuard's Wi-Fi Cloud helps you optimize W-Fi user experience with the most complete set of visibility, troubleshooting, and network health features. Quickly pinpointing network problems will lead to more happy users and most importantly, productive IT.

I'm running Hyper-v in a 2012 R2 cluster.  (Note: this is NOT SCVMM)
I'm trying to get a list of all the VMs currently running on the Host I'm logged into and their respective possible owners. i.e. which cluster nodes they could potentially migrate to.  The reason is that I THEN want to set those VMs to only run on that particular host for patching purposes.  Once done I'll want to reverse it so the VMs can once again migrate when needed.  Here is the code and attendant error message.  I'm hoping someone can assist me with achieving my goal or at least point me in the right direction.


$VMs = get-vm
foreach ($vm in $vms)
{
	get-clusterresource -vmid "$VM.vmid" | get-clusterownernode
}

Open in new window


The error I am getting is:

Get-ClusterResource : Cannot bind parameter 'VMId'. Cannot convert value "Microsoft.HyperV.PowerShell.VirtualMachine.vmid" to type "System.Guid". Error: "Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)."
At line:1 char:50
+ foreach ($vm in $vms) {get-clusterresource -vmid "$vm.vmid" | get-clusterownerno ...
+                                                  ~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-ClusterResource], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.FailoverClusters.PowerShell.GetResourceCommand
0
I have a couple of systems here at my work that got the windows store and other apps (calculator) uninstalled.  I have been trying to run the powershell commands I have found in order to reinstall those but nothing seems to be working.  Other than reinstall the OS is there anything else I could try before doing something more destructive?  thanks.
0
Hi  

We have exchange 2007 and we migrated all the mailboxes to 0365 and now we are going to decomission the exchange server and there are 900 old mail boxes left on this server that is not required  .

Please let me know the easy way of deleting all the mail boxes
Is there any poweshell command to do this task.Or do i need to manually  go to Exchnage management console- Mailbox and highlight mailbox and remove?  and change the mailbox retention period?

Any help much appreciated.

Thanks
0
I want to pin a Windows 10 application to the taskbar using Powershell.   I think syspin.exe will work to do this.   However, my problem is that the application is installed via an .appx and I can not find the location of the file to pin to the taskbar or the actual name to use as a parameter to syspin..
0
Hi,

I'm looking for a script that will loop through thousands of directories.  If there are less than 10 subdirectories in a folder, it will move that parent folder with the subfolders to another location.

Example:  under this share, \\network_share\test, is the structure below:
\\network_share\test\folder1\test\subfolder1, subfolder2, subfolder3, subfolder4, subfolder5, subfolder6, subfolder7, subfolder8, subfolder9
\\network_share\test\folder2\test\subfolder1, subfolder2,subfolder3, subfolder4, subfolder5, subfolder6, subfolder7
\\network_share\test\folder3\test\subfolder1, subfolder2, subfolder3, subfolder4, subfolder5, subfolder6, subfolder7, subfolder8, subfolder9, subfolder10

Since folder1 and folder2 have less than 10 subfolders, folder1 and folder2 along with their subfolders will be moved to \\network_share\test2.  Note: it will need to search down two subdirectories to get the count.

Thank you
0
I am new to Automation testing, i have to write automation scripts for File Router service, this service has a source/input folder and a destination folder, based on the file name, extension the file(s) will be moved to respective destination.

This is a windows service. based on the configuration this router will move the files

What will be better technology stack for this requirement, when i run the tests , they should be able to copy, verify whether it is copied or not
0
I've just done an upgrade from Exchange2013 CU19 to Exchange2016 CU10. At the moment, the two co-exist and mail flow/public folders, most stuff I can see is working as expected, without issues. Since I've migrated everything(mailboxes, PF, Arbitration MB etc) I want to get to the state where I can decommision the old Exchange2013. I checked message headers and everything is Sending/Receiving from Exchange 2016, 2013 Exchange isnt acting as a Proxy. Today I took first step towards the decommission, I turned off Exchange services on Exchange 2013 box followed by disabling the receive/send connectors for this Exchange 2013 box. Disabling services didnt do it but a little after disabling the send/receive connectors the Exchange 2013 box blue screened.

I've couple of questions - :

-Whats the proper way to decommission the Exchange 2013. Most guides tell me to simply uninstall Exchange 2013 from Add/remove programs and I'm wary of doing that just yet, especially if I've no way of knowing if the mail stuff is now completely coming from Exchange 2013. OfflineAddressbook is still pointing to Exchange 2013 (Default Offline Address List (Ex2013))

- I still see the Exchange 2013 edb is big, isnt the move suppose to migrate all the mailboxes and clean out that Exchange 2013 edb?

- I see some errors for the Public folder, how can I check if its a legacy PF mailbox or modern. Before 2013 we had Exchange 2010 where the PF came from.

-Following errors also dont make sense - …
0
I have a VB script that I want to adapt to remove a desktop link from the currently logged on user's Desktop.  It isn't working and I get no error messages - no nothing.

On Error Resume Next
Dim FSO, WSHShell, Regkey, Username, strFolder, UserPath, objShell

Set WSHShell = CreateObject("WScript.Shell")
RegKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\"
Username = WSHShell.RegRead(RegKey & "LastLoggedOnSAMUser")
Username = Mid(Username,7) 

Set FSO = CreateObject("Scripting.FileSystemObject")
UserPath = "C:\Users\" & Username 
strFile = "C:\Users\" & Username & "\Desktop\CMS Supervisor*.lnk}" 
if FSO.FileExists(strFile) = True then  FSO.DeleteFile DesktopPath & "\CMS Supervisor*.lnk"

Open in new window

1
Hello All,

I need a help with combining the results of the below three commands in to multiple sheets on one excel workbook.

Invoke-Command -ScriptBlock {Get-Mailbox -resultsize unlimited | select-object -property DisplayName , Alias, , EmailAddresses, HiddenFromAddressListsEnabled, PrimarySmtpAddress,IsInactiveMailbox, RecipientType} | export-csv C:\temp\mailbox.csv

Invoke-Command -ScriptBlock {Get-Mailbox -resultsize unlimited | Get-MailboxPermission | Where {(!$_.isinherited) -and ($_.user.SecurityIdentifier -ne "S-1-5-10") -and  ($_.accessrights -contains "fullaccess")  } | Select Identity,User } | export-csv C:\temp\access.csv


$groupmembers = foreach($i in Get-DistributionGroup)
{
Get-distributiongroupmember $i | Select Name, @{n='Member';e={$i.Name}}
}

$groupmembers | Export-Csv C:\temp\groupmembrs.csv -Notypeinformation

Thanks
Krish
0
OWASP Proactive Controls
LVL 12
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

Is it any example to write a shutdown script such that it will randomly shutdown the Window after 0:00, close the Outlook if it is opened and copy the ost file to the server ?

Thx
0
I am having trouble with my batch files .bat.  The folder names have spaces in them and the commands do not like it.

Powershell also has this problem.

There are many files to process so renaming them manually is not an option.

How can I get around this?
1
Creating new dynamic distribution groups in office 365.  Here is an example of the command that used to work with on-prem:  New-DynamicDistributionGroup -Name "All IT" -RecipientFilter {(RecipientType -eq 'UserMailbox') -and (Title -like '*Tech*')    

BUT you can no longer do leading wildcards in o365.  I tried to use  (Title -contains 'Tech*'), but I receive an error that -contains is not a valid operator.   Any ideas of what I could use?  I know -contains is an operator, but obviously I am doing something wrong.
0
hi guys

I have setup script .bat to trigger email with lockout account.

it works fine but could you help me what I have to add to actually see the name of the user  ?

REM SEND AN EMAIL SAYING EVENTID 4740 ACCOUNT LOCKOUT HAS OCCURRED
powershell -ExecutionPolicy ByPass -Command Send-MailMessage ^
    -SmtpServer xxxxx.mail.protection.outlook.com ^
    -To xxx@xxxxxx ^
    -From admin@xxxx ^
    -Subject Mother-EVENTID-4740-ACCOUNT-LOCKOUT-HAS-OCCURRED ^
    -Body Mother-EVENTID-4740-ACCOUNT-LOCKOUT-HAS-OCCURRED



thank you
1
Hi

We need to regularly create system restore points on our user computers via command line.

The idea is to automate this process without deploying any 3rd party tools.

Step 1. Check if system restore is enabled on the computer. If it is not, enable it.
Step 2. Check the storage size allocated for system restore. If it is less than 6 GB, configure to to be 6 GB.
Step 3. Create a system restore point with a generic label e.g. "maintenance".
Step 4. Check if the system restore point got created or not by listing existing system restore points and comparing the labels with the generic label used in step3.


So this is the general idea of the script we want to create and I think I can do the other bits myself except for creating system restore point via command line.

I have tried the WMIC method, powershell method and everything else I can find on blogs and google search.

Most commands I run return the "execution successful" message.

But when I check manually if the system restore point got created or not by opening system restore GUI, I don't see the restore point created.

For the life of me I can't figure out what's going on.

So pls help !
0
how do I save sent Items "Emails" in Shared Mailbox Sent Items folder only and not being copied to the user who is sending as is this possible?
i used a powershell cmdlet in the Exchange Management Shell to allow access for two users to send Emails with this shared mailbox separately and  each user can see the sent Emails from the other user.
 but in this case the sent Email are being copied to the send items of the user who send the "email as"

set-mailbox **Email address** -MessageCopyForSendOnBehalfEnabled:$true -MessageCopyForSentAsEnabled:$true

is there a workaround solution so the "send as" items are only in the shared mailbox "sent items"  only whitout them being copied to the "sent item" from the user who is sending them as.

i am trying to do this on a Exchange 2016

thanks in advance
1

Powershell

18K

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.