Powershell

15K

Solutions

55

Articles & Videos

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

Hi.
I need a help, I have two files, file1.csv with three columns (name, surname, profile) and file2.csv with the same columns (name, surname, profile), I am trying to compare if file1.csv is equal to file2 .csv. The data of each file are not in the same order:

File1.csv
Name      surname      profile
Mary        McCoy         Receptionist
Peter       Robert         Auditor
Susan      Parker         Logistics
Richard    Sarandon    Administrator

File2.csv
Name      surname      profile
Richard    Sarandon    Administrator
Mary        McCoy        Assistant
Susan      Parker        Logistics
Peter        Robert       Auditor
Sergio      Alaves       Systems

I would like to be able to compare each line of the file1.csv with all the lines of the file 2.csv and verify if they are the same, to indicate me in which column there are differences. With this scripts does not work for me:

Compare-Object -ReferenceObject $ (Get-Content C:\ file1.csv) -DifferenceObject $ (Get-Content C:\ file2.csv) -IncludeEqual

Or

diff (cat -Path "C:\file1.csv") (cat -Path "C:\file2.csv") -IncludeEqual | Export-Csv C:\Compare.csv -NTI

Could they help me?
0
On Demand Webinar - Networking for the Cloud Era
LVL 8
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Hi Experts,

