Attempting to run the following script using the scripts feature of SCCM, the script does an AD query and determines if computer is a laptop, then removes a file and copies a file. Script seems to run fine with no error messages but nothing ever happens?
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}
$user = $env:username
$upath = $env:userprofile
$comp = $env:computername
$membersce = Get-adgroupmember -identity "SSLVPN-CountyEmployee" -recursive | select -ExpandProperty SamAccountName
$membershv = Get-adgroupmember -identity "SSLVPN-CountyHVAC" -recursive | select -ExpandProperty SamAccountName
#check if user is part of VPN group
if (($membersce -contains $User) -or ($membershv -contains $User))
{
if (test-connection -Computername $comp -quiet -count 1)
{
if ((Get-WmiObject -Class Win32_ComputerSystem -Property PCSystemType -ComputerName $comp).PCSystemType -eq 2)
{
$script = get-aduser -Identity $user -Properties * | select-Object ScriptPath
$pdpath = "c:\users\public\desktop\" + $script.ScriptPath
$uppath = $upath + "\desktop\" + $script.ScriptPath
$mpath = "\\ncgc-ad.gov\netlogon\" + $script.ScriptPath
if (Test-Path -path $pdpath -pathtype Leaf)
{
Remove-item -Path $pdpath
}
copy-item -path $mpath -destination $uppath -force
}
}
}
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}
$user = $env:username
$upath = $env:userprofile
$comp = $env:computername
$membersce = Get-adgroupmember -identity "SSLVPN-CountyEmployee" -recursive | select -ExpandProperty SamAccountName
$membershv = Get-adgroupmember -identity "SSLVPN-CountyHVAC" -recursive | select -ExpandProperty SamAccountName
#check if user is part of VPN group
if (($membersce -contains $User) -or ($membershv -contains $User))
{
if (test-connection -Computername $comp -quiet -count 1)
{
if ((Get-WmiObject -Class Win32_ComputerSystem -Property PCSystemType -ComputerName $comp).PCSystemType -eq 2)
{
$script = get-aduser -Identity $user -Properties * | select-Object ScriptPath
$pdpath = "c:\users\public\desktop\" + $script.ScriptPath
$uppath = $upath + "\desktop\" + $script.ScriptPath
$mpath = "\\ncgc-ad.gov\netlogon\" + $script.ScriptPath
if (Test-Path -path $pdpath -pathtype Leaf)
{
Remove-item -Path $pdpath
}
copy-item -path $mpath -destination $uppath -force
}
}
}