Link to home
Start Free TrialLog in
Avatar of bpl5000
bpl5000

asked on

How to use GC command in PowerShell?

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

Avatar of bpl5000
bpl5000

ASKER

Oh, looks like the small test I had is working.  So I guess I would just change $_.userPrincipalName to $_?
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bpl5000

ASKER

Oh, okay... so I would use "$Users = Import-Csv -headers .\UPNs.csv"?
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.