Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all 15028 articles
Browse latest View live

Add-WindowsPackage The system cannot find the file specified

$
0
0

Hello Scripters,

I am attempting to apply windows updates to a vhdx using add-windows package, in reference to the following article:

http://www.server-talk.eu/2015/01/19/virtual-machine-template-patching/

When I run the script within my test environment I get "The system cannot find the file specified." for every file it finds on my wsus server.  I have verified the file(s) exist and are accessible.  I have also moved the update files to my local drive and rerun the test, same issue.

To verify my image is not the problem, I have mounted the vhdx, run the following code against it, and then unmounted and saved the vhdx:

dism /image:c:users\<redacted>\desktop\templatepatching /cleanup-image /restorehealth

What are my next steps?  Test code below:

# Path to VHD(x) VM Template
#$VMTemplate = "\\INFRA01.backslash.li\MSSCVMMLibrary\VHDs\TP_WS2012R2_disk_1.vhdx"
$VMTemplate = "C:\users\<redacted>\desktop\VMMTesting\WTAWIN2K12R2STD-40GB.vhdx"
$TempDirectory = "C:\Users\<redacted>\Desktop\TemplatePatching"
Mount-WindowsImage -ImagePath $VMTemplate -Path $TempDirectory -Index 1

# Get all available Updates from WSUS
$WsusServer = "updateserver.contoso.com"
$UpdatelistCab = Get-ChildItem -Path "\\$WsusServer\WsusContent" -Include *.cab -Recurse -File
$UpdatelistMsu = Get-ChildItem -Path "\\$WsusServer\WsusContent" -Include *.msu –Recurse -File

Foreach ($UpdateCab in $UpdatelistCab)
{$UpdateReady = Get-WindowsPackage -PackagePath $UpdateCab -Path $TempDirectory
If ($UpdateReady.PackageState -eq "installed")
	{Write-Output $UpdateReady.PackageName "is already installed"}
Elseif ($UpdateReady.Applicable -eq "true")
	{Add-WindowsPackage -PackagePath $Updatecab.Directory -Path $TempDirectory}}
ForEach ($UpdateMsu in $UpdatelistMsu)
	{Add-WindowsPackage -PackagePath $UpdateMsu.Directory -Path $TempDirectory}

# Dismount the VHD / VHDX
Dismount-WindowsImage -Path $TempDirectory -Save
#DisMount-WindowsImage -Path $TempDirectory -Discard


WQL Script for SCCM using the INNER JOIN function

$
0
0

Hola

I am trying to build a custom query to pull the following information into a custom Node in the SCCM 2012 Admin Console using .AdminUI.ConsoleBuilder.exe

The data that i would like is found in 2 different classes. First:

From SMS_G_System_COMPUTER_SYSTEM

Name, Manufacturer, and Model

The second class that i would like data from is SMS_G_System_SYSTEM_ENCLOSURE including the following properties:

SerialNumber

I posted in another forum ( Post found here )about the same thing, and got an answer to :

"Just like any query, you need to use a join to combine info from multiple tables/classes."

Unfortunately i don't have the faintest clue as to how to do that using "join" or "Inner Join". Can someone please provide me a link\tutorial\post\software that will help me construct this, as to how to go about this?

Set-ACL giving permission denied error for modifying security permission of Computer account

$
0
0

Hello Guys.

I'm new to this forum. Please help me in resolving the scripting issue

Scenario: I have created a computer account in our domain. Using ADAC I can add 'special user ID' in security ACL to join that machine in domain. But when I try to do the same thing using PowerShell its giving access denied for the set-acl cmdlts.

Note: I'm the owner of the computer account.

My script:

$mycomputeradmins = "_desktop_admin_pune"
$computername     = "PUNITP1111D"
$usersid = (Get-ADUser $mycomputeradmins ).sid
$ou = "OU=Desktops,OU=Computers,OU=ITP,.....,DC=com"
New-ADComputer -path $ou $computername
$mycomputer = Get-ADComputer $computername
$dn = $mycomputer.distinguishedname
$acl = Get-Acl "AD:$dn"

