I am trying to simultaneously update some users in my AD, but not being able to generate the script correctly. I am working with .csv and I get errors!
script
Import-Csv -Path C:\Temp\userteste3.csv | foreach-Object {Set-ADUser -Identity $_.SamAccountName -Add #{-telephoneNumber $_.telephoneNumber;-OtherPhone $_.OtherPhone;ipPhone $_.ipPhone}}
csv
error
No linha:1 caractere:105
+ ... oreach-Object {Set-ADUser -Identity $_.SamAccountName -Add #{-telepho ...
+ ~
O literal de hash estava incompleto.
No linha:1 caractere:186
+ ... ber $_.telephoneNumber;-OtherPhone $_.OtherPhone;ipPhone $_.ipPhone}}
+ ~
Token '}' inesperado na expressão ou instrução.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : IncompleteHashLiteral
Related
I've been trying to configure a bulk of Msol users via .csv file with non-English values.
First tried importing the values I want to set from the .csv file and didn't get any error and the user I tried to update didn't get updated.
Then, I tried setting the account by writing the non-English values in Powershell and got an error that mentions my non-English values.
Is there any special syntax for non-English values? something in my code were I tried to import the values from the file is the problem?
Thanks.
The code:
Import-Csv C:\Documents\Changes.csv | Get-MsolUser | Where {$_.UserPrincipalName -eq $_.userprincipalname} | Set-MsolUser -Department $-.class -Office $_.school -Title $_.title
The Error:
Set-MsolUser : A positional parameter cannot be found that accepts argument '×לי××'. At C:\UserChanges1.ps1:5 char:143 + ... ipalname} | Set-MsolUser -Department "מורה" -Office "×לי×× ×¡ ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [Set-MsolUser], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Online.Administration.Automation.SetUse
I have a script that is generating multiple CSV files with the time stamp and group name as part of the file name. Right now the script outputs the CSV files into the directory the script is run from.
I would like to have the CSV files output to a sub directory. Whenever I include a path in my Export-Csv command, I get an error.
Here is what I have:
#This array lists the names of the AD groups that the script will query to enumerate membership.
$aGroups = #("Group1", "Group2")
#Create a log file to verify that the script did not have any errors.
$strTimestamp = [string](Get-Date -Format "yyyy-MM-dd_hh-mm")
Start-Transcript ADGroupScriptLog-$strTimestamp.txt
Write "Enumerating group membership. This may take some time..."
#Loop through each group in the array and output to CSV each member in the group.
foreach ($group in $aGroups) {
Get-QADGroupMember $group -Indirect -Type 'user' -ShowProgress -ProgressThreshold 0 -Sizelimit '0' |
Select-Object Name, SAMAccountName, givenName, sn, title, manager, Description |
Export-Csv ($strTimestamp + "_" + $group + ".csv") -NoType
}
Write "Execution Complete"
Get-Date -format s
Stop-Transcript
I have tried:
Export-Csv \\Server\Share\File.csv ($strTimestamp + "_" + $group + ".csv") -NoType
**********************
Windows PowerShell transcript start
Start time: 20180207113151
Username :
Machine : (Microsoft Windows NT 6.1.7601 Service Pack 1)
**********************
Transcript started, output file is OneSourceUsers-2018-02-07_11-31.txt Enumerating group membership. This may take some time...
Export-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value
"2018-02-07_11-31_OneSrce_BI_Browser.csv" to type "System.Char". Error:
"String must be exactly one character long."
At E:\OneSource\get_OneSourceUsers.ps1:19 char:215
+ ... neSource\Output($strTimestamp + "_" + $group + ".csv") -NoType
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ExportCsvCommand
Export-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value
"2018-02-07_11-31_OneSrce_BI_Admin.csv" to type "System.Char". Error:
"String must be exactly one character long."
At E:\OneSource\get_OneSourceUsers.ps1:19 char:215
+ ... neSource\Output($strTimestamp + "_" + $group + ".csv") -NoType
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ExportCsvCommand
Export-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value
"2018-02-07_11-31_OneSource MSSQL POC.csv" to type "System.Char".
Error: "String must be exactly one character long."
At E:\OneSource\get_OneSourceUsers.ps1:19 char:215
+ ... neSource\Output($strTimestamp + "_" + $group + ".csv") -NoType
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ExportCsvCommand
Export-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value
"2018-02-07_11-31_One Source Reporting Alert.csv" to type "System.Char".
Error: "String must be exactly one character long."
At E:\OneSource\get_OneSourceUsers.ps1:19 char:215
+ ... neSource\Output($strTimestamp + "_" + $group + ".csv") -NoType
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ExportCsvCommand
Export-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value
"2018-02-07_11-31_One Source Loads.csv" to type "System.Char". Error:
"String must be exactly one character long."
At E:\OneSource\get_OneSourceUsers.ps1:19 char:215
+ ... neSource\Output($strTimestamp + "_" + $group + ".csv") -NoType
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ExportCsvCommand
Export-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value
"2018-02-07_11-31_One Sales Team.csv" to type "System.Char". Error:
"String must be exactly one character long."
At E:\OneSource\get_OneSourceUsers.ps1:19 char:215
+ ... neSource\Output($strTimestamp + "_" + $group + ".csv") -NoType
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ExportCsvCommand
Export-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value
"2018-02-07_11-31_OneSrce_BI_Contributor.csv" to type "System.Char".
Error: "String must be exactly one character long."
At E:\OneSource\get_OneSourceUsers.ps1:19 char:215
+ ... neSource\Output($strTimestamp + "_" + $group + ".csv") -NoType
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Export-Csv], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ExportCsvCommand
Execution Complete 2018-02-07T11:31:51
**********************
Windows PowerShell transcript end
End time: 20180207113151
**********************
When you run something like
... | Export-Csv \\server\share($strTimestamp + "_" + $group + ".csv") -NoType
PowerShell sees \\server\share as one argument, and ("something" + ".csv") as another argument (due to the grouping expression). The second positional parameter is passed to the parameter -Delimiter, which expects a single character. Hence the error you observed.
To create a path string from several variables just use a string with nested variables:
... | Export-Csv "\\server\share\${strTimestamp}_${group}.csv" -NoType
I am new-ish to PowerShell and am having a problem. I am trying to get a users password last set date and time from a domain and then add 90 days to it. So far I have:
$PLS_date = (get-aduser randomuser -Properties PasswordLastSet | Select passwordlastset) | out-string
"Password will expire on $((get-date).adddays(90)($PLS_date))"
However this spits out an error:
+ "Password will expire on $((get-date).adddays(90)($PLS_date))"
+ ~
Unexpected token '(' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
I have search around to try and find what i am doing wrong but cannot figure it out.
Help!
Try it this way:
$pwdLastSet = Get-ADUser username -Properties PasswordLastSet | Select-Object -ExpandProperty PasswordLastSet
if ( $pwdLastSet ) {
"Password will expire on: {0}" -f $pwdLastSet.AddDays(90)
}
Firstly,
I am very new to powershell. Everytime I think i get the logic i go WTF.. If this was bash it would be so easy etc..
what am I trying to do exactly ...
Get all computers from AD that Meet the Xiopwb* criteria. Once i have the list I need to change the permissions on the \\Xiopwb20\Nsiwebroot Directory to ONLY INCLUDE Domain Administrators and A Security group "webadmins"
My Logic:
Get all computers from AD that meet Xio*PWB*
Take just the NAME of objects in that list
for ever "name" in that list do Get-ACL \\Name from list\Nsiwebroot
remove *
add user / group.
What I have:
PS C:\Windows\system32> Get-ADComputer -filter * | Where-Object {$_.Name -like "xiopwb*"} | Select Name | ForEach-Object { Get-Acl \\$_.Name\nsiwebroot}
all up to the "ForEach" works... I get just the names of the PC's that I need etc..
Simple as possible I don't need a 100 line script.
Thanks
** update **
it is double \ its just not showing it... no idea why
Looks like it is doing what I want to a degree. However its spitting out the format funky. #{Name=XIOPWB09}
PS C:\Windows\system32> Get-ADComputer -filter * | Where-Object {$_.Name -like "xiopwb*"} | Select Name | ForEach-Object {get-acl "\\$_\D$\nsiwebroot"}
get-acl : Cannot find path '\#{Name=XIOPWB09}\D$\nsiwebroot' because it does not exist.
At line:1 char:99
+ ... opwb*"} | Select Name | ForEach-Object {get-acl "\$_\D$\nsiwebroot"}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-Acl], ItemNotFoundException
+ FullyQualifiedErrorId : GetAcl_PathNotFound_Exception,Microsoft.PowerShell.Commands.GetAclCommand
get-acl : Cannot find path '\#{Name=XIOPWB06}\D$\nsiwebroot' because it does not exist.
At line:1 char:99
+ ... opwb*"} | Select Name | ForEach-Object {get-acl "\$_\D$\nsiwebroot"}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-Acl], ItemNotFoundException
+ FullyQualifiedErrorId : GetAcl_PathNotFound_Exception,Microsoft.PowerShell.Commands.GetAclCommand
"Select Name" returns an Object with Table Header Name. "Select -ExpandProperty Name" is What needed here, which will convert it o String.
Regards,
kvprasoon
I wrote a small script to grab event log entries from a remote machine and write it to a .csv file. The script works when targeting a single machine, but when I try to implement a for loop and loop it over all machines in Active Directory, I get this error:
Method invocation failed because [Microsoft.ActiveDirectory.Management.ADComputer]
does not contain a method named 'op_Addition'.
At Y:\srp.ps1:7 char:143
+ ... | Export-Csv $($computer + ".csv")
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Export-Csv : Cannot validate argument on parameter 'Path'. The argument is null or empty.
Provide an argument that is not null or empty, and then try the command again.
At Y:\srp.ps1:7 char:141
+ ... 0 | Export-Csv $($computer + ".csv")
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Export-Csv],
ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,
Microsoft.PowerShell.Commands.ExportCsvCommand
The error indicates there's a problem with the Export-Csv command, but running the command by itself creates the log files needed. Here is the full script, for reference:
# Gets SRP event log entries from remote machine and writes them to a .csv file
# of the same name.
Write-Output "Running..."
$computers = Get-ADComputer -filter {(Name -like "PC*") -or (Name -like "LT*")}
foreach ($computer in $computers) {
Get-EventLog -LogName Application -Source Microsoft-Windows-SoftwareRestrictionPolicies
-ComputerName $computer -Newest 10 | Export-Csv $($computer + ".csv")
} #end foreach
Write-Host "Done."
Any ideas as to why this error appears when I try to loop over computers in AD?
It looks like Get-ADComputer returns ADComputer objects, but you're passing it to Get-EventLog's ComputerName parameter, which takes a string, as-is. I'm assuming you'll need to grab the name property from the Microsoft.ActiveDirectory.Management.ADComputer object.