I want to get the remote computer hostname from powerhshell as when i use $env:COMPUTERNAME I am getting my local machine hostname. Below is my script to get the list of installed software from the remote machine and i have a list of hostnames/IP in a txt file. Why am i asking for this is sometimes I use IP to get this list of software installed , so i need the remote hostname as well. As you can see below in my script, i need the hostname to be in the for-each object section below to replace the $env:COMPUTERNAME

 
foreach($pc in $computers){$properties = "name", "vendor","version" ,"installdate"
Get-ChildItem HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\*\Products   | ForEach-Object {
    $root  = $_.PsPath
    $_.GetSubKeyNames() | ForEach-Object {
        try {
            $RegKeyPath = (Join-Path -Path (Join-Path -Path $root -ChildPath $_) -ChildPath InstallProperties)
            $obj = Get-ItemProperty -Path $RegKeyPath  -ErrorAction Stop
            if ($obj.UninstallString) {
                [PSCustomObject]@{
                    Path = $RegKeyPath;
                    Name = $obj.DisplayName ;
                    Vendor = $obj.Publisher  ; 
                    Version = $obj.DisplayVersion ;
                    InstallDate = $obj.InstallDate ; 

                   
                } | where vendor -like 'microsoft*'
            }  
        } catch {
        } 
    } 
} | ForEach-Object {
    '{0},{1},{2},{3},{4}' -f 

Open in new window

0
Hey

I need to write a date to registry

Next run:

If the date is more than 24 hour from current date - do something.

Thx in advance
0
All our users' home folders are located on the file sevrer, in E:\Folder\%USERNAME%\.  Inside this is a folder called Flags.  What I want is a PowerShell script that created an empty file E:\Folder\%USERNAME%\Flags\Pin2016.flg - recursively for every user E:\Folder\%USERNAME%

It's PowerShell Version 4 on Windows Server 2008 R2

Also it would be good to have the result for each file creation dumped to a log file, because there might be one or two Flags folders in there that has weird permissions.

Thank you.
0
Since the default policy tag will delete anything older than 2 years ...

I would like to know if any items (not in the recoverable items folder) exist that are older than 2 years old.

Other than Get-MailboxFolderStatistics (as this command is extremely slow), what is available?
0
I am unable to find a method in PowerShell to do this.  

Does anybody know how to report on the searches (not the holds - that I can do) within an eDiscovery case, within the new Security & Compliance Center?

Thank you.
1
Hello,

I want to add an active directory account to the local esxi servers through powercli.
The user has to have shell access and should be in the local group "read only"
Im running esxi 6.0

I have tried the following but i cant get it working
New-VMHostAccount -UserAccount user@domain -GrantShellAccess $true

it keeps asking for a password which i dont want to give as it is a domain account.

Thanks
0
Experts,
I'm faced with the following challenge - I need to reconfigure existing ADFS server to point to WID instead of a SQL Server that's going away.
The following link tells me that I have to export and export an existing relying party from SQL using PowerShell and import it to a WID database.

https://jorgequestforknowledge.wordpress.com/2015/02/24/migrating-adfs-databases-from-sql-to-wid/

What I'm lacking is an instructions on how to create a WID and point my ADFS there.
0
hello everyone, Happy to share my 2nd article published on Expert Exchange, there I am sharing a Powershell Tip on converting StringData into a Hash Table using "ConvertFrom-StringData" Powershell CMD, your Feedback, and Suggestions are welcome, please give me your endorsement to help me level up.

https://www.experts-exchange.com/articles/29939/Powershell-Tips-Convert-String-Data-into-a-hash-table-ConvertFrom-StringData.html
2
 

Expert Comment

by:Justin Carey
Have you created a course?
0
 
LVL 4

Author Comment

by:Sunil Chauhan
not yet Justin.
0
Hi,
I am migrating a bunch of users over to Ex2016 from Ex2010.
Many of those users on 2010 had quotas that I manually set.
The new Ex2016 machine has much more space so I am setting a high quota as a default (not terribly high but much more then they had).

Is there a simple Powershell script or individual command I can run that would set a users mailbox quota in a given DB to the default quota?

Thanks,
Nacht
0
Free Tool: SSL Checker
LVL 8
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Need help with combining these script together if it can be done, any help is appreciated.

Also want to mention, this will be for use in a large environment, 20k or so, and I plan on having as a scheduled task.  Not sure if this is an efficient script or will be too intrusive.  Input is welcome.

The first script goes through all mailboxes in ExO, and if it's a member of a group "MobileUsers", it enables activesync and owafordevices, for everything else it disables these features.

Import-Module MSOnline
$mailboxes = Get-CASMailbox -resultSize unlimited
$asusers = Get-DistributionGroupMember -Identity 'MobileUsers'

$asguids = @()
foreach ($user in $asusers) {
    $asguids += $user.GUID
}

foreach ($mailbox in $mailboxes) {
    if ($asguids -contains $mailbox.GUID ) {           
        if ($mailbox.ActiveSyncEnabled -ne $true) {     
            $mailbox | Set-CASMailbox -ActiveSyncEnabled $true –OWAforDevicesEnabled $True
        }
    }
    else {
        if ($mailbox.ActiveSyncEnabled -ne $false) {   
            $mailbox | Set-CASMailbox -ActiveSyncEnabled $false –OWAforDevicesEnabled $false
        }
    }
}

Open in new window


The second script (which can be based off of the same "MobileUsers" group, I have to set an license SKU in ExO for intune.  The header from the input file is:   "UPN","usagelocation","SKU"#

$users = import-csv .\intune.csv -delimiter “,”
foreach ($user in $users)
{
$upn=$user.UPN
$usagelocation=$user.usagelocation
$SKU=$user.SKU
Set-MsolUser -UserPrincipalName $upn -UsageLocation $usagelocation
Set-MsolUserLicense -UserPrincipalName $upn -AddLicenses $SKU
}

Open in new window

0
I use my own laptop at my customer site.  I have a network logon, but because my laptop is not a member of the domain (and I don't log on to the network) I am prompted for my credentials whenever I use some network resource (IIS, fileshares, Exchange).

At times, this becomes annoying.  The prompts for my credentials may popup behind other windows and I don't see them, etc.

Long story short, I'd like to have a PS that will map a drive (and then unmap it) for the servers with shares I most use to do this that I can schedule to run regularly from the scheduler so that the prompting is done in the background and I can just start using the shares (about a half dozen) I regularly use.

I've found commands for mapping and unmapping drives, but I don't see a syntax with a credential parameter, which won't work for this situation.  Can anyone provide an example or pointer to one that would workout?
0
I need a powershell script that can force logoff multiple users on multiple computers.

Lets say i have a csv file with 2 columns(servername, user)
Example: server= server 1, users=sa.user, sa.user1
server=server2, users=sa.user, sa.user1, sa.user2

Note: Don't need to to know how to get the list of server/s and user/s because I already have a separate script for that.
0
So I've inherited a somewhat small environment where I manage Active Directory but the former DBA apparently had all these scripts doing tons of things against AD and everything else in the environment.  
Problem is one of the things that's happening is we have students and alumni in this small campus. Well the script, which I believe is the one below, is moving people to the Alumni OU even though they are a student.
I can ascertain that some of this is partially SQL query but I was hoping someone with a bit of experience could help translate what is going on here and what criteria/reason is moving someone from one OU to another OU or vice versa.

From the script, I see that one important variable appears to be:
$StudentsThatShouldMove = Fill-Dataset $IntegrationConnString $Sql_StudentsThatShouldMove
   
Does that mean I have to look to the SQL side to see what's going on?
#. \\scorch01.VelCollegenet.edu\C$\Users\Public\Documents\Scripts\_CreateAcctsAndDistGroupsV4.ps1
# .\_CreateAcctsAndDistGroupsV4.ps1
#########0#########0#########0#########0#########0#########0#########0#########0
#
# # Description: Move students and alumni accounts to the correct OUs
#
# History:
#	???????? EWM Initial Creation
#   20111213 EWM Sql Server Agent Job 
#				 [Active Directory NEW students daily].[Shell Game (move stuff around where it goes)]
#				 Occurs daily at 9:00:00 PM with no end date
#
#########0#########0#########0#########0#########0#########0#########0#########0

Open in new window

0
Need assistance with a powershell/vbs script to do the following:

We need to monitor the following path \\SERVER\folder.  When a new folder is created that's an indication of a failure of a background process. Once the new folder is detected we need to send an email alert. We are looking to received the alert only when newly created folders (now-15 minutes or so)or just the last date (compare with the most recent folder date creation) if newer then sent alert.

We do have SCOM and so we might run the script from there otherwise from the server itself (windows server)

Can you someone please assist
0
I trying to run a script to clean up a server and I'm getting the attached warning.   How to I get it to run?
I'm not that familiar with PowerShell so please give step by step instructions.  I'd appreciate it.
powershell.jpg
0
I would like to be able to run commands from a windows machine (using some tool ) and run commands in linux machine and retrieve results of those commands.
I have a powershell code which connects to remote windows systems, I want to be able to retrieve system info from linux machines as well. Is this possible?

This is in relation to this question:
 powershell to linux.
0
Hi Experts,

Im new to powershell. I want to filter only to show Microsoft products installed in a machine and save it to a file. Below is the script Im writing. Is there anywhere i can fit where-object in it or any other suggestions.

Get-WmiObject -Class win32_Product -ComputerName $pc -Property name,vendor,version,installdate | ForEach-Object {
    '{0},{1},{2},{3},{4}' -f $env:COMPUTERNAME,$_.Name,$_.Vendor,$_.Version,$_.InstallDate
} | out-file C:\"$env:COMPUTERNAME"_SW01.txt

Open in new window

0
Hi,
I am migrating mailboxes over from Exchange 2010 to Exchange 2016.
Can someone tell me a powershell/Exchange Mgt shell command that will tell me which of my current users  have quotas over 1 GB?
I don't want to move my users from 2010-2016 and have them move into a smaller DB.

Thanks,
nacht
0
Free Tool: Path Explorer
LVL 8
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

This is what I came up with in powershell but it doesn't list the actual users, or exclude people with just 'Domain Users'

Get-ADUser -Filter {Enabled -eq $false} –Properties MemberOf | Select-Object -ExpandProperty MemberOf | Get-ADGroup -Properties name | Select-Object DistinguishedName,name,GroupCategory

Open in new window

1
Hello Experts,
In continuation to : https://www.experts-exchange.com/questions/29014655/Powershell-help-for-creating-accounts.html
I have a further enhancement request,
I have 2 Columns in SQL
ADGroup & O365Group

These columns contains values, which are separated by comma (,) these are existing groups in AD & O365
I want them to be integrated into the script so that when the new user is created he is added to the respective groups in both the places.

Thanks in advance.
A
0
Hi,

Is there a way that I can add one EXTERNAL contact into a SHARED mailbox? In Office365 Exchange. Have a shared mailbox and want to add ONE user to the shared mailbox.

Thanks in advance

John
0
Install a .exe file (MS Patch) using PSEXEC as Admin on multiple servers

Any help is appreciated.
0
I have a task attached to an event the runs a powershell script to send an email when ever an event is logged
For actions I have start a program, entered powershell.exe with and path to script in arguments
It all works well except when ever the task runs I get an email with the event details and a 2nd email like below
can anyone tell me how to prevent the 2nd email>>


SubjectUserSid      S-1-5-21-2560493146-1397779600-2150419373-2289
SubjectUserName      service account name
SubjectDomainName      AD
SubjectLogonId      0x585dd7
ObjectServer      Security
ObjectType      Key
ObjectName      \REGISTRY\MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WSMAN
HandleId      0x304
TransactionId      {00000000-0000-0000-0000-000000000000}
AccessList      %%1538 %%4432 %%4435 %%4436
AccessReason      -
AccessMask      0x20019
PrivilegeList      -
RestrictedSidCount      0
ProcessId      0xc9c
ProcessName      C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
0
Hi,  I got some issues with my Powershell v2.0 code. I am trying to scan after archive files, create folder on fileserver with logged in username if it's not yet created and then robocopy the archive files found.
However I am receiving ERROR 123 (0x0000007B) Accessing Source Directory C:\source\Test.pst\
The filename, directory name, or volume label syntax is incorrect.


The filename and directory name is correct what I can see. And doing just the copy command instead of robocopy works.

I would appreciate if someone could help me out. Quite new to Powershell.

#Grab root folders, exclude systemfolders and program files folders
        $folders=get-childitem c:\ | where-object{$_.mode -like "d-*" -AND $_.name -notlike "windows" -AND $_.name -notlike "drivers" -AND $_.name -notlike "program files*"}
       
        #Search thru each root folder for PST-files
        $allfiles=$folders | ForEach-Object{get-childitem -Path $_.fullname -include "*.pst" -recurse -ErrorAction silentlycontinue};


$env:username
$foldertocreate="\\fileshare\users$\$env:username"
   
   
#if((Test-Path -Path $foldertocreate -PathType Container)) {write-host "Folder already created, start copying"}
               # else {write-host "Creating folder" | New-Item -ItemType Directory -Force -Path $foldertocreate}          

robocopy $allfiles $foldertocreate /COPY:DAT
0

Powershell

15K

Solutions

55

Articles & Videos

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.