我创建了一个脚本来循环浏览具有两列的电子表格。我遇到的问题是本地变量在我运行时不起作用invoke-command
。我已经添加了-ArgumentList
参数,但我仍然收到有关$null
参数的错误。有人知道我在这里做错了什么吗?
foreach ($list in (Import-Csv C:\Users\joerod\Desktop\remove_users.csv)) {
Write-Output "Connecting to $($list.computer)..."
$myses = New-PSSession -ComputerName $list.computer
Invoke-Command -Session $myses -ScriptBlock {
Write-Output "Searching for software..."
Write-Output $list.user
$find_java = gwmi Win32_Product -Filter "Name LIKE '%Java'" | select -ExpandProperty IdentifyingNumber
if ($find_java -ne $null) {
Write-Output "Software found... Uninstalling..."
foreach ($i in $find_mktx) {
msiexec.exe /x $i /qn /passive /l*v! c:\uninst.log
}
Write-Output "Adding $($list.user) to security group"
$group = "CN=Java_removed,OU=Groups,OU=Resources,DC=Contoso,DC=LOCAL"
Add-ADGroupMember $group -Identity $list.user
}
else {
Write-Output "Could not find Java software installed"
}
} -ArgumentList $list
}