I'm having a difficult time getting this to work. This script will ask for the location for the GAM.exe, and then the location of a CSV. Then it should run a foreach loop executing GAM with the said variables to add bulk users to google docs. An example of working code:
$Gamfile 'create user' crashtestdummy 'firstname' "Crash" 'lastname' "Test Dummy" 'password' "BuckleUp"
The above works, and will add the user [email protected]
The issue I am having is in the foreach loop. I just get:
Unexpected token '$User'
Unexpected token ' 'password' '
Thanks in advance!
Function Get-GamFile($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "GAM File (gam.exe)| gam.exe"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
} #end function Get-GamFile
$GamFile = Get-GamFile
Function Get-CSV($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "CSV (*.csv)| *.csv"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
} #end function Get-CSV
$GetCSV = Get-CSV
$CSV = Import-Csv $GetCSV
Write-Host $GamFile
Write-Host $GetCSV
Function AddUsers {
foreach ($User in $CSV) {
Write-Host Making User $User.firstname $user.lastname
$GamFile 'create user' $User.firstname 'firstname' $User.firstname 'lastname' $User.lastname 'password' $User.Password
}
}
AddUsers
#$Gamfile 'create user' crashtestdummy 'firstname' "Crash" 'lastname' "Test Dummy" 'password' "BuckleUp"
"'$GamFile' create user '$($User.firstname)' firstname '$($User.firstname)' lastname '$($User.lastname)' password '$($User.Password)'"does that look ok? If it does should just be able to put an&infront of it to make it execute. Any of your last names have spaces maybe? Just spit balling.'create user'is being interpeted as one element when it really is two. Remove the quotes.& $GamFile create user $User.firstname ....