$rule1 = New-Object System.DirectoryServices.ActiveDirectoryAccessRule ($usersid,'DeleteTree, ExtendedRight, Delete, GenericRead', 'Allow', [GUID]'00000000-0000-0000-0000-000000000000')

$rule2 = New-Object System.DirectoryServices.ActiveDirectoryAccessRule ($usersid,'WriteProperty', 'Allow', [GUID]'4c164200-20c0-11d0-a768-00aa006e0529')

$rule3 = New-Object System.DirectoryServices.ActiveDirectoryAccessRule ($usersid,'Self', 'Allow', [GUID]'f3a64788-5306-11d1-a9c5-0000f80367c1')

$rule4 = New-Object System.DirectoryServices.ActiveDirectoryAccessRule ($usersid,'Self', 'Allow', [GUID]'72e39547-7b18-11d1-adef-00c04fd8d5cd')

$rule5 = New-Object System.DirectoryServices.ActiveDirectoryAccessRule ($usersid,'WriteProperty', 'Allow', [GUID]'3e0abfd0-126a-11d0-a060-00aa006c33ed')

$rule6 = New-Object System.DirectoryServices.ActiveDirectoryAccessRule ($usersid,'WriteProperty', 'Allow', [GUID]'bf967953-0de6-11d0-a285-00aa003049e2')

$rule7 = New-Object System.DirectoryServices.ActiveDirectoryAccessRule ($usersid,'Extendedright', 'Allow', [GUID]'5f202010-79a5-11d0-9020-00c04fc2d4cf')

$rule8 = New-Object System.DirectoryServices.ActiveDirectoryAccessRule ($usersid,'WriteProperty', 'Allow', [GUID]'bf967953-0de6-11d0-a285-00aa003049e2')

$mycomputeracl.AddAccessRule($rule1)

$mycomputeracl.AddAccessRule($rule2)

$mycomputeracl.AddAccessRule($rule3)

$mycomputeracl.AddAccessRule($rule4)

$mycomputeracl.AddAccessRule($rule5)

$mycomputeracl.AddAccessRule($rule6)

$mycomputeracl.AddAccessRule($rule7)

$mycomputeracl.AddAccessRule($rule8)

$acl | Set-Acl "AD:$dn"
If ($? -eq '$true') {
Write-Host "computer account created successfully" } else {
$error[0] }
Error:

PS C:\windows\system32> D:\Scripting\Powershell\Computer_New.ps1
Set-Acl : Access is denied
At D:\Scripting\Powershell\Computer_New.ps1:42 char:8+ $acl | Set-Acl "AD:$dn"+        ~~~~~~~~~~~~~~~~+ CategoryInfo          : PermissionDenied: (CN=PUNITP1111D,...=infosys,DC=com:String) [Set-Acl], UnauthorizedAccessException+ FullyQualifiedErrorId : ADProvider:SetSecurityDescriptor:AccessDenied,Microsoft.PowerShell.Commands.SetAclCommand

I know something is wrong/missing in this script.

Please suggest me and let me know if anything else needed from my side to quickly resolve this issue.

Thanks in Advance

Mahesh Swami

Retrieving AD Data in VBA

$
0
0

I have a number of needs to grab AD data via VBA.  I have found plenty of examples for doing this, but have not been able to find the full syntax/structure for the command text.  Most of the pieces are quite clear in https://social.technet.microsoft.com/Forums/scriptcenter/en-US/14525416-8f52-46f5-b077-af58bc90106f/vba-query-of-ad-using-ldap?forum=ITCG

What is not is when structuring the command text, the example is "<LDAP://dc=icts,dc=co,dc=uk>;;name;subtree".  This implies that there are four components.  The first is the path into AD, and the third is the fields.  I have no idea what the second is, nor do I have a real good idea of the options for the fourth.

I'd be most grateful for any clarification that can be provided.

TIA,

John

Get-QADUser -Filter Conditions

$
0
0

Hello,

I am running a script which relies a specific parameters over accounts set in AD, and i'm struggling to add an AND condition on the end of a multiple OR condition.

Get-QADUser -LdapFilter "(|(Name=Peter) (Department=Sales) (Building=None) (AccountIsDisabled=false) )

