Quantcast
Channel: Windows PowerShell forum
Viewing all 21975 articles
Browse latest View live

convert comma separated value to number

$
0
0

Hi 

I'm trying to send data trough a webcall API and have to send a specific value as number.

						$groupmembers = Get-ADGroupMember -Identity $group.SamAccountName -Recursive
						$members = ""
						foreach ($member in $groupmembers) {
							$currentFlexAssets = (Get-ITGlueFlexibleAssets -filter_flexible_asset_type_id $Users_flex_asset_id -filter_organization_id $api__org_id -filter_name $member.name)
							$value = $currentFlexAssets.data.attributes.'resource-url'
							$Split = $value.split("{/}")
							$members += $Split[7] + ", "
						}
						$members = $members.TrimEnd(", ")
						$members
						$members2 = 1715837278175409, 1715837265510575, 1715837270687920



members is the tag field build up from the string split and comma separted.

members2 is the tag field which I've typed myself for testing

memberstext are the same values but then send to a text field:

Group name

GG_Inkoop

Members
<small style="box-sizing:border-box;font-size:11.9px;"> Piet van der Ven</small>
members2
  •  Henk de Vries
  •  Kees Jansma
  •  Piet van der Ven
memberstext

1715837278175409, 1715837270687920

memberstext2

1715837278175409

1715837265510575

1715837270687920


$api__body = @{
        type = "flexible_assets"
        attributes = @{
            organization_id = $api__org_id
            flexible_asset_type_id = $api_config.flexible_asset_type_id
            traits = @{
				$api__key_name_group_name = $groupname
				$api__key_name_members = $members
				$api__key_name_members2 = $members2
				$api__key_name_memberstext = $memberstext
				$api__key_name_memberstext2 = $memberstext2
            }
        }
    }



I've tried string to integer but the value is to long 

Cannot convert value "1715837270687920" to type "System.Int32". Error: "Value was either too large or too small for an Int32

looking at values I've seen the brackets around members2 

traits                         {members2, memberstext, members, memberstext2...}
members2                       {1715837278175409, 1715837265510575, 1715837270687920}
memberstext                    1715837278175409, 1715837265510575, 1715837270687920
members                        1715837278175409, 1715837265510575, 1715837270687920
memberstext2                   {1715837278175409, 1715837265510575, 1715837270687920}

But doing $members = "{" + $members.TrimEnd(", ") + "}" results in an error from the webserver saying the value is wrong

I'm a bit stuck on this one has someone got a solution?



Modifying who can add/remove GPO links on an OU, using powershell

$
0
0

Hello there,

I'm trying to figure out a way to allow a security group to be able to add/remove GPO links on a OU, using powershell. It's easy using the delegation tab in gpedit.

I can see the properties "read gPOtions" and "Write gPOtions" is being set on an object (user or group), when modified through gpedit. But I don't know how to set those properties using powershell..

I've searched, and the only thing I can find is how to modify permissions with powershell, on the GPO it self,. but that's not what I am interested in.

Any help is appreciated 


Best Regards,

Jesper Vindum, Denmark

Systems Administrator

Help the forum: Monitor(alert) your threads and vote helpful replies or mark them as answer, if it helps solving your problem.

Powershell - Read data from individual excel cell and place this data into a variable

$
0
0

I'm trying to read data from an individual excel cell, based on the input of a serial number the user enters previously. Below is my code:

#create excel object
$excel = New-Object -ComObject Excel.Application
# open Excel file
$workbook = $excel.Workbooks.Open("C:\Users\NAME\Documents\Reports\Database.xlsx")
$sheet = $workbook.ActiveSheet
$column = 2
$row = $serial
$info = $sheet.cells.Item($column, $row).Text
Write-Output($info)

When this runs I receive the following error:

Exception from HRESULT: 0x800A03EC
At C:\Users\NAME\Documents\Reports\report_script-v0.3.ps1:27 char:1
+ $info = $sheet.cells.Item($column, $row).Text
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

issue in using foreach loop and break , unable to count the *.temp file within a subfolder

$
0
0

i want to loop through subfolders and fetch the file name with a .temp extension and when i use foreach loop, it didnt work.

how to use foreach to iterate through subfolders and find the existence of a .temp file 

$folders = get-childitem - directory -path $mysharedfolder

foreach($folder in $folders)

