Michael's profileThe Old Dogs Scripting B...BlogListsNetworkMore ![]() | Help |
The Old Dogs Scripting Blog A Blog for Advanced Beginners and Intermediate scripters. PowerShell and VBScript |
|||||||||||||||
|
|
Useful and Fun Links
July 01 How to change the Wins IP address on a computerWere you wondering if anyone has a script that can change the Wins IP address on a server? Get-WmiObject -ComputerName "." ` Win32_NetworkAdapterConfiguration | ?{$_.IPEnabled -eq $True} | ` % {$_.SetWINSServer("172.16.1.240", "172.16.1.241")} I'm guessing you'll want to do this on multiple servers. One way you can do it is read a list of servers from a file into a variable and then run the command on each server: $servers = get-content c:\servers.txt foreach ($server in $servers) { Get-WmiObject -ComputerName $server ` Win32_NetworkAdapterConfiguration | ?{$_.IPEnabled -eq $True} | ` % {$_.SetWINSServer("172.16.1.240", "172.16.1.241")} } June 29 Want to Show a vbScript MsgBox in Powershell ?I wanted to ask before I closed my Excel spreadsheet. In vbScript, I used a msgbox for this.
I found this process for PowerShell and it works.
#<----- Start POSH Script ------------------------------------------------------------->
Function Show-Msgbox {
Param([string]$message=$(Throw "You must specify a message"), [string]$button="okonly", [string]$icon="Question", [string]$title="Message Box" ) # Buttons: OkOnly, OkCancel, AbortRetryIgnore, YesNoCancel, YesNo, RetryCancel # Icons: Critical, Question, Exclamation, Information [reflection.assembly]::loadwithpartialname("microsoft.visualbasic") | Out-Null [microsoft.visualbasic.interaction]::Msgbox($message,"$button,$icon",$title) } $rc=Show-Msgbox -message "Do you want to view the Spredsheet?" `
-icon "exclamation" -button "YesNoCancel" -title "Hey $env:username!!" Switch ($rc) { "Yes" {$x.Visible = $True } # close and release resources "No" {$y.close($false) $xl.quit() spps -n excel } #<---- This will shut down every instance of Excell (for sure!) "cancel" {"When in doubt, punt."} } #<------------ End of Script -------------------------------------------------------------> June 24 Enable the Trusted Platform Module on a Dell OMCI clientMore TPM madness For Dell users only:
Begin vbScript
'**********************************************************************
'*** Name: SampleTrustedPlatformModule.vbs '*** Purpose: To Enable the Trusted Platform Module on a Dell OMCI client. '*** Usage: cscript.exe //nologo SampleTrustedPlatformModule.vbs <systemname> '*** Make sure to open a cmd.com shell as administrator in Vista otherwise UAC will '*** cause it to error out. '*** '*** NOTE: Replace the word yourpassword at the end of line 51 (inside the '*** quotes) with the correct BIOS password if one is set. '*** '*** To only Activate the TPM comment out line 70 “objInstance.Properties_.Item(strPropNameTpmON).Value = 3” '********************************************************************** Option Explicit
'*** Declare variables
Dim strNameSpace Dim strComputerName Dim strClassName Dim strKeyValue Dim objInstance Dim strPropNameTpmON Dim strPropNameTpmActivation Dim strPropValue '*** Check that the right executable was used to run the script
'*** and that all parameters were passed If (LCase(Right(WScript.FullName, 11)) = "wscript.exe" ) Or _ (Wscript.Arguments.Count < 1) Then Call Usage() WScript.Quit End If '*** Initialize variables
strNameSpace = "root/Dellomci" strComputerName = WScript.Arguments(0) strClassName = "Dell_Configuration" strKeyValue = "Configuration" '*** Retrieve the instance of Dell_Configuration class (there should
'*** only be 1 instance). Set objInstance = GetObject("WinMgmts:{impersonationLevel=impersonate,AuthenticationLevel=pktprivacy}//" &_ strComputerName & "/" & strNameSpace & ":" & strClassName & "=" &_ Chr(34) & strKeyValue & Chr(34)) '*** Verify the BIOS Admin Password to enable changes to BIOS settings
'*** Replace ‘password’ in the next line with the BIOS Admin password objInstance.Properties_.Item("Password").Value = "dell123" objInstance.Properties_.Item("PasswordEncrypted").Value = 0 objInstance.Put_ '*** Initialize variables strClassName = "Dell_SMBIOSSettings" strKeyValue = "0" strPropNameTpmON = "TrustedPlatformModule" strPropNameTpmActivation = "TrustedPlatformModuleActivation" '*** Retrieve the instance of Dell_SMBIOSSettings class (there should
'*** only be 1 instance). Set objInstance = GetObject("WinMgmts:{impersonationLevel=impersonate,AuthenticationLevel=pktprivacy}//" &_ strComputerName & "/" & strNameSpace & ":" & strClassName & "=" &_ Chr(34) & strKeyValue & Chr(34)) '*** Set the value of TrustedPlatformModule to '3' ("Enabled")
'*** Set the new value for the property and save the instance objInstance.Properties_.Item(strPropNameTpmON).Value = 3 '*** Set the value of TrustedPlatformModuleActivation to '3' ("Activated")
'*** Set the new value for the property and save the instance objInstance.Properties_.Item(strPropNameTpmActivation).Value = 3 objInstance.Put_ '*** If any errors occurred, let the user know
If Err.Number <> 0 Then WScript.Echo "Enabling Trusted Platform Module failed." End If '*** Sub used to display the correct usage of the script Sub Usage() Dim strMessage strMessage = "incorrect syntax. You should run: " & vbCRLF & _ "cscript.exe /nologo SampleTrustedPlatformModule.vbs <systemname>" WScript.Echo strMessage End Sub June 09 Log Off at end of scriptSo there I was, wondering how to log off from a session after I had finshed my script.
I had to run the the thing under elevated privlages and I was running it from the "run once"
key in the registry, so I wanted it to log off ASAP.
I looked around and poked around and looked in my books, and then I ran across this piece of wisdom from
Set oShell = CreateObject("WScript.Shell")
oShell.Run "logoff", 0, False a List of links to my favorite blogs
|
||||||||||||||
|
|