Solved

How to use GC command in PowerShell?

Posted on 2013-12-06
4
633 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Set OWA language and time zone in Exchange for individuals, all users or per database.
A procedure for exporting installed hotfix details of remote computers using powershell
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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