{

#found the file with *.temp then break / exit the loop

}


Das


Deployment package using Powershell to run in multiple servers

$
0
0

Hi .

I am using a command line prompt, to install my application on multiple server, after logging into each server.

what the existing script does is  -  Navigate to a specific path using command prompt , execute two commands to install the application. This same step I need to perform in multiple servers, by first logging into the server, opening command prompt, using cd to navigate to the directory and run those commands.   

I have created a configuration XML file, which contains all the information to be executed . Is there a way to achieve this in powershell without logging into the server and executing the command ? My config file is as below:

<?xml version="1.0"?><Config>   <Action Name="Deploy"><CommandPath>path to navigate</CommandPath><PackagePath>path of Application package</PackagePath><ModelName>Name of model to be deployed</ModelName><ServiceName>Name of Service</ServiceName><DeploymentServer><Server Name = 'Server1'></Server><Server Name = 'Server2'></Server></DeploymentServer></Action><Action Name="Update"><CommandPath>path to navigate</CommandPath><PackagePath>path of Application package</PackagePath><ModelName>Name of model to be updated</ModelName><ServiceName>Name of Service</ServiceName><DeploymentServer><Server Name = 'Server1'></Server><Server Name = 'Server2'></Server></DeploymentServer></Action>     </Config>

I want to get the type of installation -  deploy or update from user and then update the commands.

I am aware of reading the data from user , but need the help to run the other commands by reading from the config xml and exceuting in the servers defined in the DeploymentServer tag.

How to achieve this deployment in multiple servers using Powershell ?

Thanks


Powershell Command Query

$
0
0

Need a command that will run an extract from a list of user accounts in AD, and tell us what OU they are in.

Is this possible

Powershell Test-Path if Exist Exit Script

$
0
0

Hi 

I require some assistance please. 

I am using a script which i found online, to redirect the Downloads folder to OneDrive.  I want to be able to run the script via login script, add a registry and then check the registry key when the script is run again.  If the reg key exists the script should stop and exit.  Currently with the test i have, the script continues to run even when the registry key exists.

Is there someone out there who could assist me in rectifying this?

# Work in progress! 
# Derived from http://stackoverflow.com/questions/25709398/set-location-of-special-folders-with-powershell<#
.SYNOPSIS
    Sets a known folder's path using SHSetKnownFolderPath.
.PARAMETER Folder
    The known folder whose path to set.
.PARAMETER Path
    The path.
