Solved

How to use GC command in PowerShell?

Posted on 2013-12-06
4
628 Views
Last Modified: 2013-12-06
How can I import a TXT file using GC?  Right now I have the following code, but I want to pull it from a txt file that does not have a header... it's just a list of UPNs.  Would I change the first line to "$Users = GC .\UPNs.txt"?  If so, since there is no header, $_.userPrincipalName will no longer work and I wouldn't know what to change it to.

I tried this as a test, but it's not working...
$Users= GC .\zTest.txt
$Users | foreach-object {
write-host $_
}

Thanks in advance!


# Import list of user UPNs
$Users = Import-Csv .\UPNs.csv

# Loop thru users
$Users | ForEach-Object {

Get-MsolUser -UserPrincipalName $_.userPrincipalName
Set-MsolUser -UserPrincipalName $_.userPrincipalName -UsageLocation $UsageLocation

if ($DLtype -eq "1") 
{write-host "Activating User"

Set-MsolUserLicense -UserPrincipalName $_.userPrincipalName -AddLicenses $AccountSkuId -LicenseOptions $options
}

Open in new window

0
Comment
Question by:bpl5000
  • 2
  • 2
4 Comments
 
LVL 5

Author Comment

by:bpl5000
ID: 39701891
Oh, looks like the small test I had is working.  So I guess I would just change $_.userPrincipalName to $_?
0
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
ID: 39701896
Yes, that's correct.
Also, if you had a .CSV without headers, you could manually specify them with the -header parameter of Import-CSV.
0
 
LVL 5

Author Comment

by:bpl5000
ID: 39701935
Oh, okay... so I would use "$Users = Import-Csv -headers .\UPNs.csv"?
0
 
LVL 39

Expert Comment

by:footech
ID: 39701958
You could use
$Users = Import-Csv -header "userprincipalname" .\UPNs.csv

Open in new window

It's just an option that I thought I'd mention, could be useful if there're other properties you might want to add to the objects.
But outside of that, with just a single column I would go the GC route.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A procedure for exporting installed hotfix details of remote computers using powershell
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now