It works, however they are all OR's. I need the final "AccountIsDisabled" to be in addition to one of the 3 beforehand, so they either need to have a name Peter, Department Sales or Building None, but in any event they should not be Disabled.

Any Ideas?

Thanks

Powershell, regex, pick parts of a share?

$
0
0

 Hi,

I'd like to make a function which has an input of a share. I'd like to select Publisher, Application, ApplicationVersion as variable
 I know you can use the split function but how do I build the regex so I can ignore the first \\ then select part 6 for $Publisher etc?

To clarify: something like this:

$Share = "\\ourshare\folder\software\App-V\X64\Publisher\Application\ApplicationVersion\PackageVersion\Folder\"
$Publisher = ($Share -split (\\))[6]
$Application = ($Share -split (\\))[7]

...



 Please advise.
 J.


Jan Hoedt

Move-Item : The process cannot access the file because it is being used by another process.

$
0
0

Hi,

I get the above error when running my code.  Is there anyway to close it or is there a work around (I'm dealing with 1000's of files?

Thanks,

Bernard

Copy A Portion of One AD Attribute to Another

$
0
0

So my employer has asked me to populate the AD attribute "extensionName" (currently empty) with the last 4 digits of the already filled in "telephoneNumber" attribute in AD.  He only wants it done in our home office which is easy enough because all the numbers start with the same area code and suffix.

This is what I have so far... (obviously the area code and suffix is fictional)

get-adobject -filter {telephoneNumber -like"555-555-*"}   (If I put a select-object cmdlet on the end it pipes out the relevant phone numbers I need to copy to the extensionName field)

Please help me  figure out the next step to copy just the last 4 digits of the "telephoneNumber"attribute and put it in the "extensionName" field.  Been racking my brain trying to figure this out.


Tab-completion of command based upon a folderlist?

$
0
0

Hi,

Please see this post:

https://social.technet.microsoft.com/Forums/en-US/a42527e9-7a0f-42e2-8536-a2a0ca16136a/generate-
folderlist-of-sublevels?forum=ITCG

$form_Load = {

     $root = '\\share\packages\'
     $f = Get-ChildItem $root -Directory | Sort-Object
     $combobox1.DataSource = [system.collections.arraylist]@($f)
     $combobox1.DisplayMember = 'Basename'
     $combobox1.SelectedIndex=10
 }

 $combobox1_SelectedIndexChanged = {
     if ($f = Get-ChildItem $combobox1.SelectedItem.FullName -Directory) {
         $combobox2.DataSource = [collections.arraylist]@($f)
         $combobox2.DisplayMember = 'Basename'
     } else {
         $combobox2.DataSource=$null   
     }
 }


Can this command also achieved by commandline? So what I would like to do, is have a command

Deploy-AppVPackage -Publisher Microsoft -Name Office -Version 2010
in which Microsoft, Office and 2010 can be filled in via tab-completion.

So tab completion of -Publisher (in my example Microsoft) should come from:
$f = Get-ChildItem $root -Directory | Sort-Object

tab comletion of -Name (in my example Office) should come from what is selected in -Publisher (in my example Microsoft) = folders underneath Microsoft etc

Folderstructure share =

*Microsoft
**Office
***2010
***VisualBasic
*Mindjet
**MindManager
***11.0

Please advise.
J.


Jan Hoedt

Add-CMDeploymentType : Specified cast is not valid.

$
0
0

Hi,

I'm trying to write a Powershell-script to deploy software in SCCM 2012.

Everything works fine but the Add-CMDeploymtenType, there I got this error:

Creating Deployment Type Microsoft - Office - 2010 (1.0) - X64
WARNING: The parameter 'AutoIdentifyFromInstallationFile' has been deprecated from this parameter set and may be removed in a future release.
WARNING: Unexpected site version '-1' was detected. Defaulting to latest Application Management SDK API set. This may introduce cmdlet incompatibilities.
Add-CMDeploymentType : Specified cast is not valid.

This is my command:

Add-CMDeploymentType -ApplicationName $AppVName -DeploymentTypeName $DeploymentTypeName -AppV5xInstaller -InstallationFileLocation $InstallFileLocation -AutoIdentifyFromInstallationFile -ForceForUnknownPublisher $true -AddRequirement $oDTRule  

Note: I updated the Powershell to version 4.0 on Windows 2012 R2 and updated the lateste SCCM CMDlets due to an issue (which I also posted in the forum).

Please advise.
J.


Jan Hoedt


Dump Email from Service Account

$
0
0

Hi

I have a service account, as well as my default Outlook email account. I need to run a powershell script that will pull the data from that account's inbox, not from my default inbox, and save the results to a text file. I've found/mashed a script I found online that does the trick for my inbox, but I don't know how to change the inbox setting. Any help would be much appreciated.

See my script below

Thanks

PS H:\> $olFolderInbox = 6
$outlook = new-object -com outlook.application;
$ns = $outlook.GetNameSpace("MAPI");
$inbox = $ns.GetDefaultFolder($olFolderInbox)
$targetfolder = $inbox.Folders
$inbox.items | foreach {
if($_.subject -match "Rerun") {$_.body | out-file -Append -encoding ASCII EmailDump.txt} 

Batch file for extracting part of a file name and renaming it accordingly

$
0
0

I have a large number of files that I need to rename using part of the original file name. I would like to create a batch file to extract this information and rename the files. 

Examples:

Originals:

ag_record_74_136_17604878902_2728622.wav

ag_record_76_136_12527728500_2730331.wav

ag_record_76_136_12522233874_2863170.wav

What I would like them to come out as (respectively)

7604878902.wav

2527728500.wav

2522233874.wav

Could someone please help with this. Thank you in advance.

Powershell to Copy folders to another location based on text file

$
0
0

Hi All,

Hope I can find some help. I have a server with Tier-1 storage and Tire-2 storage. I have a text file with a very large list of folders that I need to copy to Tire-2 storage. I tried this command below, but it crashed the server, unknown why. I replaced server path with SOURCE/DESTINATION

for /f %i in ("Snap2014-429K.txt") do robocopy /COPYALL /NJH /NJS /Log+:LOGFILE.log /V /E /NP \\SOURCE\%i \\DESTINATION\%i

Does anyone have a powershell script that can perform the same function? Any help is appreciated.

-Bryan

VBS Script Loop While

$
0
0

Hi Guys and Girls,

I need some help here, I am trying to add functionality into the following VBS script so that if the user does not input a b or c it tells them and then loops back to the same sub until a b or c is selected.  I am a complete novice at vbs and am studying it as part of my course for college but this particular script is for another course, I have added a Do While statement with a counter of 3 so the user has 3 attempts to put the right answer and I can get it to run but it loops the invalid message box if i add a loop and case in it loops the message box for alert and then the 3 attempts box then moves to the next sub.

Here is the snippet of code for the sub, any help directions pointers would be much appreciated. This is for my troubleshooting course and I identified it as an error so would like to correct it and learn how to loop a sub properly

    Sub userSelection()
        Select Case choice
            Case = "a"
                price = 5.9
            Case "b"
                price = 11.3
            Case "c"
                price = 6.95
            Case Else
                MsgBox("You have made an invalid choice", vbOKOnly, "Invalid Selection")
        End Select
        counter = 3
        Do
            While counter > 0
                counter = counter - 1
                MsgBox("You have made" counter "incorrect attemps please retry", vbOKOnly, "Error Retry")
            End While
            Exit Do
        Loop Until counter = 0
    End Sub

Thanks so much

Jordan


Creating a conditional matrix in VBScript

$
0
0

Hey all! I am trying to find a solution to a challenge that would land me a complicated If / Then -jungle if implemented in that traditional, simple way.

So - I have a VBScript -based scripting interface in an application that controls Bug management in software development. I have a conditional set of properties for a number of categorization fields for a reported Bug that should change their requiredness based on the Bug flow through it's lifecycle.

For an example, a Bug in the state of NEW will have A, B and C categorization fields as required to be filled. When the bug changes (fast forward) to Fixed, I would have to have A, B, C, X and Y required. However, if the Bug goes from New -> Submitted -> Rejected, I would need to have A, B, C, D and E required. There are a number of statuses for the Bug and almost each one has a different set of required fields.

I am exploring scripting Dictionaries as a solution for this dilemma, but I cannot get my head around how I could implement this with them. Maybe there is another way?

Any help in this matter would be greatly appreciated! Thanks in advance, wishing a nice weekend to everyone!

~t


to check Symantec endpoint protection is installed on a server or not.

$
0
0

I have list of 100 server in my domain, but remoting is not enable on any server.

I need to check whether Symantec client is installed on each server and want  to know the installed client version.

kindly help.

Can't tell the difference between and AD user and a contact

$
0
0

Hey Scripting gods!

With vbs, I know how do you get both users and contacts, but how can you distinguish between a user and a contact using vbs?

Thanks,
John


jj

Profiles on a Host and Their AD Membership

$
0
0

Hi All,

I am trying to write a script that will:

1. Get domain profiles on a remote machine and write them profile names in a file
2. Get those profiles' AD group membership and write that to a file.

I have the various bits and pieces needed, but got stuck at connecting it all together.

I found the following for getting profiles on a predefined machine and getting the usernames.

[cmdletbinding()]
param (
[parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[string[]]$ComputerName = $env:computername
)

foreach ($Computer in $ComputerName) {
 $Profiles = Get-WmiObject -Class Win32_UserProfile -Computer $Computer -ea 0
 foreach ($profile in $profiles) {
  try {
      $objSID = New-Object System.Security.Principal.SecurityIdentifier($profile.sid)
      $objuser = $objsid.Translate([System.Security.Principal.NTAccount])
      $objusername = $objuser.value
  } catch {
        $objusername = $profile.sid
  }
  switch($profile.status){
   1 { $profileType="Temporary" }
   2 { $profileType="Roaming" }
   4 { $profileType="Mandatory" }
   8 { $profileType="Corrupted" }
   default { $profileType = "LOCAL" }
  }
  $User = $objUser.Value
    $OutputObj = New-Object -TypeName PSobject
  $OutputObj | Add-Member -MemberType NoteProperty -Name ProfileName -Value $objusername
  $OutputObj

 }
}

To get these profile names written to a file I have another script.:

.\getprofiles.ps1 -ComputerName (Get-Content .\temp\ZZScripts\CN.dat) | Export-Csv .\profiles.csv -NoTypeInformation

The problem is, I have issues getting AD group membership for those profiles written into the file. The first script finds both domain and local profiles, so I thought I'd run a -Replace to remove unneeded information from the output file and run 

(get-aduser $user -Properties MemberOf | select MemberOf).MemberOf | % {$_.split(",")[0].replace("CN=","")} | Export-Csv .\UserPrivs.csv -Notypeinformation

Can you please help me get all of this come together?

How can I set SHARE permissions using powershell v2.0?

$
0
0

I have been looking all over the place but can't seem to find the answer for this.

I am working on a script that will set the SYSVOL and NETLOGON share permissions on our domain controllers.

Our domain controllers are W2K8R2 and upgrading to powershell 2.0 to the latest is not an option.

I have looked all over the place but everything I find is for setting NTFS permissions and not SHARE permissions.

NET SHARE looked promising at first but that only lets me set permissions when it create a new share.

From the research I have done it seems like this maybe possible through WMI calls I just can't seem to find the right one that will actually set permissions on a share..

Basic coding Q. How to take an output from a question further up in a script and inject it back into script further down?

$
0
0

As i am a complete scripting novice this is possibly an easy question for some of you guys/girls out there!

How do i use an outcome from an initial query in a script/batch file to be used or referenced further down the script?

My Idea - to create a batch file to quickly identify/output a wep/wpa code/passphrase of a connected or stored wireless network from a machine using the NETSH WLAN SHOW Profiles command.

Like this:

NETSH WLAN SHOW PROFILES

answer: 'EXAMPLEWIFIPROFILESSID'

NETSH WLAN SHOW PROFILE EXAMPLEWIFIPROFILESSID KEY=CLEAR


if output could also be filtered so it just shows the 'key content' value??

Its how to take the profile name that is a result in the first query, and re-enter it in the second query to save entering it manually......?

Thanks

TR27Lenny


Viewing all 15028 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>