#>
function Set-KnownFolderPath {
    Param (
            [Parameter(Mandatory = $true)]
            [ValidateSet('AddNewPrograms', 'AdminTools', 'AppUpdates', 'CDBurning', 'ChangeRemovePrograms', 'CommonAdminTools', 'CommonOEMLinks', 'CommonPrograms', 'CommonStartMenu', 'CommonStartup', 'CommonTemplates', 'ComputerFolder', 'ConflictFolder', 'ConnectionsFolder', 'Contacts', 'ControlPanelFolder', 'Cookies', 'Desktop', 'Documents', 'Downloads', 'Favorites', 'Fonts', 'Games', 'GameTasks', 'History', 'InternetCache', 'InternetFolder', 'Links', 'LocalAppData', 'LocalAppDataLow', 'LocalizedResourcesDir', 'Music', 'NetHood', 'NetworkFolder', 'OriginalImages', 'PhotoAlbums', 'Pictures', 'Playlists', 'PrintersFolder', 'PrintHood', 'Profile', 'ProgramData', 'ProgramFiles', 'ProgramFilesX64', 'ProgramFilesX86', 'ProgramFilesCommon', 'ProgramFilesCommonX64', 'ProgramFilesCommonX86', 'Programs', 'Public', 'PublicDesktop', 'PublicDocuments', 'PublicDownloads', 'PublicGameTasks', 'PublicMusic', 'PublicPictures', 'PublicVideos', 'QuickLaunch', 'Recent', 'RecycleBinFolder', 'ResourceDir', 'RoamingAppData', 'SampleMusic', 'SamplePictures', 'SamplePlaylists', 'SampleVideos', 'SavedGames', 'SavedSearches', 'SEARCH_CSC', 'SEARCH_MAPI', 'SearchHome', 'SendTo', 'SidebarDefaultParts', 'SidebarParts', 'StartMenu', 'Startup', 'SyncManagerFolder', 'SyncResultsFolder', 'SyncSetupFolder', 'System', 'SystemX86', 'Templates', 'TreeProperties', 'UserProfiles', 'UsersFiles', 'Videos', 'Windows')]
            [string]$KnownFolder,

            [Parameter(Mandatory = $true)]
            [string]$Path
    )

    # Define known folder GUIDs
    $KnownFolders = @{
        'AddNewPrograms' = 'de61d971-5ebc-4f02-a3a9-6c82895e5c04';
        'AdminTools' = '724EF170-A42D-4FEF-9F26-B60E846FBA4F';
        'AppUpdates' = 'a305ce99-f527-492b-8b1a-7e76fa98d6e4';
        'CDBurning' = '9E52AB10-F80D-49DF-ACB8-4330F5687855';
        'ChangeRemovePrograms' = 'df7266ac-9274-4867-8d55-3bd661de872d';
        'CommonAdminTools' = 'D0384E7D-BAC3-4797-8F14-CBA229B392B5';
        'CommonOEMLinks' = 'C1BAE2D0-10DF-4334-BEDD-7AA20B227A9D';
        'CommonPrograms' = '0139D44E-6AFE-49F2-8690-3DAFCAE6FFB8';
        'CommonStartMenu' = 'A4115719-D62E-491D-AA7C-E74B8BE3B067';
        'CommonStartup' = '82A5EA35-D9CD-47C5-9629-E15D2F714E6E';
        'CommonTemplates' = 'B94237E7-57AC-4347-9151-B08C6C32D1F7';
        'ComputerFolder' = '0AC0837C-BBF8-452A-850D-79D08E667CA7';
        'ConflictFolder' = '4bfefb45-347d-4006-a5be-ac0cb0567192';
        'ConnectionsFolder' = '6F0CD92B-2E97-45D1-88FF-B0D186B8DEDD';
        'Contacts' = '56784854-C6CB-462b-8169-88E350ACB882';
        'ControlPanelFolder' = '82A74AEB-AEB4-465C-A014-D097EE346D63';
        'Cookies' = '2B0F765D-C0E9-4171-908E-08A611B84FF6';
        'Desktop' = 'B4BFCC3A-DB2C-424C-B029-7FE99A87C641';
        'Documents' = 'FDD39AD0-238F-46AF-ADB4-6C85480369C7';
        'Downloads' = '374DE290-123F-4565-9164-39C4925E467B';
        'Favorites' = '1777F761-68AD-4D8A-87BD-30B759FA33DD';
        'Fonts' = 'FD228CB7-AE11-4AE3-864C-16F3910AB8FE';
        'Games' = 'CAC52C1A-B53D-4edc-92D7-6B2E8AC19434';
        'GameTasks' = '054FAE61-4DD8-4787-80B6-090220C4B700';
        'History' = 'D9DC8A3B-B784-432E-A781-5A1130A75963';
        'InternetCache' = '352481E8-33BE-4251-BA85-6007CAEDCF9D';
        'InternetFolder' = '4D9F7874-4E0C-4904-967B-40B0D20C3E4B';
        'Links' = 'bfb9d5e0-c6a9-404c-b2b2-ae6db6af4968';
        'LocalAppData' = 'F1B32785-6FBA-4FCF-9D55-7B8E7F157091';
        'LocalAppDataLow' = 'A520A1A4-1780-4FF6-BD18-167343C5AF16';
        'LocalizedResourcesDir' = '2A00375E-224C-49DE-B8D1-440DF7EF3DDC';
        'Music' = '4BD8D571-6D19-48D3-BE97-422220080E43';
        'NetHood' = 'C5ABBF53-E17F-4121-8900-86626FC2C973';
        'NetworkFolder' = 'D20BEEC4-5CA8-4905-AE3B-BF251EA09B53';
        'OriginalImages' = '2C36C0AA-5812-4b87-BFD0-4CD0DFB19B39';
        'PhotoAlbums' = '69D2CF90-FC33-4FB7-9A0C-EBB0F0FCB43C';
        'Pictures' = '33E28130-4E1E-4676-835A-98395C3BC3BB';
        'Playlists' = 'DE92C1C7-837F-4F69-A3BB-86E631204A23';
        'PrintersFolder' = '76FC4E2D-D6AD-4519-A663-37BD56068185';
        'PrintHood' = '9274BD8D-CFD1-41C3-B35E-B13F55A758F4';
        'Profile' = '5E6C858F-0E22-4760-9AFE-EA3317B67173';
        'ProgramData' = '62AB5D82-FDC1-4DC3-A9DD-070D1D495D97';
        'ProgramFiles' = '905e63b6-c1bf-494e-b29c-65b732d3d21a';
        'ProgramFilesX64' = '6D809377-6AF0-444b-8957-A3773F02200E';
        'ProgramFilesX86' = '7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E';
        'ProgramFilesCommon' = 'F7F1ED05-9F6D-47A2-AAAE-29D317C6F066';
        'ProgramFilesCommonX64' = '6365D5A7-0F0D-45E5-87F6-0DA56B6A4F7D';
        'ProgramFilesCommonX86' = 'DE974D24-D9C6-4D3E-BF91-F4455120B917';
        'Programs' = 'A77F5D77-2E2B-44C3-A6A2-ABA601054A51';
        'Public' = 'DFDF76A2-C82A-4D63-906A-5644AC457385';
        'PublicDesktop' = 'C4AA340D-F20F-4863-AFEF-F87EF2E6BA25';
        'PublicDocuments' = 'ED4824AF-DCE4-45A8-81E2-FC7965083634';
        'PublicDownloads' = '3D644C9B-1FB8-4f30-9B45-F670235F79C0';
        'PublicGameTasks' = 'DEBF2536-E1A8-4c59-B6A2-414586476AEA';
        'PublicMusic' = '3214FAB5-9757-4298-BB61-92A9DEAA44FF';
        'PublicPictures' = 'B6EBFB86-6907-413C-9AF7-4FC2ABF07CC5';
        'PublicVideos' = '2400183A-6185-49FB-A2D8-4A392A602BA3';
        'QuickLaunch' = '52a4f021-7b75-48a9-9f6b-4b87a210bc8f';
        'Recent' = 'AE50C081-EBD2-438A-8655-8A092E34987A';
        'RecycleBinFolder' = 'B7534046-3ECB-4C18-BE4E-64CD4CB7D6AC';
        'ResourceDir' = '8AD10C31-2ADB-4296-A8F7-E4701232C972';
        'RoamingAppData' = '3EB685DB-65F9-4CF6-A03A-E3EF65729F3D';
        'SampleMusic' = 'B250C668-F57D-4EE1-A63C-290EE7D1AA1F';
        'SamplePictures' = 'C4900540-2379-4C75-844B-64E6FAF8716B';
        'SamplePlaylists' = '15CA69B3-30EE-49C1-ACE1-6B5EC372AFB5';
        'SampleVideos' = '859EAD94-2E85-48AD-A71A-0969CB56A6CD';
        'SavedGames' = '4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4';
        'SavedSearches' = '7d1d3a04-debb-4115-95cf-2f29da2920da';
        'SEARCH_CSC' = 'ee32e446-31ca-4aba-814f-a5ebd2fd6d5e';
        'SEARCH_MAPI' = '98ec0e18-2098-4d44-8644-66979315a281';
        'SearchHome' = '190337d1-b8ca-4121-a639-6d472d16972a';
        'SendTo' = '8983036C-27C0-404B-8F08-102D10DCFD74';
        'SidebarDefaultParts' = '7B396E54-9EC5-4300-BE0A-2482EBAE1A26';
        'SidebarParts' = 'A75D362E-50FC-4fb7-AC2C-A8BEAA314493';
        'StartMenu' = '625B53C3-AB48-4EC1-BA1F-A1EF4146FC19';
        'Startup' = 'B97D20BB-F46A-4C97-BA10-5E3608430854';
        'SyncManagerFolder' = '43668BF8-C14E-49B2-97C9-747784D784B7';
        'SyncResultsFolder' = '289a9a43-be44-4057-a41b-587a76d7e7f9';
        'SyncSetupFolder' = '0F214138-B1D3-4a90-BBA9-27CBC0C5389A';
        'System' = '1AC14E77-02E7-4E5D-B744-2EB1AE5198B7';
        'SystemX86' = 'D65231B0-B2F1-4857-A4CE-A8E7C6EA7D27';
        'Templates' = 'A63293E8-664E-48DB-A079-DF759E0509F7';
        'TreeProperties' = '5b3749ad-b49f-49c1-83eb-15370fbd4882';
        'UserProfiles' = '0762D272-C50A-4BB0-A382-697DCD729B80';
        'UsersFiles' = 'f3ce0f7c-4901-4acc-8648-d5d44b04ef8f';
        'Videos' = '18989B1D-99B5-455B-841C-AB7C74E4DDFC';
        'Windows' = 'F38BF404-1D43-42F2-9305-67DE0B28FC23';
    }

    # Define SHSetKnownFolderPath if it hasn't been defined already
    $Type = ([System.Management.Automation.PSTypeName]'KnownFolders').Type
    if (-not $Type) {
        $Signature = @'
[DllImport("shell32.dll")]
public extern static int SHSetKnownFolderPath(ref Guid folderId, uint flags, IntPtr token, [MarshalAs(UnmanagedType.LPWStr)] string path);
'@
        $Type = Add-Type -MemberDefinition $Signature -Name 'KnownFolders' -Namespace 'SHSetKnownFolderPath' -PassThru
    }

	# Make path, if doesn't exist
	if(!(Test-Path $Path -PathType Container)) {
		New-Item -Path $Path -type Directory -Force
    }

    # Validate the path
    if (Test-Path $Path -PathType Container) {
        # Call SHSetKnownFolderPath
        return $Type::SHSetKnownFolderPath([ref]$KnownFolders[$KnownFolder], 0, 0, $Path)
    } else {
        throw New-Object System.IO.DirectoryNotFoundException "Could not find part of the path $Path."
    }
	# Fix up permissions, if we're still here
	attrib +r $Path

	$Leaf = Split-Path -Path "$Path" -Leaf
	# Move-Item "$HOME\$Leaf\*" $Path
	# rd $HOME\$Leaf -recurse -Force

}
$registryPath = "HKCU:\Software\DimensionData\OneDriveScript"

