From the Functions list right click on the bar to the right and click copy, select a new blank line, and click paste.
I know, dead simple right? Some times it helps to have these things out there as it’s easy to miss that this is possible in C/Side.
From the Functions list right click on the bar to the right and click copy, select a new blank line, and click paste.
I know, dead simple right? Some times it helps to have these things out there as it’s easy to miss that this is possible in C/Side.
If you have ever needed to call an exe application from PowerShell and needed to pass multiple parameters to the exe then the technique I outline here will really help you out.
Declare a variable that holds the executable name as a string and any other variables you might want to use
$pfm = “pfm”
$MountPath = “T:”
As a side note the application I am calling is Pismo File Mount which is by far the best free (even for commercial use) software I have ever used for mounting ISOs
Declare all your parameters as an object array
$Mount = “mount”,”-m”,”$MountPath”
Now in your code you can do the following
& $pfm $Mount “$MSDNIsoPath\en_visual_studio_2010_premium_rc_x86_dvd_489527.iso”
If I wanted to write out all my parameters every time I could always write in PowerShell:
Pfm mount -m “$MountPath” “$MSDNIsoPath\en_visual_studio_2010_premium_rc_x86_dvd_489527.iso”
I can’t say as I have figured out why this works this way and if anyone has an explanation I would love to hear it in the comments.
I am a big fan of differencing VHDs as the provide tremendous power when working with large database but they also come with their own set of complications.
One of those complications that can arise is when due to files being moved or folder structures being reorganized the parent VHD of your differencing VHD is no longer accessible. After you try and attach your differencing VHD you may see an error message like this one:
We can use the following power shell from a Windows 7 PC with the latest version of Microsoft Virtual PC that comes with Windows XP Mode installed to take a look at the parent property of our differencing disk to see if something is wrong
$vpc=new-object -com VirtualPC.Application
$VHDChild = $vpc.GetHardDisk("C:\NAV2010.06.10_Diff")
$VHDChild
$VHDChild.Parent
In my case I recently changed the IP address of a NAS that was storing the parent VHD and assigned a DNS record to the NAS so that I wouldn’t have to keep track of it’s IP address but now the path to the parent VHD that is stored in my differencing VHD is no longer valid.
Thankfully this is fairly easy to fix. All we need to do is add the following code so that we get a new $VHDParent object using the corrected path and then assign that object to the Parent property of our differencing disk
$VHDParent = $vpc.GetHardDisk("\\devnas\Data_Backups SQLCluster1\NAV2010.06.10.vhd")
$VHDChild.Parent = $VHDParent
$VHDChild.Parent
Now we can attach our differencing VHD without error and get back to work =).
I love the fact that Windows 7 can attach VHD disks as if they were local hard disks. This allows me to pull off some very interesting stuff that I will blog about later but one pain point has been that through the UI with only Windows 7 I cannot create a differencing VHD from a parent VHD that is stored at a UNC path on the network.
The solution to this is to install the latest version of Microsoft Virtual PC which can be downloaded form the Windows XP Mode website. After installing this you are now able to create differencing disks based on parent VHDs that are stored on your network at a UNC path as shown below:
$vpc=new-object -com VirtualPC.Application
$vpc.CreateDifferencingVirtualHardDisk("\\devnas\Data_Backups\SQLCluster1\NAV 2010.08.20 Differencing.vhd","\\devnas\Data_Backups\SQLCluster1\NAV 2010.08.20 Full.vhd")
Note: If you still have the parent VHD attached to a machine this command will silently fail. Make sure that the parent is not being used and is not attached to any machine before running this.
In a future post I will talk about some of the use cases for this technique that make it invaluable.
Hint: Multiple 300GB+ database development from a laptop with only an 120 GB hard drive as if all DBs were local
Using IN with values from an option field to test whether a field is set to one of the values in a subset of the total options.
IF (Status IN [Status::Open, Status::Authorized, Status::Closed] = TRUE) THEN BEGIN
Legend:
A ‘,’ separates items that come in a sequence for instance Alt, F, S would mean press Alt, let go, press F, let go, and finally press S.
A ‘+’ separates keys that are suppose to be pressed at the same time. Alt + D would mean press and hold Alt while pressing D
ALT, V, B – Shows the C/AL globals
ALT, V, A – Shows the C/AL locals
ALT + D – Design the current object
ALT + R – Run the current object
ALT > F > S to save
CTRL + F to find
I have used the command line interface (CLI) for Sun’s Virtual Box and for Hyper V but I didn’t realize that Virtual PC also can be accessed through PowerShell. This might be the key to creating network based differencing disks natively on Windows 7 which currently isn’t something that can be done in a straightforward way through the GUI and even the way that it can be done has limitations (like not being able to create a differencing disk with the parent disk on the network).
</pre>
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
PS H:\> $vpc=new-object -com VirtualPC.Application
PS H:\> $vpc
HostInfo : System.__ComObject
VirtualMachines : System.__ComObject
VirtualNetworks : System.__ComObject
UnconnectedNetworkAdapters : System.__ComObject
SupportDrivers : System.__ComObject
Tasks : System.__ComObject
MinimumMemoryPerVM : 4
MaximumMemoryPerVM : 3575
SuggestedMaximumMemoryPerVM : 3217
MaximumFloppyDrivesPerVM : 1
MaximumSerialPortsPerVM : 2
MaximumParallelPortsPerVM : 1
MaximumNetworkAdaptersPerVM : 4
MaximumNumberOfIDEBuses : 2
DefaultVMConfigurationPath : C:\Users\cmagnuson\AppData\Local\Microsoft\Windows Virtual PC\Virtual Machines\
SearchPaths : {}
USBDeviceCollection : System.__ComObject
Name : Windows Virtual PC
Version : 6.1.7600.16393
UpTime : 6
PS H:\> $vm = $vpc.FindVirtualMachine(
>>
>>
>>
PS H:\> $vm = $vpc.FindVirtualMachine("IE 6")
PS H:\> $vm
Name : IE 6
ConfigID : {DB33D85B-1FAC-4A67-910A-33EE4A4F06FC}
File : C:\Users\cmagnuson\AppData\Local\Microsoft\Windows Virtual PC\Virtual Machines\IE 6.vmc
Accountant : System.__ComObject
GuestOS : System.__ComObject
Display : System.__ComObject
Keyboard : System.__ComObject
Mouse :
State : 2
ShutdownActionOnQuit : 0
SavedStateFilePath : C:\Users\cmagnuson\AppData\Local\Microsoft\Windows Virtual PC\Virtual Machines\IE 6.vsv
BIOSGUID : {D5356F8F-4383-4B68-ACDA-03D1A06E5C46}
BIOSSerialNumber : 8425-1374-7407-2656-1007-9980-44
BaseBoardSerialNumber : 8425-1374-7407-2656-1007-9980-44
ChassisSerialNumber : 8425-1374-7407-2656-1007-9980-44
ChassisAssetTag : 1746-8710-8930-6641-7796-6780-67
HardDiskConnections : System.__ComObject
Undoable : False
UndoAction : 1
DVDROMDrives : System.__ComObject
FloppyDrives : System.__ComObject
NetworkAdapters : System.__ComObject
SerialPorts : System.__ComObject
ParallelPorts : System.__ComObject
ProcessorSpeed : 2926
HasMMX : True
HasSSE : True
HasSSE2 : False
Has3DNow : False
RdpPipeName :
Notes :
Memory : 1024
AttachedDriveTypes : {1, 0, 2, 0}
PS H:\>
Original Source: http://blogs.msdn.com/b/virtual_pc_guy/archive/2009/07/14/windows-virtual-pc-and-powershell.aspx
So when I go to do this again I will have something to refer back to:
WITH r_RecordVariableName DO BEGIN
// SetFilters and SetRanges
IF FIND('-') THEN BEGIN
REPEAT
ForEachRecordDoThis();
UNTIL NEXT = 0;
END;
END;
How to install Visual Studio 2005 on Windows 7 x64 the Unattended way
:Variables
SET VisualStudio2005FilesPath=c:\VS2005
SET VisualStudio2005ResourcesPath=c:\VS2005_Resources</code>
echo.
echo Install Visual Studio 2005
echo -Install Prequisites
"%VisualStudio2005FilesPath%\WCU\64bitPrereq\x64\vs_bsln.exe" /Q
"%VisualStudio2005FilesPath%\WCU\DExplore\dexplore.exe" /q:a /c:"install.exe /q"
echo -Install Visual Studio 2005
"%VisualStudio2005FilesPath%\setup\setup.exe" /unattendfile "c:\VS2005.ini"
echo -Install Visual Studio 2005 SP1
"%VisualStudio2005ResourcesPath%\en_visual_Studio_2005 SP1 (VS80sp1-KB926601-X86-ENU).exe" /q
echo -Install Visual Studio 2005 SP1 for Windows Vista
"%VisualStudio2005ResourcesPath%\en_visual_studio_2005 SP1 Vista (VS80sp1-KB932232-X86-ENU).exe" /q
Once you have done all that run the c:\InstallVS2005.bat file from a cmd prompt with Administrator priviledges. Towards the end of the initial Visual Studio 2005 install windows 7 will prompt you with a warning about Visual Studio 2005 being a an application that it has trouble running. Dismiss the warning and allow the installation to continue.
Once the bat file is finished you should have a working Visual Studio 2005 installation.
Ancillary tools that you might find useful, MetaBase Explorer
on error resume next
dim Contains
Set ArgObj = WScript.Arguments
If ArgObj.Count < 1 Then
Wscript.echo "Please specify the name or part name to look for in the host header field!"
Wscript.echo ""
Wscript.echo "Example"
Wscript.echo " cscript EnumByHostHeader.vbs ccrowe"
else
Contains = ucase(ArgObj.Item(0))
dim websrv, site
dim Found
dim webinfo
Found = false
WScript.echo "Searching for " & Contains & " in the host headers"
WScript.echo ""
WScript.echo "Web Site Instance ID - Server Comment - Host Header"
set websrv = getobject("IIS://Localhost/W3SVC")
if (err <> 0) then
else
err.Clear
for each site in websrv
if (site.classname = "IIsWebServer") then
bindings = Site.ServerBindings
For Index = LBound(bindings) To UBound(bindings)
Values = split(bindings(Index), ":")
HostHeader = ucase(Values(2))
if (instr(HostHeader, Contains) > 0) then
Found = true
WScript.echo site.Name
' WScript.echo site.Name & " - " & _
' site.ServerComment & " - " & _
' HostHeader
end if
next
end if
next
end if
if (Found = false) then
WScript.echo "The search term " & Contains & " was not found!"
end if
end if
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Script to Import a bunch of IP addresses to the ReplayIpList
' and IPSecurity
' (c)vijaysk@microsoft.com
' blogs.msdn.com/vijaysk
'
'
' USAGE : cscript ImportRelayList.vbs <PathToRelayIP.txt> <PathToSecurityIP.txt>
' PREREQUISITE : This script needs RelayIp.txt and SecurityIp.txt in the same folder or
' the path parameters must be used on the command line to specify the locations.
' FORMAT for *Ip.txt files: Each line should be IP,MASK ex. 127.0.0.1,255.255.255.255
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
Dim objSMTP,objRelayIpList,objCurrentList,objIP,objFSO,objTextFile,count,newIpList(),inputOption,IPTxtPath
Set objSMTP = GetObject("IIS://localhost/smtpsvc/1")
Set objRelayIpList = objSMTP.Get("RelayIpList")
'objRelayIpList is of type IIsIPSecuritySetting http://msdn.microsoft.com/en-us/library/ms525725.aspx
If Wscript.Arguments.Count <> 0 Then
IPTxtPath = Wscript.Arguments(0)
ELSE
IPTxtPath = "ip.txt"
End If
Wscript.Echo "============================================"
Wscript.Echo "CURRENT SETTINGS"
Wscript.Echo "================"
Wscript.Echo " "
Wscript.Echo "Computer(s) that may relay through this virtual server."
Wscript.Echo " "
' GrantByDefault returns 0 when "only the list below" is set (false) and -1 when all except the list below is set(true)
If objRelayIpList.GrantByDefault = true Then
Wscript.Echo "All except the list below :"
objCurrentList = objRelayIpList.IPDeny
Else
Wscript.Echo "Only the list below :"
objCurrentList = objRelayIpList.IPGrant
End If
count = 0
For Each objIP in objCurrentList
Wscript.Echo objIP
count = count + 1
Next
If count = 0 Then
Wscript.Echo "*NIL*"
End If
Wscript.Echo "============================================"
Wscript.Echo " "
Wscript.Echo "Replacing ReplayIpList with the IP address(es) from the ip.txt file."
Wscript.Echo " "
'Hard coding the script to always use the allow option unattended installation
inputOption = "a"
Do While Not((inputOption = "a") Or (inputOption = "d") Or (inputOption = "x") )
Wscript.Echo "ENTER "
Wscript.Echo "A to add to Allow List (Only the list below)"
Wscript.Echo "D to add to Deny List (All except the list below)"
Wscript.Echo "X Exit without making changes"
Wscript.Echo " "
inputOption = lcase(trim(Wscript.StdIn.ReadLine))
Loop
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(IPTxtPath) Then
Set objTextFile = objFSO.OpenTextFile(IPTxtPath,1)
count = 0
Do Until objTextFile.AtEndOfStream
Redim Preserve newIpList(count)
newIpList(count) = objTextFile.Readline
count = count + 1
Loop
objTextFile.Close
'For each objIP in newIpList
' Wscript.Echo objIP
'Next
Wscript.Echo " "
Select Case inputOption
Case "a"
objRelayIpList.GrantByDefault = false
objRelayIpList.IpGrant = newIpList
Wscript.Echo "SET " & count &" address(es) to Allow List"
Case "d"
objRelayIpList.GrantByDefault = true
objRelayIpList.IpDeny = newIpList
Wscript.Echo "SET " & count &" address(es) to Deny List"
Case "x"
Wscript.Echo "Exiting without making changes"
Wscript.Echo "============================================"
Wscript.Quit
End Select
objSMTP.Put "RelayIpList",objRelayIpList
objSMTP.SetInfo
Wscript.Echo " "
Wscript.Echo "============================================"
Else
Wscript.Echo "Please create a file ip.txt that contains the list of IP address(es)"
Wscript.Echo "FORMAT : Each Line should be IP,MASK "
Wscript.Echo "EX : 127.0.0.1,255.255.255.255"
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Script to Import a bunch of IP addresses to the ReplayIpList '
' '
' (c)vijaysk@microsoft.com '
' blogs.msdn.com/vijaysk '
' '
' '
' USAGE : cscript ImportRelayList.vbs '
' PREREQUISITE : This script needs ip.txt in the same folder. '
' Store your IP addresses in ip.txt FORMAT: Each line should be IP,MASK '
' '
' '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Script to Import a bunch of IP addresses to the ReplayIpList
' and IPSecurity
' (c)vijaysk@microsoft.com
' blogs.msdn.com/vijaysk
'
'
' USAGE : cscript ImportRelayList.vbs <PathToRelayIP.txt> <PathToSecurityIP.txt>
' PREREQUISITE : This script needs RelayIp.txt and SecurityIp.txt in the same folder or
' the path parameters must be used on the command line to specify the locations.
' FORMAT for *Ip.txt files: Each line should be IP,MASK ex. 127.0.0.1,255.255.255.255
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
Dim objSMTP,objIpSecurity,objCurrentList,objIP,objFSO,objTextFile,count,newIpList(),inputOption,IPTxtPath
Set objSMTP = GetObject("IIS://localhost/smtpsvc/1")
Set objIpSecurity = objSMTP.Get("IPSecurity")
'objIpSecurity is of type IIsIPSecuritySetting http://msdn.microsoft.com/en-us/library/ms525725.aspx
If Wscript.Arguments.Count <> 0 Then
IPTxtPath = Wscript.Arguments(0)
ELSE
IPTxtPath = "ip.txt"
End If
Wscript.Echo "============================================"
Wscript.Echo "CURRENT SETTINGS"
Wscript.Echo "================"
Wscript.Echo " "
Wscript.Echo "Computer(s) that may connect to this virtual server."
Wscript.Echo " "
' GrantByDefault returns 0 when "only the list below" is set (false) and -1 when all except the list below is set(true)
If objIpSecurity.GrantByDefault = true Then
Wscript.Echo "All except the list below :"
objCurrentList = objIpSecurity.IPDeny
Else
Wscript.Echo "Only the list below :"
objCurrentList = objIpSecurity.IPGrant
End If
count = 0
For Each objIP in objCurrentList
Wscript.Echo objIP
count = count + 1
Next
If count = 0 Then
Wscript.Echo "*NIL*"
End If
Wscript.Echo "============================================"
Wscript.Echo " "
Wscript.Echo "Replacing IPSecurity with the IP address(es) from the " & IPTxtPath & " file."
Wscript.Echo " "
'Hard coding the script to always use the allow option unattended installation
inputOption = "a"
Do While Not((inputOption = "a") Or (inputOption = "d") Or (inputOption = "x") )
Wscript.Echo "ENTER "
Wscript.Echo "A to add to Allow List (Only the list below)"
Wscript.Echo "D to add to Deny List (All except the list below)"
Wscript.Echo "X Exit without making changes"
Wscript.Echo " "
inputOption = lcase(trim(Wscript.StdIn.ReadLine))
Loop
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(IPTxtPath) Then
Set objTextFile = objFSO.OpenTextFile(IPTxtPath,1)
count = 0
Do Until objTextFile.AtEndOfStream
Redim Preserve newIpList(count)
newIpList(count) = objTextFile.Readline
count = count + 1
Loop
objTextFile.Close
'For each objIP in newIpList
' Wscript.Echo objIP
'Next
Wscript.Echo " "
Select Case inputOption
Case "a"
objIpSecurity.GrantByDefault = false
objIpSecurity.IpGrant = newIpList
Wscript.Echo "SET " & count &" address(es) to Allow List"
Case "d"
objIpSecurity.GrantByDefault = true
objIpSecurity.IpDeny = newIpList
Wscript.Echo "SET " & count &" address(es) to Deny List"
Case "x"
Wscript.Echo "Exiting without making changes"
Wscript.Echo "============================================"
Wscript.Quit
End Select
objSMTP.Put "IPSecurity",objIpSecurity
objSMTP.SetInfo
Wscript.Echo " "
Wscript.Echo "============================================"
Else
Wscript.Echo "Please create a file ip.txt that contains the list of IP address(es)"
Wscript.Echo "FORMAT : Each Line should be IP,MASK "
Wscript.Echo "EX : 127.0.0.1,255.255.255.255"
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Script to Import a bunch of IP addresses to the ReplayIpList '
' '
' (c)vijaysk@microsoft.com '
' blogs.msdn.com/vijaysk '
' '
' '
' USAGE : cscript ImportRelayList.vbs '
' PREREQUISITE : This script needs ip.txt in the same folder. '
' Store your IP addresses in ip.txt FORMAT: Each line should be IP,MASK '
' '
' '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Theme: Rubric. Blog at WordPress.com.