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!
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
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oh, okay... so I would use "$Users = Import-Csv -headers .\UPNs.csv"?
You could use
But outside of that, with just a single column I would go the GC route.
$Users = Import-Csv -header "userprincipalname" .\UPNs.csv
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.
ASKER