$Name = "Version"

$value = "1"

IF(!(Test-Path $registryPath))

  {

    New-Item -Path $registryPath -Force | Out-Null

    New-ItemProperty -Path $registryPath -Name $name -Value $value `

    -PropertyType DWORD -Force | Out-Null}

 ELSE {

    New-ItemProperty -Path $registryPath -Name $name -Value $value `

    -PropertyType DWORD -Force | Out-Null}

$ONEDRIVESYNC = "$env:USERPROFILE\OneDrive - EXAMPLE Companu"

# Root Folders
Set-KnownFolderPath -KnownFolder 'Downloads' -Path "$ONEDRIVESYNC\Downloads"





Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\OneDrive -Name EnableADAL -PropertyType DWORD -Value 1
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\OneDrive -Name EnableAllOcsiClients -PropertyType DWORD -Value 1
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\OneDrive -Name DisablePersonalSync -PropertyType DWORD -Value 1 
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\OneDrive -Name DefaultToBusinessFRE -PropertyType DWORD -Value 1
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\OneDrive\Tenants\50d55d1e-ea3b-4856-ae47-aa831f63fdec -Name DisableCustomRoot -PropertyType DWORD -Value 1


start odopen://sync?useremail=$env:USERNAME@example.com

permision Restore Deleted Active Directory computer?

