Jump to content


Search the Community

Showing results for tags 'Now Micro Right Click Tools'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Cloud
    • Azure
    • Microsoft Intune
    • Office 365
  • General Stuff
    • General Chat
    • Events
    • Site News
    • Windows News
    • Suggestion box
    • Jobs
  • MDT, SMS, SCCM, Current Branch &Technical Preview
    • How do I ?
    • Microsoft Deployment Toolkit (MDT)
    • Official Forum Supporters
    • SMS 2003
    • Configuration Manager 2007
    • Configuration Manager 2012
    • System Center Configuration Manager (Current Branch)
    • Packaging
    • scripting
    • Endpoint Protection
  • Windows Client
    • how do I ?
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows Vista
    • Windows XP
    • windows screenshots
  • Windows Server
    • Active Directory
    • Microsoft SQL Server
    • System Center Operations Manager
    • KMS
    • Windows Deployment Services
    • NAP
    • Failover Clustering
    • PKI
    • Windows Server 2008
    • Windows Server 2012
    • Windows Server 2016
    • Windows Server 2019
    • Hyper V
    • Exchange
    • IIS/apache/web server
    • System Center Data Protection Manager
    • System Center Service Manager
    • System Center App Controller
    • System Center Virtual Machine Manager
    • System Center Orchestrator
    • Lync
    • Application Virtualization
    • Sharepoint
    • WSUS

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

