?
Solved

How to use GC command in PowerShell?

Posted on 2013-12-06
4
Medium Priority
?
760 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 40

Accepted Solution

by:
footech earned 2000 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 40

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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

A brief introduction to what I consider to be the best editor for PowerShell.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

764 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