$
0
0

hello,

Peace
I have a script I wrote for computer recovery that is removed from the domain by the following command:

Get-ADObject -Filter 'samaccountname -eq $comp' -IncludeDeletedObjects | ForEach-Object {
  If ($_.Deleted)
  {
    Restore-ADObject $_
  }

But I need special permissions for that 
If I run the command with DomainAdmin I succeed
But I do not want these permissions to have a laser running the script
How delegation privileges am I required to perform this operation in AD


s


How to set audit in Folders and SubFolders

$
0
0

Hi everyone,

I tryed to find something about it on Google, but I couldn't. How can I set audit permissions for folders, subfolders and files by powershell?

Thank you

Powershell Outook advancedsearch. Name of folder for found message.

$
0
0

So i have a very basic search that works really well. However I really need to know where the email is within the mailbox structure (eg \inbox\ebs\sandra) 

$Term  = 'T drive eg the pheno-geno'
$Scope = "'\'"
 

$Outlook = New-Object -ComObject Outlook.Application
$Emails  = $Outlook.AdvancedSearch( $Scope, "urn:schemas:httpmail:textdescription LIKE '%$Term%'", $true)

Start-Sleep -Seconds 10

$Emails.Results | Select-Object -Property subject

how to represent a number (string or INT) as HH:MM:SS

$
0
0

I am parsing a log file and on each line it gives me milliseconds from when the job/log was started as each event occurs. Kind of like below

230 Started doing a thing

450 Started doing a different thing

1150 Started doing a third thing

What I have already done is parsed the file and captured start time and end time and done the math to determine number of milliseconds run time was between events.

Now for my question. if I have a number that represents milliseconds, lets say 21145, how can I (easily) change that to show HH:MM:SS? I believe I need to look at the conditional formatting (like here, https://devblogs.microsoft.com/scripting/use-powershell-and-conditional-formatting-to-format-numbers/) but I don't see what I need or perhaps I don't understand it. Also, the end result doesn't have to be a date time necessarily, it could be a string or integer.

Thank you very much!

User Ids status not coming in output file

$
0
0

HI 

I need one help on below powerhsell script fo output. I am not getting samaccountname in output file and if user already disabled, that status also not coming in outupt.

$attr65= Import-Csv "D:\temp\users_to_be_deprovisioned.csv" | Select-Object -ExpandProperty Name
$date = (Get-Date).ToString("M-d-yyyy")

foreach ($attr65a in $attr65)
{

$user = @{}
$user=get-aduser -Filter '(cAHAttribute65 -eq $attr65a)' -SearchBase "DC=controso, dc=com" -Server "NF01.controso.com" -Properties samaccountname,enabled | Select samaccountname,enabled | Disable-ADAccount -ErrorAction SilentlyContinue

#Set-ADUser -Identity $user.samaccountname -Description "Disabled on $date by the automated deprovisioning script"

if($user.enabled -eq '$True') {$result = "Account not disabled"}

else

{$result = "Account successfully Disabled"}


$array =@{}
$array.add("samaccountname",$user.samaccountname)
$array.add("enabled",$user.enabled)
$array.add("Status", $result)
$out = New-object psobject -property $array | select-object @{N="Samaccountname";E={$_.samaccountname}},@{N="Enabled";E={$_.enabled}},@{N="Status";E={$result}} | Export-Csv .\out.csv -nti
}

"Samaccountname","Enabled","Status"
,,"Account successfully Disabled"

How to release / unlock file from process

$
0
0

Hi there,

I create a bundle *.mpb and import this bundle to Service Manager via

Import-SCSMManagementPack myFile.mpb

If I want to create a new bundle I got the following error-msg:

PS> New-SCSMManagementPackBundle -ManagementPack "myFile.mp" -Resource "my.dll" -Name "myFile.mpb" -Force New-SCSMManagementPackBundle : the process can't access file "C:\myFile.mpb" because the
file is used by an other programm.

So I tried to release the file via handle.exe, but it doesn't work:

$handleOut = & 'D:\SysInternals\handle.exe'

foreach ($line in $handleOut) { 
              
        if ($line -match '\S+\spid:') {
            $exe = $line
            $found = $line -match '.*pid: (\d+).*'
            $spid = $matches[1]
        } 
        if($line -like "*myFile.mpb*"){"$exe - $line"
           $found = $line -match '([a-zA-Z\d]+):.*'
           $handleID = $matches[1]
           Start-Process -NoNewWindow -FilePath "D:\SysInternals\handle.exe" -ArgumentList "-c $($handleID)", "-p $($spid)"
        }  

     }
powershell_ise.exe pid: 12296 \user.name -   6D0: File          C:\myFile.mpb

If I run New-SCSMManagementPackBundle again, same error msg appears. If I kill the process, that mean closing powershell_ise, I can bundle the file again. I don't want to close powershell_ise each time, any suggestion?





Remove OneDrive Powershell

$
0
0

Building a PowerShell script to remove OneDriveSetup from the registry. Each time I attempt to unload the UserHive, I get an "Error: Access is denied."

How am I unable to unload this hive?

##### Remove OneDriveSetup from Registry

$regHKUPath = "HKU:\UserHive\Software\Microsoft\Windows\CurrentVersion\Run"
$element = "C:\Users\Default"

$hideMe = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
$hideMe = reg load HKU\UserHive "$element\NTUSER.DAT"

If (Get-ItemProperty -Path $regHKUPath -Name OneDriveSetup -ErrorAction SilentlyContinue) {

    Write-Output 'OneDriveSetup Value exists'
    Get-Item -Path $regHKUPath | Remove-ItemProperty -Name OneDriveSetup
} Else {
    Write-Output 'OneDriveSetup Value DOES NOT exist'
}

[gc]::Collect()

$hideMe = reg unload HKU\UserHive
$hideMe = Remove-PSDrive -Name HKU

##### End Remove OneDriveSetup from Registry

find and remove similar file

$
0
0

hi,

Like a title i want to find a files similar like this exemple :

ART-20200616102346-1070821.xml

but just the end of the file like that : 1070821.xml

I start to write a script in power shell like that : Get-ChildItem -Path C:\Users\adfransquin\Desktop\test | Where-Object { !$_.PSIsContainer -and $_.name -like "ART**.xml" }

but i don't find how to do for say in powershell to find a files who is the end of their name is similar.

I don't know if what i say it is clerly.

kind regards

adrien


powershell. "Does a folder exist" command? (outlook not exchange)

$
0
0

I'm copying files from various folders in the mailbox to another folder in the same mailbox. (I am an end user, not an exchange admin).

however I need to check if the folder structure I am copying the mailitem  to exists (if not create it).

Done so much so far, but this one simply thing is annoying me (I have a workaround based on "if error, then create the folder structure"

Actually while you are here .... is there any mechanism to recursively create folders? eg \testA\testB\TestC in one go, rather than testa then testb  then test c?

Powershell - Scripting Help with Get-Childitem

$
0
0

Hi,

I have a script that runs every morning at 4am that look to see if two files are located there and then proceeds to restore a SQL Database if these files exists. 

However once every 2 weeks, We get an issue where it fails to find the two files so doesn't restore the database but when i check in the morning the files were created a few hours before the script runs. 

$path = gci "\\WEB\ws\logs" | ? { $_.PSIsContainer } | sort CreationTime -desc | select -f 1

$logs = Get-ChildItem -Path $path.fullname -Recurse -file 
$Filea = $Logs | where-object {$_.Name -eq "SuccessfulDataTransfers.txt"}
$Fileb = $Logs | where-object {$_.Name -eq "VerifiedDataTransfers.txt"}
Try{
If ((test-path -path $Filea.fullname) -and (test-path -Path $Fileb.fullname)) 

{
Write-host "found both"

}
Catch{

$email1 = @{
From = "xxx@xxxx.co.uk"
To = "xxx@xxxx.co.uk"

Subject = " Beta Restore Failed"
SMTPServer = "x.x.x.x"
Body = "Restore - Please check if the files are located as one file is missing"
}
send-mailmessage @email1
}

is anyone able to give me a hand with trying to find out why or suggestions as to why?

Thanks inadvance

SelectedIndexChange on ComboBox not working

$
0
0

Hi,

I've created a GUI for my PowerShell script using WPF in Visual Studio.

I'm trying to capture when a user chooses an item from a combobox and then connect to the vCenter chosen. I am trying to start simple and just have the text box reflect what was chosen. I need this to happen before the user clicks on the button.

I can't for the life of me get it to work. I know I'm doing something wrong, and I'm hoping someone here can point out my error.


#this script automates the decomm process of virtual servers
Add-Type -AssemblyName PresentationFramework
# where is the XAML file?
$XamlPath = "$PSScriptRoot\MainWindow.xaml"
[xml]$Form = Get-Content -Path $XamlPath
$NR = (New-Object System.Xml.XmlNodeReader $Form)
$Win = [WIndows.Markup.XamlReader]::Load($NR)
$server = $win.FindName("cmbServer")
$vCenter = $win.FindName("cmbvCenter")
$btnDecomm = $win.FindName("btnDecomm")
$statusBar = $win.FindName("txtStatusBar")
$output = $win.FindName("txtOutput")
$vCenter.Items.Add("vcenter1")
$vCenter.Items.Add("vcenter2")
$vCenter.Items.Add("vcenter3")
$vCenter_SelectedIndexChanged = {
    $output.text = "vCenter chosen"
    write-host "vCenter chosen"
}
$btnDecomm.Add_Click({
    decomm
})
$win.ShowDialog()

Unable to Enter the value of a variable in web.config

$
0
0

I am unable to update the value of $t which either holds enable or disable string.

$temp = Read-Host "Do you want to enable or disable IsNotificationService "
$t=$temp.Equals('enable')
Foreach($Server in Get-Content "C:\temp\Servers.txt")
{
Invoke-Command $Server -ScriptBlock {
$webConfig = "C:\rsweb.config"
$doc = (Get-Content $webConfig) -as [Xml]
$doc.configuration.Service.IsNotificationService=$t
$doc.Save($webConfig)
$check=$doc.configuration.Service.IsNotificationService
Write-host "IsNotificationService of " $check
}
}

Below is the error

cannot set "IsNotificationService" because only strings can be used as values to set XmlNode properties.
   + CategoryInfo          : NotSpecified: (:) [], SetValueException
   + FullyQualifiedErrorId : XmlNodeSetShouldBeAString

But when i try to do write-host $t it prints ...same issue is there with $server variable as well.. i am unable to print $server value in Write-host "IsNotificationService of "$server $check


Best Regards,ACDBA

ran Get-WindowsUpdateLog cmdlet for multiple machines remotely and get the logs into common location

$
0
0

windows update log by design is updating during patching once we ran get-windowsupdatelog cmdlet then only log creates on user desktops it is possible to ran Get-WindowsUpdateLog cmdlet for multiple machines remotely and get the logs into common location

PS C:\Windows\system32> Get-WindowsUpdateLog

Converting C:\Windows\logs\WindowsUpdate into C:\Users\Admin\Desktop\WindowsUpdate.log ...


    Directory: C:\Users\Admin\AppData\Local\Temp\WindowsUpdateLog


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       25-07-2020     20:43                SymCache

Input
----------------
File(s):
     C:\Windows\logs\WindowsUpdate\WindowsUpdate.20200725.160520.153.5.etl
     C:\Windows\logs\WindowsUpdate\WindowsUpdate.20200725.160520.153.6.etl
     C:\Windows\logs\WindowsUpdate\WindowsUpdate.20200725.160520.153.7.etl
     C:\Windows\logs\WindowsUpdate\WindowsUpdate.20200725.160520.153.8.etl
     C:\Windows\logs\WindowsUpdate\WindowsUpdate.20200725.160520.153.9.etl
     C:\Windows\logs\WindowsUpdate\WindowsUpdate.20200725.160520.153.10.etl
     C:\Windows\logs\WindowsUpdate\WindowsUpdate.20200725.160520.153.11.etl
     C:\Windows\logs\WindowsUpdate\WindowsUpdate.20200725.160520.153.12.etl
     C:\Windows\logs\WindowsUpdate\WindowsUpdate.20200725.160520.153.13.etl
     C:\Windows\logs\WindowsUpdate\WindowsUpdate.20200725.160520.153.14.etl

0.00%4.69%9.38%14.08%18.77%23.46%28.15%32.84%37.54%42.23%46.92%51.61%56.30%61.00%65.69%70.38%75.07%79.77%84.46%89.15%93.84%98.53%100.00%

Output
----------------
DumpFile:           C:\Users\Admin\AppData\Local\Temp\WindowsUpdateLog\wuetl.CSV.tmp.00000

The command completed successfully


Input
----------------
File(s):
     C:\Windows\logs\WindowsUpdate\WindowsUpdate.20200725.160520.153.15.etl
     C:\Windows\logs\WindowsUpdate\WindowsUpdate.20200725.160520.153.16.etl
     C:\Windows\logs\WindowsUpdate\WindowsUpdate.20200725.160520.153.17.etl
     C:\Windows\logs\WindowsUpdate\WindowsUpdate.20200725.160520.153.18.etl
     C:\Windows\logs\WindowsUpdate\WindowsUpdate.20200725.160520.153.19.etl
     C:\Windows\logs\WindowsUpdate\WindowsUpdate.20200725.181021.300.1.etl

0.00%10.53%21.05%31.58%42.11%52.63%63.16%73.68%84.21%94.74%100.00%

Output
----------------
DumpFile:           C:\Users\Admin\AppData\Local\Temp\WindowsUpdateLog\wuetl.CSV.tmp.00001

The command completed successfully.

WindowsUpdate.log written to C:\Users\Admin\Desktop\WindowsUpdate.log

Viewing all 21975 articles
Browse latest View live


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