Found 1 result

  1. I work for a university that has a standard DNS suffix that matches the domain name across most of the University. My department, however, is unique and our workstations are actually assigned a different DNS suffix that does not match the domain name. So a computer may be named CompName.DomainName.edu but it will resolve as CompName.AltDNSSuffix.edu. Central IT has given out department's IT delegated access to our department's device collection in Configuration Manager 2012 and sent us to training. One of the suggestions of our trainer was to utilize Now Micro Right Click Tools. These tools work for every department in the university but mine. Any time I try to use them, I get told that the workstation is offline. I believe the reason for this is my department's unique DNS Suffix. The actual error I get is "CompName.DomainName.edu is not online." The problem is that CompName.DomainName.edu does not resolve, only CompName.AltDNSSuffix.edu will resolve. I do not have control over the DNS or DHCP so I am looking for a solution that does not involve changes to their configuration. Now Micro Right Click tools is really just a cool collection of Powershell scripts so I believe I can correct this if I can get the script which queries and assigns the computer name to a variable to assign only the first part of the computer name, not the FQDN to the variable. Meaning the variable $CompName becomes "CompName" and not "CompName.DomainName.edu". I am not that skilled with Powershell or scripting in general and would appreciate any assistance. I believe the script I will paste at the bottom of this post is the one that needs to be altered. Thanks! Ryan <# Functions that do all the work Author: Ryan Ephgrave Now Micro Right Click Tools #> $ErrorActionPreference = "SilentlyContinue" $Script:JobTimer = @{} $Script:SkippedJobs = @() $Script:TimedOutComps = New-Object System.Collections.Arraylist $Script:UnsuccessfulCount = 0 $Script:NumSuccessful = 0 $Script:SuccessfulArray = New-Object System.Collections.Arraylist $Script:UnsuccessfulArray = New-Object System.Collections.Arraylist Function WOL { Param ( $CompName, $MAC, $IP, $SubnetMask, $Port, $PacketsToSend ) $UDPclient = New-Object System.Net.Sockets.UdpClient filter Convert-IPToDecimal{([iPAddress][string]([iPAddress]$_)).Address} filter Convert-DecimalToIP{([system.Net.IPAddress]$_).IPAddressToString} $PacketSentCount = 0 $SentPacket = $false $IPArray = $IP.Split(",") $MaskArray = $SubnetMask.Split(",") foreach ($instance in $IPArray){ if ($instance.contains(".")){ foreach ($MaskInstance in $MaskArray){ if ($MaskInstance.contains(".")){ $Error.Clear() $strEditedMac = $MAC | Out-String $strEditedMac = $strEditedMac.replace(":","") $strEditedMac = $strEditedMac.Substring(0,12) [uInt32]$ip = $instance | Convert-IPToDecimal [uInt32]$subnet = $MaskInstance | Convert-IPToDecimal [uInt32]$broadcast = $ip -band $subnet $broadcastAddr = $broadcast -bor -bnot $subnet | Convert-DecimalToIP $BroadcastAddress = [Net.IPAddress]::Parse($BroadcastAddr) $MakingPacket=0,2,4,6,8,10 | % {[Convert]::ToByte($strEditedMac.substring($_,2),16)} $Packet = (,[byte]255 * 6) + ($MakingPacket * 16) $UDPclient.Connect($BroadcastAddress,$Port) Do { [void]$UDPclient.Send($Packet, 102) $PacketSentCount++ } while ($PacketSentCount -lt $PacketsToSend) $SentPacket = $true $Results = Select-Object -InputObject "" One, Two, Three, Four, Five $Results.One = "$CompName" $Results.Two = "$MAC" $Results.Three = "$Instance" $Results.Four = "$MaskInstance" $Results.Five = "$Port" $Script:SuccessfulArray += $Results } } } } if ($SentPacket -eq $false) { $Results = Select-Object -InputObject "" One $Results.One = "$CompName" $Script:UnsuccessfulArray += $Results } $SentPacket } $Client_Actions = { $CompName = $args[0] $strAction = $args[1] $Answer = $args[2] If (Test-Connection -computername $CompName -count 1 -quiet){ if ($Answer -eq 6) { $ActionObject = Get-WmiObject -Query "Select * from InventoryActionStatus where InventoryActionID = '$strAction'" -Namespace root\ccm\invagt -ComputerName $CompName $ActionObject | Remove-WmiObject } $Error.Clear() $WMIPath = "\\" + $CompName + "\root\ccm:SMS_Client" $SMSwmi = [wmiclass] $WMIPath [Void]$SMSwmi.TriggerSchedule($strAction) if($Error[0]){$strOutput = "$CompName" + "|Error|" + $Error} else{$strOutput = "$CompName" + "|Successful"} } else {$strOutput = "$CompName" + "|Off"} Write-Output $strOutput } $Ping_Computer = { $CompName = $args[0] $strOutput = "$CompName|Left|" Test-connection -computername $CompName -count 1 | ForEach-Object { $StrOutput = $strOutput + $_.ProtocolAddress $StrOutput = $strOutput + "|" + $_.ResponseTime + "ms" $StrOutput = $strOutput + "|" + $_.ReplySize $StrOutput = $strOutput + "|" + $_.ResponseTimeToLive + "|" } if ($Error[0]) {$strOutput = "$CompName|Right|Off"} Write-Output $strOutput } $GPUpdate_Computer = { $CompName = $args[0] $UserPolicy = $args[1] $ComputerPolicy = $args[2] $Error.Clear() if ($UserPolicy -eq "True" -and $ComputerPolicy -eq "True") {$strCommand = "cmd /c echo N | gpupdate /force"} elseif ($UserPolicy -eq "True") {$strCommand = "cmd /c echo N | gpupdate /Target:User /force"} elseif ($ComputerPolicy -eq "True") {$strCommand = "cmd /c echo N | gpupdate /Target:Computer /force"} else {$strCommand = "cmd /c echo N | gpupdate /force"} if (Test-Connection $CompName -Count 1) { if ($UserPolicy -eq "True") { $LoggedOnUser = $null $strQuery = "Select UserName from Win32_ComputerSystem" Get-WmiObject -Query $strQuery -ComputerName $CompName | ForEach-Object {$LoggedOnUser = $_.UserName} if ($LoggedOnUser.Length -lt 1) { $strQuery = "Select * from Win32_Process where Name like 'explorer.exe'" Get-WmiObject -Query $strQuery -ComputerName $CompName | ForEach-Object {$LoggedOnUser = $_.GetOwner()} $LoggedOnUser = $LoggedOnUser.Domain + "\" + $LoggedOnUser.User } $LoggedOnUser = $LoggedOnUser | Out-String $LoggedOnUser = $LoggedOnUser.replace("`n","") if ($LoggedOnUser.Length -gt 2) { $Today = Get-Date $Tomorrow = $Today.AddDays(1) $Today = "{0:MM/dd/yyyy}" -f [DateTime]$Today $Tomorrow = "{0:MM/dd/yyyy}" -f [DateTime]$Tomorrow & cmd /c schtasks.exe /create /S "$CompName" /RU "$LoggedOnUser" /SC DAILY /SD "$Today" /ST "00:02" /ED "$Tomorrow" /Z /F /TN "Temp_GPUpdate_Task" /TR "`"$strCommand`"" Start-Sleep 10 & cmd /c schtasks.exe /run /S "$CompName" /i /tn "Temp_GPUpdate_Task" & cmd /c schtasks.exe /delete /S "$CompName" /f /tn "Temp_GPUpdate_Task" if ($Error[0]) { $ErrorMsg = $Error[0].Exception.Message $strOutput = "$CompName|Error|$ErrorMsg" } else {$strOutput = "$CompName|Successful|$LoggedOnUser"} } else { [WMIClass]$wmi = "\\$CompName\root\cimv2:Win32_Process" $wmi.Create($strCommand) | Out-Null if ($Error[0]) { $ErrorMsg = $Error[0].Exception.Message $strOutput = "$CompName|Error|$ErrorMsg" } else {$strOutput = "$CompName|Successful"} } } else { [WMIClass]$wmi = "\\$CompName\root\cimv2:Win32_Process" $wmi.Create($strCommand) | Out-Null if ($Error[0]) { $ErrorMsg = $Error[0].Exception.Message $strOutput = "$CompName|Error|$ErrorMsg" } else {$strOutput = "$CompName|Successful"} } } else {$strOutput = "$CompName|Off"} Write-Output $strOutput } $Cancel_Pending_Reboot = { $CompName = $args[0] If (test-connection -computername $CompName -count 1 -quiet){ $Error.Clear() & shutdown.exe /m $CompName /a $ShutdownExitCode = $LastExitCode if ($ShutdownExitCode -eq 1116) {$strOutput = "$CompName" + "|No pending shutdown"} elseif ($ShutdownExitCode -eq 0) {$strOutput = "$CompName" + "|Cancelled pending shutdown"} else {$strOutput = "$CompName" + "|Error|" + $Error} } else {$strOutput = "$CompName|Off"} Write-Output $strOutput } $Change_Cache_Size = { $CompName = $args[0] $NewCacheSize = $args[1] If (test-connection -computername $CompName -count 1 -quiet){ $Error.Clear() $CacheUsed = 0 $strQuery = "select ContentSize from CacheInfoEx" Get-WmiObject -ComputerName $CompName -Query $strQuery -Namespace root\ccm\SoftMgmtAgent | ForEach-Object { if ($_.ContentSize -ne $null) { $TempNum = 0 $TempNum = $_.ContentSize $TempNum = $TempNum / 1024 $CacheUsed = $CacheUsed + $TempNum } } $cachesize = Get-WmiObject -ComputerName $CompName -Class CacheConfig -Namespace root\ccm\softmgmtagent foreach ($instance in $cachesize) {$OldCache = $instance.Size} $Error.Clear() $cachesize.Size = "$NewCacheSize" $cachesize.Put() | Out-Null if($Error[0]){$strOutput = $CompName + "|Error|" + $Error} else{$strOutput = $CompName + "|Successful|" + $NewCacheSize + "|" + $OldCache + "|" + $CacheUsed} } else {$strOutput = "$Compname|Off"} Write-Output $strOutput } $Clear_Cache = { $CompName = $null $CompName = $args[0] If (test-connection -computername $CompName -count 1 -quiet){ $Error.Clear() Get-WmiObject -ComputerName $CompName -Class CacheInfoEx -Namespace root\ccm\softmgmtagent | ForEach-Object { $CachePath = $_.Location $CachePath = $CachePath.replace(":","$") $CachePath = "\\$CompName\$CachePath" Remove-Item $CachePath -Recurse -Force $_ | Remove-WmiObject } if ($Error[0]) {$strOutput = "$CompName" + "|Error| " + $Error} else {$strOutput = "$CompName" + "|Successful"} } else {$strOutput = "$CompName" + "|Off"} Write-Output $strOutput } $Repair_Client = { $CompName = $null $CompName = $args[0] If (test-connection -computername $CompName -count 1 -quiet){ $Error.Clear() $WMIPath = "\\" + $CompName + "\root\ccm:SMS_Client" $SMSwmi = [wmiclass] $WMIPath [Void]$SMSwmi.RepairClient() if ($Error[0]) {$strOutput = "$CompName" + "|Error|" + $Error} else {$strOutput = "$CompName" + "|Successful"} } else {$strOutput = "$CompName" + "|Off"} Write-Output $strOutput } $Restart_SMS_Service = { $CompName = $null $CompName = $args[0] If (test-connection -computername $CompName -count 1 -quiet){ $Error.Clear() $CcmExecService = Get-Service -ComputerName $CompName -Name "CcmExec" Restart-Service -InputObject $CcmExecService if ($Error[0]) {$strOutput = "$CompName" + "|Error| " + $Error} else {$strOutput = "$CompName" + "|Successful"} } else {$strOutput = "$CompName" + "|Off"} Write-Output $strOutput } $Uninstall_Client = { $CompName = $null $CompName = $args[0] If (test-connection -computername $CompName -count 1 -quiet){ $Error.Clear() Get-WmiObject -ComputerName $CompName -Class CCM_InstalledProduct -Namespace root\ccm | ForEach-Object {$ProductCode = $_.ProductCode} $UninstallCommand = "msiexec /x `"$ProductCode`" REBOOT=ReallySuppress /q" $WMIPath = "\\" + $CompName + "\root\cimv2:Win32_Process" $StartProcess = [wmiclass] $WMIPath $ProcError = $StartProcess.Create($UninstallCommand,$null,$null) $ProcError = $ProcError.ReturnValue if ($Error[0]) {$strOutput = "$CompName" + "|Error| " + $Error} else { if ($ProcError -eq 0){$strOutput = "$CompName" + "|Successful"} else {$strOutput = "$CompName" + "|Error| " + $Error} } } else {$strOutput = "$CompName" + "|Off"} Write-Output $strOutput } $Schedule_ShutdownRestart = { $CompName = $null $CompName = $args[0] $Action = $args[1] $Delay = $args[2] $IfUserOnBoxText = $args[3] $TaskName = $args[4] $FreqText = $args[5] $Modifier = $args[6] $StartDate = $args[7] $StartTime = $args[8] $EndDate = $args[9] $Directory = $args[10] $StartDay = $args[11] If (test-connection -computername $CompName -count 1 -quiet){ $Error.Clear() if ($Action -eq "Restart"){ if ($IfUserOnBoxText -eq "Restart/Shutdown") { $ShutdownCommand = "shutdown /r /f /t $delay" } elseif ($IfUserOnBoxText -eq "Give user a prompt to cancel"){ Get-WmiObject -ComputerName $CompName -class Win32_OperatingSystem | ForEach-Object {$WinDirectory = $_.WindowsDirectory} $ShutdownCommand = "$WinDirectory\ConfigMgr_Shutdown_Utility.exe /r /t $Delay /Schtask `"$WinDirectory\ConfigMgr_Shutdown_Utility.exe`"" $CopyDirectory = $WinDirectory.ToLower().replace("c:","\\$CompName\c$") Copy-Item "$Directory\ConfigMgr_Shutdown_Utility.exe" $CopyDirectory -Force Copy-Item "$Directory\ConfigMgr_Shutdown_Utility.vbs" $CopyDirectory -Force } elseif ($IfUserOnBoxText -eq "Cancel Restart/Shutdown") { Get-WmiObject -ComputerName $CompName -class Win32_OperatingSystem | ForEach-Object {$WinDirectory = $_.WindowsDirectory} $ShutdownCommand = "$WinDirectory\ConfigMgr_Shutdown_Utility.exe /r /t $Delay /Skip /Schtask `"$WinDirectory\ConfigMgr_Shutdown_Utility.exe`"" $CopyDirectory = $WinDirectory.ToLower().replace("c:","\\$CompName\c$") Copy-Item "$Directory\ConfigMgr_Shutdown_Utility.exe" $CopyDirectory -Force } } elseif ($Action -eq "Shutdown") { if ($IfUserOnBoxText -eq "Restart/Shutdown") { $ShutdownCommand = "shutdown /s /f /t $delay" } elseif ($IfUserOnBoxText -eq "Give user a prompt to cancel"){ Get-WmiObject -ComputerName $CompName -class Win32_OperatingSystem | ForEach-Object {$WinDirectory = $_.WindowsDirectory} $ShutdownCommand = "$WinDirectory\ConfigMgr_Shutdown_Utility.exe -arguments /s /t $Delay /Schtask `"$WinDirectory\ConfigMgr_Shutdown_Utility.exe`"" $CopyDirectory = $WinDirectory.ToLower().replace("c:","\\$CompName\c$") Copy-Item "$Directory\ConfigMgr_Shutdown_Utility.exe" $CopyDirectory -Force Copy-Item "$Directory\ConfigMgr_Shutdown_Utility.vbs" $CopyDirectory -Force } elseif ($IfUserOnBoxText -eq "Cancel Restart/Shutdown") { Get-WmiObject -ComputerName $CompName -class Win32_OperatingSystem | ForEach-Object {$WinDirectory = $_.WindowsDirectory} $ShutdownCommand = "$WinDirectory\ConfigMgr_Shutdown_Utility.exe -arguments /s /t $Delay /Skip /Schtask `"$WinDirectory\ConfigMgr_Shutdown_Utility.exe`"" $CopyDirectory = $WinDirectory.ToLower().replace("c:","\\$CompName\c$") Copy-Item "$Directory\ConfigMgr_Shutdown_Utility.exe" $CopyDirectory -Force } } if ($Error[0]) {$strOutput = "$CompName" + "|Error| " + $Error} else { if ($FreqText -eq "Once") { $Error.Clear() $strTest = & schtasks.exe /create /S "$CompName" /RU SYSTEM /SC ONCE /SD "$StartDate" /ST "$StartTime" /F /TN "$TaskName" /TR "`"$ShutdownCommand`"" if ($Error[0]) {$strOutput = "$CompName" + "|Error| " + $Error} else {$strOutput = "$CompName" + "|Successful"} } elseif ($FreqText -eq "Daily") { $Error.Clear() $strTest = & schtasks.exe /create /S "$CompName" /RU SYSTEM /SC DAILY /SD "$StartDate" /ST "$StartTime" /ED "$EndDate" /Z /F /TN "$TaskName" /TR "`"$ShutdownCommand`"" if ($Error[0]) {$strOutput = "$CompName" + "|Error| " + $Error} else {$strOutput = "$CompName" + "|Successful"} } elseif ($FreqText -eq "Weekly") { $Error.Clear() $strTest = & schtasks.exe /create /S "$CompName" /RU SYSTEM /SC WEEKLY /d "$StartDay" /SD "$StartDate" /ST "$StartTime" /ED "$EndDate" /Z /F /TN "$TaskName" /TR "`"$ShutdownCommand`"" if ($Error[0]) {$strOutput = "$CompName" + "|Error|$Error"} else {$strOutput = "$CompName" + "|Successful"} } elseif ($FreqText -eq "Monthly (On Day)") { $Error.Clear() if ($Modifier -eq "LASTDAY") {$strTest = & schtasks.exe /create /S "$CompName" /RU SYSTEM /SC MONTHLY /MO $Modifier /M * /SD "$StartDate" /ST "$StartTime" /ED "$EndDate" /Z /F /TN "$TaskName" /TR "`"$ShutdownCommand`""} else {$strTest = & schtasks.exe /create /S "$CompName" /RU SYSTEM /SC MONTHLY /MO $Modifier /d $StartDay /SD "$StartDate" /ST "$StartTime" /ED "$EndDate" /Z /F /TN "$TaskName" /TR "`"$ShutdownCommand`""} if ($Error[0]) {$strOutput = "$CompName" + "|Error| " + $Error} else {$strOutput = "$CompName" + "|Successful"} } elseif ($FreqText -eq "Monthly (On Date)") { $Error.Clear() $strTest = & schtasks.exe /create /S "$CompName" /RU SYSTEM /SC MONTHLY /d $StartDay /SD "$StartDate" /ST "$StartTime" /ED "$EndDate" /Z /F /TN "$TaskName" /TR "`"$ShutdownCommand`"" if ($Error[0]) {$strOutput = "$CompName" + "|Error| " + $Error} else {$strOutput = "$CompName" + "|Successful"} } } } else {$strOutput = "$CompName" + "|Off"} Write-Output $strOutput } $ShutdownRestart_Device = { $CompName = $args[0] $strAction = $args[1] $IndexNum = $args[2] $Delay = $args[3] $msg = $args[4] $Directory = $args[5] $psexec = $args[6] $LoggedOnUser = $null $LoggedOnDomain = $null If (test-connection $CompName -count 1 -quiet){ $Error.Clear() if ($strAction -eq "Restart"){ if ($IndexNum -eq 0){ & shutdown.exe /r /f /t $Delay /d p:0:0 /m $CompName /c $msg if ($Error[0]){ $ErrorMsg = $Error[0] $strOutput = $CompName + "|Error|" + $ErrorMsg } else {$strOutput = $CompName + "|Successful|" + $strAction} } elseif ($IndexNum -eq 1){ Get-WmiObject -ComputerName $CompName -class Win32_OperatingSystem | ForEach-Object {$WinDirectory = $_.WindowsDirectory} $CopyDirectory = $WinDirectory.ToLower().replace("c:","\\$CompName\c$") Copy-Item "$Directory\ConfigMgr_Shutdown_Utility.exe" $CopyDirectory -Force Copy-Item "$Directory\ConfigMgr_Shutdown_Utility.vbs" $CopyDirectory -Force $strQuery = "Select * from Win32_Process where Name='explorer.exe'" $SentShutdown = $false Get-WmiObject -ComputerName $CompName -Query $strQuery | ForEach-Object{ if ($_.Name -ne $null){ $SessionID = $_.SessionID $LoggedOnUser = $_.GetOwner().User $LoggedOnDomain = $_.GetOwner().Domain $LoggedOn = "$LoggedOnDomain" + "\" + "$LoggedOnUser" if (!($Error[0])) {$ClearError = $true} & $psexec "\\$CompName" /d /s /i $SessionID wscript.exe "$WinDirectory\ConfigMgr_Shutdown_Utility.vbs" "$WinDirectory\ConfigMgr_Shutdown_Utility.exe" /r /t $Delay /msg "`"$msg`"" | Out-Null if ($ClearError -eq $true) {$Error.Clear()} $SentShutdown = $true $strOutput = $Compname + "|Successful|Gave $LoggedOn a prompt to cancel $strAction" } } if ($SentShutdown -eq $false) { & shutdown.exe /r /f /t $Delay /d p:0:0 /m $CompName /c $msg $strOutput = $CompName + "|Successful|" + "$strAction" } if ($Error[0]) {$strOutput = $CompName + "|Error|" + $Error} } elseif ($IndexNum -eq 2){ $skip = 0 $strQuery = "Select * from Win32_Process where Name='explorer.exe'" Get-WmiObject -ComputerName $CompName -query $strQuery | ForEach-Object{ if ($_.Name -ne $null){ $skip = 1 $LoggedOnUser = $_.GetOwner().User $LoggedOnDomain = $_.GetOwner().Domain $LoggedOn = "$LoggedOnDomain" + "\" + "$LoggedOnUser" $strOutput = $CompName + "|Successful|Skipped - $LoggedOn" } } if ($skip -eq 0){ $Error.Clear() & shutdown.exe /r /f /t $Delay /d p:0:0 /m $CompName /c $msg if ($Error[0]){ $ErrorMsg = $Error[0] $strOutput = $CompName + "|Error|" + $ErrorMsg } else {$strOutput = $CompName + "|Successful|" + "$strAction"} } } } elseif ($strAction -eq "Shutdown"){ if ($IndexNum -eq 0){ & shutdown.exe /s /f /t $Delay /d p:0:0 /m $CompName /c $msg if ($Error[0]){ $ErrorMsg = $Error[0] $strOutput = $CompName + "|Error|" + $ErrorMsg } else {$strOutput = $CompName + "|Successful|" + "$strAction"} } elseif ($IndexNum -eq 1){ Get-WmiObject -ComputerName $CompName -class Win32_OperatingSystem | ForEach-Object {$WinDirectory = $_.WindowsDirectory} $CopyDirectory = $WinDirectory.ToLower().replace("c:","\\$CompName\c$") Copy-Item "$Directory\ConfigMgr_Shutdown_Utility.exe" $CopyDirectory -Force Copy-Item "$Directory\ConfigMgr_Shutdown_Utility.vbs" $CopyDirectory -Force $strQuery = "Select * from Win32_Process where Name='explorer.exe'" $SentShutdown = $false Get-WmiObject -ComputerName $CompName -Query $strQuery | ForEach-Object{ if ($_.Name -ne $null){ $SessionID = $_.SessionID $LoggedOnUser = $_.GetOwner().User $LoggedOnDomain = $_.GetOwner().Domain $LoggedOn = "$LoggedOnDomain" + "\" + "$LoggedOnUser" if (!($Error[0])) {$ClearError = $true} & $psexec "\\$CompName" /d /s /i $SessionID wscript.exe "$WinDirectory\ConfigMgr_Shutdown_Utility.vbs" "$WinDirectory\ConfigMgr_Shutdown_Utility.exe" /s /t $Delay /msg "`"$msg`"" | Out-Null if ($ClearError -eq $true) {$Error.Clear()} $SentShutdown = $true $strOutput = $Compname + "|Successful|Gave $LoggedOn a prompt to cancel $strAction" } } if ($SentShutdown -eq $false) { & shutdown.exe /s /f /t $Delay /d p:0:0 /m $CompName /c $msg $strOutput = $CompName + "|Successful|" + "$strAction" } if ($Error[0]) {$strOutput = $CompName + "|Error|" + $Error[0]} } elseif ($IndexNum -eq 2){ $skip = 0 $strQuery = "Select * from Win32_Process where Name='explorer.exe'" Get-WmiObject -ComputerName $CompName -query $strQuery | ForEach-Object{ if ($_.Name -ne $null){ $skip = 1 $LoggedOnUser = $_.GetOwner().User $LoggedOnDomain = $_.GetOwner().Domain $LoggedOn = "$LoggedOnDomain" + "\" + "$LoggedOnUser" $strOutput = "$CompName" + "|Successful|Skipped - $LoggedOn" } } if ($skip -eq 0){ $Error.Clear() & shutdown.exe /s /f /t $Delay /d p:0:0 /m $CompName /c $msg if ($Error[0]){ $ErrorMsg = $Error[0] $strOutput = $CompName + "|Error|" + $ErrorMsg } else {$strOutput = $CompName + "|Successful|" + "$strAction"} } } } } else {$strOutput = "$CompName |Off"} Write-Output $strOutput } $Rerun_Deployment = { $CompName = $null $CompName = $args[0] $AdvID = $args[1] If (test-connection -computername $CompName -count 1 -quiet){ $Error.Clear() $strQuery = "Select * from CCM_Scheduler_ScheduledMessage where ScheduledMessageID like '" + $AdvID + "%'" $objSMSSchID = Get-WmiObject -Query $strQuery -Namespace root\ccm\policy\machine\actualconfig -computername $CompName foreach($instance in $objSMSSchID){$strScheduleID = $instance.ScheduledMessageID} if ($Error[0]){$strOutput = "$CompName" + "|Error| " + $Error} else { $strQuery = "Select * from CCM_SoftwareDistribution where ADV_AdvertisementID='" + $AdvID + "'" Get-WmiObject -ComputerName $CompName -Namespace "root\CCM\Policy\Machine\ActualConfig" -Query $strQuery | ForEach-Object { $_.ADV_MandatoryAssignments = "True" $_.ADV_RepeatRunBehavior = "RerunAlways" [Void]$_.Put() } $WMIPath = "\\" + $CompName + "\root\ccm:SMS_Client" $SMSwmi = [wmiclass] $WMIPath [Void]$SMSwmi.TriggerSchedule($strScheduleID) if ($Error[0]){$strOutput = "$CompName" + "|Error| " + $Error} else {$strOutput = "$CompName" + "|Successful"} } } else {$strOutput = "$CompName" + "|Off"} Write-Output $strOutput } $CcmEval = { $CompName = $null $CompName = $args[0] $CcmEvalPath = $null If(Test-Connection $CompName -Count 1) { Get-WmiObject -ComputerName $CompName -Class Win32_OperatingSystem | ForEach-Object {$WindowsDirectory = $_.WindowsDirectory} $WindowsDirectory = $WindowsDirectory.replace(":","$") $WindowsDirectory = "\\$CompName\$WindowsDirectory" $TestPath1 = $WindowsDirectory + "\CCM\CcmEval.exe" $TestPath2 = $WindowsDirectory + "\System32\CCM\CcmEval.exe" $TestPath3 = $WindowsDirectory + "\syswow64\CCM\CcmEval.exe" if (Test-Path $TestPath1){$CCMEvalPath = $TestPath1} elseif (Test-Path $TestPath2){$CCMEvalPath = $TestPath2} elseif (Test-Path $TestPath3){$CCMEvalPath = $TestPath3} if ($CcmEvalPath -ne $null) { $Error.Clear() ([WMIClass]"\\$CompName\root\CIMV2:Win32_Process").Create($CcmEvalPath) | Out-Null if ($Error[0]) {$strOutput = "$CompName" + "|Error|" + "$Error"} else {$strOutput = "$CompName" + "|Successful"} } else {$strOutput = "$CompName" + "|Error|" + "$Error"} } else {$strOutput = "$CompName" + "|Off"} Write-Output $strOutput } #>
×
×
  • Create New...